Jump to content

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


Recommended Posts

Posted (edited)
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
Posted
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

Posted (edited)

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
Posted

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

Posted

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();
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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