Jump to content
×
×
  • Create New...

[Help] Needed in variables and other stuff..


Recommended Posts

package scripts;
import org.powerbot.script.PollingScript;
import org.powerbot.script.Script;
import org.powerbot.script.rt4.*;


@Script.Manifest(name = "Buy/Bank a Item",description = "Buys fish , net in port sarim",properties = "author=Batuhanboran; topic=999; client=4;")

public class Main extends  PollingScript<ClientContext>{

    final static int Npc_Id = 2891;
    final static int ItemFlyingRod = 309;
    final static int ItemNet  = 303;
    final static int Itemcage  = 301;
    final static int ourmoney  = 905;
    final static int depositbox  = 27381;

    @Override
    public void start()
    {
        System.out.println("Started");
        ctx.camera.pitch(99);
        ctx.camera.angle(45);
        ctx.camera.angleTo(100);
    }
    @Override
    public void stop()
    {
        System.out.println("Stopped");
    }
    @Override
    public void poll()
    {
        //constant loop
        NpcTrade();
        wait(500);
        buy();
        wait(500);
        Hop();
    }
    public void NpcTrade()
    {
        Npc gerrant = ctx.npcs.toStream().id(Npc_Id).nearest().first();
        gerrant.interact("Trade");
        System.out.println("Our money : " + ctx.inventory.select().id(ourmoney).poll());
    }
    public void buy()
    {
        //buying
        wait(500);
        ctx.store.buy(ItemFlyingRod,5);
        wait(500);
        ctx.store.buy(ItemNet,5);
        wait(500);
        ctx.store.buy(Itemcage,5);
        wait(500);
        ctx.store.close();
    }
    public void Hop()
    {
        ctx.worlds.open();
        wait(500);


    }
    public static void wait(int ms)
    {
        try
        {
            Thread.sleep(ms);
        }
        catch(InterruptedException ex)
        {
            Thread.currentThread().interrupt();
        }
    }
}

Hi there this is my local script working on it since yesterday it buys fish net , cage , rod in port sarim and put depositbox and make profit from it its my goal

I am f2p player as you can understand and I want learn some javascript while doing I have couple of issues with it.

-How can I hop other world ? I could not find it I can open world switcher but I dont know to hop

-Can I list array for 10 worlds of least population so I can safely travel in these areas ?

-I want to zoomout in camera for better  view but

ctx.camera.getZoom()

I can not compile with thisI am doing wrong ?

-Do I have sign tiles to for to move in depositbox ?

-And I can not access money I have on inventory I tried stacksize too but I wont show it.

Thank you , I am not native in english so sorry for errors.

Edited by Batuhan Boran
Link to post
Share on other sites
  • Moderators

-How can I hop other world ? I could not find it I can open world switcher but I dont know to hop

Using widgets and tabs, for example;

ctx.game.tab(LOGOUT); //this opens the log out tab,
//from there, you'll need to open the world selection list using widgets
ctx.widgets.widget(ID int).component(ID int).click(); //this clicks said widget, you can view the widgets by opening the widget explorer in the client under the view menu.

 

-Can I list array for 10 worlds of least population so I can safely travel in these areas ?

 public static final int[] f2p = {301, 326, 335, 371, 379, 380, 382, 383, 384, 393, 394, 397, 398, 399, 418, 425, 426, 430, 431, 433, 434, 435, 436, 437, 438, 439, 440, 451, 452, 453, 454, 455, 456, 457, 458, 459, 469, 470, 471, 472, 473, 474, 475, 476, 477, 497, 498, 499, 500, 501, 502, 503, 504, 302, 303};
//heres an array of some f2p worlds.

-I want to zoomout in camera for better  view but

ctx.camera.getZoom()

I can not compile with thisI am doing wrong ?

//something to note, anything that says 'get' is likely to return a variables value, not set one.
//the reason you can't compile is because you're not making a method call in that statement.
ctx.input.scroll(boolean); // this might help.

 

-Do I have sign tiles to for to move in depositbox ?

//No clue what you said but if you mean to walk to the deposit box then you can get the deposit box tile and do something like this;
ctx.movement.moveTo(depositBoxTile);

 

-And I can not access money I have on inventory I tried stacksize too but I wont show it.

//Looking at your script, you're using 2 different API's one of which is depreciated, going forward, use Streams.
//However, your problem is an incorrect ID, gp is 995 not 905.

final static int ourmoney  = 995;
...
...
...
...
ctx.inventory.toStream().id(ourmoney).first().stackSize();

 

Also, don't use thread.sleep() look into

Condition.sleep(ms); // a static sleep time for the amount you set as ms
Condition.wait(()->boolean, ms, tries); //this is conditional, if your boolean is true, it'll early exit, if false, it'll time out ms*tries

 

Somehting else to mention, scripts are very conditional, they activate code based on previous checks, in simple, if x is true, do y. In your script, you don't have a single if statement, meaning every single method inside poll() will be called no matter what your char is doing. For example, your NpcTrade() method will activate, even if you're at the deposit box for example or if you've already got the shop open.

You should start to wrap them in if statements; as an example

 public boolean shouldTrade()
    {
        Npc gerrant = ctx.npcs.toStream().id(Npc_Id).nearest().first();
		if(!ctx.store.opened() && gerrant.visible()){//checking that the store isn't already open and you can see gerrant on screen
   			return true; // this can be simplified, but for where you're probably at in terms of java syntax, this will do for now.
        } else {
            return false;
    }

public void NpcTrade()
    {
        Npc gerrant = ctx.npcs.toStream().id(Npc_Id).nearest().first();
        gerrant.interact("Trade");
        System.out.println("Our money : " + ctx.inventory.select().id(ourmoney).poll());
    }

 @Override
    public void poll(){
        if(shouldTrade()){  // this check to see first if we should trade, before we call the trade method.
			NpcTrade();
        	wait(500);
        }
...
...
...
    }

 

Link to post
Share on other sites
23 minutes ago, Dan said:

-How can I hop other world ? I could not find it I can open world switcher but I dont know to hop

Using widgets and tabs, for example;

ctx.game.tab(LOGOUT); //this opens the log out tab,
//from there, you'll need to open the world selection list using widgets
ctx.widgets.widget(ID int).component(ID int).click(); //this clicks said widget, you can view the widgets by opening the widget explorer in the client under the view menu.

 

-Can I list array for 10 worlds of least population so I can safely travel in these areas ?

 public static final int[] f2p = {301, 326, 335, 371, 379, 380, 382, 383, 384, 393, 394, 397, 398, 399, 418, 425, 426, 430, 431, 433, 434, 435, 436, 437, 438, 439, 440, 451, 452, 453, 454, 455, 456, 457, 458, 459, 469, 470, 471, 472, 473, 474, 475, 476, 477, 497, 498, 499, 500, 501, 502, 503, 504, 302, 303};
//heres an array of some f2p worlds.

-I want to zoomout in camera for better  view but

ctx.camera.getZoom()

I can not compile with thisI am doing wrong ?

//something to note, anything that says 'get' is likely to return a variables value, not set one.
//the reason you can't compile is because you're not making a method call in that statement.
ctx.input.scroll(boolean); // this might help.

 

-Do I have sign tiles to for to move in depositbox ?

//No clue what you said but if you mean to walk to the deposit box then you can get the deposit box tile and do something like this;
ctx.movement.moveTo(depositBoxTile);

 

-And I can not access money I have on inventory I tried stacksize too but I wont show it.

//Looking at your script, you're using 2 different API's one of which is depreciated, going forward, use Streams.
//However, your problem is an incorrect ID, gp is 995 not 905.

final static int ourmoney  = 995;
...
...
...
...
ctx.inventory.toStream().id(ourmoney).first().stackSize();

 

Also, don't use thread.sleep() look into

Condition.sleep(ms); // a static sleep time for the amount you set as ms
Condition.wait(()->boolean, ms, tries); //this is conditional, if your boolean is true, it'll early exit, if false, it'll time out ms*tries

 

Somehting else to mention, scripts are very conditional, they activate code based on previous checks, in simple, if x is true, do y. In your script, you don't have a single if statement, meaning every single method inside poll() will be called no matter what your char is doing. For example, your NpcTrade() method will activate, even if you're at the deposit box for example or if you've already got the shop open.

You should start to wrap them in if statements; as an example

 public boolean shouldTrade()
    {
        Npc gerrant = ctx.npcs.toStream().id(Npc_Id).nearest().first();
		if(!ctx.store.opened() && gerrant.visible()){//checking that the store isn't already open and you can see gerrant on screen
   			return true; // this can be simplified, but for where you're probably at in terms of java syntax, this will do for now.
        } else {
            return false;
    }

public void NpcTrade()
    {
        Npc gerrant = ctx.npcs.toStream().id(Npc_Id).nearest().first();
        gerrant.interact("Trade");
        System.out.println("Our money : " + ctx.inventory.select().id(ourmoney).poll());
    }

 @Override
    public void poll(){
        if(shouldTrade()){  // this check to see first if we should trade, before we call the trade method.
			NpcTrade();
        	wait(500);
        }
...
...
...
    }

 

Wow such huge help thank you , I will do my research and improve on it.

  • Like 1
Link to post
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.

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.