Jump to content

Need help with reading message from chatbox and doing stuff if it contains something. debug my code please


sarthycool

Recommended Posts

package doubling;
 
import java.awt.Graphics2D;
import java.lang.Thread.State;
import java.util.List;
 
import org.osbot.rs07.api.Chatbox;
import org.osbot.rs07.api.Chatbox.MessageType;
import org.osbot.rs07.script.API;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
 
 
@ScriptManifest(name = "respond", author = "", version = 1.0, info = "", logo = "") 
public class doubling extends Script {
 
 
 
 
    @Override
    public void onStart() {
        log("started");
       
 
 
    }
    
    @Override
    public void onExit() {
        log("ended!");
 
 
    }
    
 
   
    public void onMessage(String m) throws InterruptedException{
 
   
    }
 
    @Override
    public int onLoop() throws InterruptedException {
    List<String> m =  chatbox.getMessages(MessageType.PLAYER);
if (m.contains("hey")){
       
    log("someone said it");
   
    String a = new String("somethinga");
    String b = new String("somethingb");
    String c = new String("somethingc");
    int r = random(1, 3);
    if(r%2 == 0){
    keyboard.typeString(a);
    log("said" + a);
    sleep(500);
   
   
    if(r == 1){
    keyboard.typeString(b);
    log("said" + b);
    sleep(400);
    }
   
 
    if(r == 3){
    keyboard.typeString©;
    log("said" + c);
    sleep(500);
    }
    }
   
   
        return 215; //The amount of time in milliseconds before the loop starts over
    }
 
 
    @Override
    public void onPaint(Graphics2D g) {
        //This is where you will put your code for paint(s)
 
 
 
 
    }
 
 
}

 

 

The message to be read from player in chatbox.

Edited by sarthycool
Link to comment
Share on other sites

package doubling;
 
import java.awt.Graphics2D;
import java.lang.Thread.State;
import java.util.List;
 
import org.osbot.rs07.api.Chatbox;
import org.osbot.rs07.api.Chatbox.MessageType;
import org.osbot.rs07.script.API;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
 
 
@ScriptManifest(name = "respond", author = "", version = 1.0, info = "", logo = "") 
public class doubling extends Script {
 
 
 
 
    @Override
    public void onStart() {
        log("started");
       
 
 
    }
    
    @Override
    public void onExit() {
        log("ended!");
 
 
    }
    
 
   
    public void onMessage(String m) throws InterruptedException{
 
   
    }
 
    @Override
    public int onLoop() throws InterruptedException {
    List<String> m =  chatbox.getMessages(MessageType.PLAYER);
if (m.contains("hey")){
       
    log("someone said it");
   
    String a = new String("somethinga");
    String b = new String("somethingb");
    String c = new String("somethingc");
    int r = random(1, 3);
    if(r%2 == 0){
    keyboard.typeString(a);
    log("said" + a);
    sleep(500);
   
   
    if(r == 1){
    keyboard.typeString(b);
    log("said" + b);
    sleep(400);
    }
   
 
    if(r == 3){
    keyboard.typeString©;
    log("said" + c);
    sleep(500);
    }
    }
   
   
        return 215; //The amount of time in milliseconds before the loop starts over
    }
 
 
    @Override
    public void onPaint(Graphics2D g) {
        //This is where you will put your code for paint(s)
 
 
 
 
    }
 
 
}

 

 

The message to be read from player in chatbox.

try using onMessage?

since chatboxGetMessages will get all the messages including old ones i think

and onMessage gets the new ones or somethng lol

Link to comment
Share on other sites

onMessage should work, i use it with many scripts.

 

package doubling;

import java.awt.Graphics2D;

import java.lang.Thread.State;

import java.util.List;

import org.osbot.rs07.api.Chatbox;

import org.osbot.rs07.api.Chatbox.MessageType;

import org.osbot.rs07.script.API;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "respond", author = "", version = 1.0, info = "", logo = "")

public class doubling extends Script {

@Override

public void onStart() {

log("started");

}

@Override

public void onExit() {

log("ended!");

}

public void onMessage(String m) throws InterruptedException{

String m = message.getMessages(MessageType.PLAYER);

if (m.contains("Repaid")){

log("someone said repaid");

String a = new String("wow!");

String b = new String("Thank you! <3");

String c = new String("<3 <3");

int r = random(1, 3);

if(r%2 == 0){

keyboard.typeString(a);

log("said" + a);

sleep(500);

}

if(r == 1){

keyboard.typeString(b);

log("said" + b);

sleep(400);

}

if(r == 3){

keyboard.typeString©;

log("said" + c);

sleep(500);

}

}

}

@Override

public int onLoop() throws InterruptedException {

return 215; //The amount of time in milliseconds before the loop starts over

}

@Override

public void onPaint(Graphics2D g) {

//This is where you will put your code for paint(s)

}

}

 

 

This is the code now. The line marked in red is giving error.  

Edited by sarthycool
Link to comment
Share on other sites

package doubling;

import java.awt.Graphics2D;

import java.lang.Thread.State;

import java.util.List;

import org.osbot.rs07.api.Chatbox;

import org.osbot.rs07.api.Chatbox.MessageType;

import org.osbot.rs07.script.API;

import org.osbot.rs07.script.Script;

import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(name = "respond", author = "", version = 1.0, info = "", logo = "")

public class doubling extends Script {

@Override

public void onStart() {

log("started");

}

@Override

public void onExit() {

log("ended!");

}

public void onMessage(String m) throws InterruptedException{

String m = message.getMessages(MessageType.PLAYER);

if (m.contains("Repaid")){

log("someone said repaid");

String a = new String("wow!");

String b = new String("Thank you! <3");

String c = new String("<3 <3");

int r = random(1, 3);

if(r%2 == 0){

keyboard.typeString(a);

log("said" + a);

sleep(500);

}

if(r == 1){

keyboard.typeString(b);

log("said" + b);

sleep(400);

}

if(r == 3){

keyboard.typeString©;

log("said" + c);

sleep(500);

}

}

}

@Override

public int onLoop() throws InterruptedException {

return 215; //The amount of time in milliseconds before the loop starts over

}

@Override

public void onPaint(Graphics2D g) {

//This is where you will put your code for paint(s)

}

}

 

 

This is the code now. The line marked in red is giving error.  

String Txt = message.getMessage().toLowerCase(); try this

Link to comment
Share on other sites

Doesnt work. 'message' is being underlined. The error is "message cannot be resolved".

 

:???:

 

Your function definition is this:

public void onMessage(String m) throws InterruptedException {

}

It should be:

@Override
public void onMessage(Message message) throws InterruptedException {

}

And now the Message variable is called message so:

@Override
public void onMessage(Message message) throws InterruptedException {
    String text = message.getMessage().toLowerCase();
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...