• Log in or sign up for an account here: https://www.sythe.org/login

Script Writing Guide.

Status
Not open for further replies.
Joined
Apr 7, 2008
Sythe Gold
0
Messages
1,429
Location
Ormond beach
Category 1
  • Here you will learn the basics of scripting
  • You will see the outline of a script
  • You will also learn about imports
The basics of scripting in RSBot.​
  • Rsbot is coded in java.
  • When you add a method you have to have the required import.
  • You can state something and not add it into the loop and expect it to work
  • The loop is the key.
Outline
This is a basic script outline with a progress report, a.k.a piant included.

PHP:
import java.awt.*;
import java.util.Map;
import java.util.ArrayList;

import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.*;
import com.speljohan.rsbot.event.listeners.ServerMessageListener;
import com.speljohan.rsbot.event.listeners.PaintListener;
import com.speljohan.rsbot.event.events.ServerMessageEvent;

public class NAME OF YOUR SCRIPT extends Script implements ServerMessageListener,PaintListener {

    public double getVersion() {
    
        return 1;
    }

    public String getScriptCategory() {
    
        return "Your name/Skill";
    }

    public String getName() {

        return "Name of script";
    }

    public String getAuthor() {

        return "Your name";
    }

    public String getScriptDescription() {
        String html = "";
        html += "<html>\n";
        html += "<body>\n";
        html += "<center>\n";
        html += "<font size=\"5\">Title</font><br><br>";
        html += "</center>";
        html += "Details";
        html += "Details";
        html += "</body>";
        html += "</html>";

        return( html );
    }
    
    
    public boolean onStart(Map<String, String> args) {
        startTime = System.currentTimeMillis();
        Bot.getEventManager().addListener(PaintListener.class, this);
        return true;
    }
    
    public void onFinish() {
        Bot.getEventManager().removeListener(PaintListener.class, this);
        Bot.getEventManager().removeListener(ServerMessageListener.class, this);
    }

    public int loop() {
return true;
    }      
    
public void onRepaint(final Graphics g) {
        if (isLoggedIn()) {
            Color BG = new Color(0, 0, 0, 100);
            long millis = System.currentTimeMillis() - startTime;
            final long hours = millis / (1000 * 60 * 60);
            millis -= hours * (1000 * 60 * 60);
            final long minutes = millis / (1000 * 60);
            millis -= minutes * (1000 * 60);
            final long seconds = millis / 1000;
            final int topX = 515 - 173, topY = 340 - 80, x = topX + 5;
            int y = topY + 5;
            g.setColor(BG);
            g.fill3DRect(topX, topY, 515 - topX, 340 - topY, true);
            g.setColor(Color.COLORHERE);
            g.drawString(getName(), x, y += 13);
        }
    }  
}


Category 2

Adding a simple function
  • This is quite easy, so just follow along.
Lets add a simple void to spin the camera

PHP:
public void turnCamera() {
        char[] LR = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT };
        char[] UD = new char[] { KeyEvent.VK_DOWN, KeyEvent.VK_UP };
        char[] LRUD = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
                                 KeyEvent.VK_UP, KeyEvent.VK_UP };
        int random2 = random(0,2);
        int random1 = random(0,2);
        int random4 = random(0,4);
        
        if(random(0,3) == 0) {
            Bot.getInputManager().pressKey(LR[random1]);
            try { Thread.sleep(random(100, 400)); } catch (Exception e) {}
            Bot.getInputManager().pressKey(UD[random2]);
            try { Thread.sleep(random(300, 600)); } catch (Exception e) {}
            Bot.getInputManager().releaseKey(UD[random2]);
            try { Thread.sleep(random(100, 400)); } catch (Exception e) {}
            Bot.getInputManager().releaseKey(LR[random1]);                
        } else {
            Bot.getInputManager().pressKey(LRUD[random4]);
            if(random4>1) {
                try { Thread.sleep(random(300, 600)); } catch (Exception e) {}
            } else {
                try { Thread.sleep(random(500, 900)); } catch (Exception e) {}
            }
            Bot.getInputManager().releaseKey(LRUD[random4]);
        }
    }
add that void into your script right above the loop so it looks like this.

PHP:
    import java.awt.*;
import java.util.Map;
import java.util.ArrayList;

import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.script.Script;
import com.speljohan.rsbot.script.wrappers.*;
import com.speljohan.rsbot.event.listeners.ServerMessageListener;
import com.speljohan.rsbot.event.listeners.PaintListener;
import com.speljohan.rsbot.event.events.ServerMessageEvent;

public class NAME OF YOUR SCRIPT extends Script implements ServerMessageListener,PaintListener {

    public double getVersion() {
    
        return 1;
    }

    public String getScriptCategory() {
    
        return "Your name/Skill";
    }

    public String getName() {

        return "Name of script";
    }

    public String getAuthor() {

        return "Your name";
    }

    public String getScriptDescription() {
        String html = "";
        html += "<html>\n";
        html += "<body>\n";
        html += "<center>\n";
        html += "<font size=\"5\">Title</font><br><br>";
        html += "</center>";
        html += "Details";
        html += "Details";
        html += "</body>";
        html += "</html>";

        return( html );
    }
    
    
    public boolean onStart(Map<String, String> args) {
        startTime = System.currentTimeMillis();
        Bot.getEventManager().addListener(PaintListener.class, this);
        return true;
    }
    
    public void onFinish() {
        Bot.getEventManager().removeListener(PaintListener.class, this);
        Bot.getEventManager().removeListener(ServerMessageListener.class, this);
    }
    
public void turnCamera() {
        char[] LR = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT };
        char[] UD = new char[] { KeyEvent.VK_DOWN, KeyEvent.VK_UP };
        char[] LRUD = new char[] { KeyEvent.VK_LEFT, KeyEvent.VK_RIGHT,
                                 KeyEvent.VK_UP, KeyEvent.VK_UP };
        int random2 = random(0,2);
        int random1 = random(0,2);
        int random4 = random(0,4);
        
        if(random(0,3) == 0) {
            Bot.getInputManager().pressKey(LR[random1]);
            try { Thread.sleep(random(100, 400)); } catch (Exception e) {}
            Bot.getInputManager().pressKey(UD[random2]);
            try { Thread.sleep(random(300, 600)); } catch (Exception e) {}
            Bot.getInputManager().releaseKey(UD[random2]);
            try { Thread.sleep(random(100, 400)); } catch (Exception e) {}
            Bot.getInputManager().releaseKey(LR[random1]);                
        } else {
            Bot.getInputManager().pressKey(LRUD[random4]);
            if(random4>1) {
                try { Thread.sleep(random(300, 600)); } catch (Exception e) {}
            } else {
                try { Thread.sleep(random(500, 900)); } catch (Exception e) {}
            }
            Bot.getInputManager().releaseKey(LRUD[random4]);
        }
    }
    
    public int loop() {
    turncamera();
    return true;
    }      
    
public void onRepaint(final Graphics g) {
        if (isLoggedIn()) {
            Color BG = new Color(0, 0, 0, 100);
            long millis = System.currentTimeMillis() - startTime;
            final long hours = millis / (1000 * 60 * 60);
            millis -= hours * (1000 * 60 * 60);
            final long minutes = millis / (1000 * 60);
            millis -= minutes * (1000 * 60);
            final long seconds = millis / 1000;
            final int topX = 515 - 173, topY = 340 - 80, x = topX + 5;
            int y = topY + 5;
            g.setColor(BG);
            g.fill3DRect(topX, topY, 515 - topX, 340 - topY, true);
            g.setColor(Color.COLORHERE);
            g.drawString(getName(), x, y += 13);
        }
    }  
}
and remember always state a void in your script for it to work!

Take notice of the loop.




ill add more soon, like tommorow..


​
 
Status
Not open for further replies.
Runescape Gamblingrunescape gambling
Back
Top