Jump to content

IP Display Changer


Recommended Posts

  • 2 weeks later...
Posted

can someone do a massive solid for me and compile this? It'll save me the hour or two figuring it out :D 

 

Really? All you do is go to the tutorials section, find the script skeleton. Than add the code to the onStart() method. Not hard, id recommend learning some java if you wish to handle scripts, look on youtube for the boston or something like that. He teaches everything from variables to polymorphism, and abstract classes.

  • 1 month later...
Posted (edited)

Here's the proper way of doing it : 

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;

import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

@ScriptManifest(author = "Purple", name = "IP Display Changer", version = 1.01, info = "Changes the title of your osbot to display your bots IP address.", logo = "")
public class Display extends Script {

    @Override
    public void onStart() {
        changeFrameTitle("OSBot (" + getCurrentIPAddress() + ")");
        stop(false);
    }

    public void changeFrameTitle(final String title) {
        for(Frame frame : Frame.getFrames()) {
            if(frame.isVisible() && frame.getTitle().startsWith("OSBot")) {
                SwingUtilities.invokeLater(() -> frame.setTitle(title));
                break;
            }
        }
    }
    
    public int onLoop() throws InterruptedException {
        
        return 0;
    }

    public String getCurrentIPAddress() {
        try {
            URL url = new URL("http://myip.dnsomatic.com/");
            BufferedReader b = new BufferedReader(new InputStreamReader(url.openStream()));
            String ip = b.readLine();
            b.close();
            return ip;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "null";
    }
}

 

Edited by Jeune Padawan
  • 5 months later...
  • 2 weeks later...

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...