Jump to content

How to buy items from a store/check if they are out?


imancity

Recommended Posts

I want to be able to buy different items from a store, let's say a General store. And if they are out of said item, to hop worlds (p2p worlds). I tried digging through some tutorials, and using widgets myself, but its not working. Any ideas?

There is a store class to handle most things for you :) It can be found here and it should hold everything you need

  • Like 1
Link to comment
Share on other sites

You're welcome smile.png If you run into any issues let me know biggrin.png

 

Hey, Solution. Could you help me with this?

 

So in this case, I have it trade the NPC nearby and buy all of the supply of 4 different items. I want it to buy them all, and once out, to hop worlds and continue. I can't seem to make it work because the way I currently have it, it opens the Store but doesn't buy. If I put the buying code outside the trade if then it does it but once its out, it doesn't hop but rather keeps spam trading the NPC.

 

Sorry if that's a bit unclear, I can explain more if need be.

case BUY:

                if ((getNpcs().closest("NPC") !=null) && (!getStore().isOpen())) {
                    getNpcs().closest("NPC").interact("Trade");
                    wait(100,200);

                    if ((getStore().isOpen()) /*&& (getStore().contains("Item1" , "Item2" , "Item3" , "Item4"))*/) {
                        if (getStore().getAmount("Item1") > 0) {
                            getStore().buy("Item1", 10);
                            wait(100, 200);
                        } else if (getStore().getAmount("Item2") > 0) {
                            getStore().buy("Item2", 10);
                            wait(100, 200);
                        } else if (getStore().getAmount("Item3") > 0) {
                            getStore().buy("Item3", 10);
                            wait(100, 200);
                        } else if (getStore().getAmount("Item4") > 0) {
                            getStore().buy("Item4" , 10);
                            wait(100,200);
                        }
                        else {
                            getStore().close();
                            wait(100,200);
                            worlds.hopToP2PWorld();
                        }
                    }
                }
           
                break;
Link to comment
Share on other sites

 

Hey, Solution. Could you help me with this?

 

So in this case, I have it trade the NPC nearby and buy all of the supply of 4 different items. I want it to buy them all, and once out, to hop worlds and continue. I can't seem to make it work because the way I currently have it, it opens the Store but doesn't buy. If I put the buying code outside the trade if then it does it but once its out, it doesn't hop but rather keeps spam trading the NPC.

 

Sorry if that's a bit unclear, I can explain more if need be.

case BUY:

                if ((getNpcs().closest("NPC") !=null) && (!getStore().isOpen())) {
                    getNpcs().closest("NPC").interact("Trade");
                    wait(100,200);

                    if ((getStore().isOpen()) /*&& (getStore().contains("Item1" , "Item2" , "Item3" , "Item4"))*/) {
                        if (getStore().getAmount("Item1") > 0) {
                            getStore().buy("Item1", 10);
                            wait(100, 200);
                        } else if (getStore().getAmount("Item2") > 0) {
                            getStore().buy("Item2", 10);
                            wait(100, 200);
                        } else if (getStore().getAmount("Item3") > 0) {
                            getStore().buy("Item3", 10);
                            wait(100, 200);
                        } else if (getStore().getAmount("Item4") > 0) {
                            getStore().buy("Item4" , 10);
                            wait(100,200);
                        }
                        else {
                            getStore().close();
                            wait(100,200);
                            worlds.hopToP2PWorld();
                        }
                    }
                }
           
                break;
  1. Don't use "wait()" when you want the script to sleep. Use ConditionalSleep for dynamic sleeping

    open store
    new ConditionalSleep(5000
       public boolean condition() {
           return store is open;
       }
    }.sleep();
    
    //it will sleep maximum 5000 ms or until the store is open
  2. Your getState() or w/e it's called is flawed
Edited by Woody
  • Like 1
Link to comment
Share on other sites

 

  1. Don't use "wait()" when you want the script to sleep. Use ConditionalSleep for dynamic sleeping

    open store
    new ConditionalSleep(5000
       public boolean condition() {
           return store is open;
       }
    }.sleep();
    
    //it will sleep maximum 5000 ms or until the store is open
  2. Your getState() or w/e it's called is flawed

 

 

Why do you say my getState() is flawed? I'm not sure what you mean by this.

 

Link to comment
Share on other sites

Why do you say my getState() is flawed? I'm not sure what you mean by this.

 

I think he is talking about your onLoop() because unless I am blind your getState() wasn't even provided.

 

Here is an example of what I used in one of my scripts:

NPC gerrant = getNpcs().closest("Gerrant");
    		if(gerrant == null){
    			log("[Error] Gerrant not found!");
    			return 1000;
    		}
    		if(gerrant.interact("Trade")){
    			new ConditionalSleep(6000){
    				@Override
    				public boolean condition() throws InterruptedException {
    					return getWidgets().isVisible(300);
    				}
    			}.sleep();
    		}

I was using Widgets and not the store class.

  • Like 1
Link to comment
Share on other sites

I think he is talking about your onLoop() because unless I am blind your getState() wasn't even provided.

 

Here is an example of what I used in one of my scripts:

NPC gerrant = getNpcs().closest("Gerrant");
    		if(gerrant == null){
    			log("[Error] Gerrant not found!");
    			return 1000;
    		}
    		if(gerrant.interact("Trade")){
    			new ConditionalSleep(6000){
    				@Override
    				public boolean condition() throws InterruptedException {
    					return getWidgets().isVisible(300);
    				}
    			}.sleep();
    		}

I was using Widgets and not the store class.

 

Ohh well if that's the case, I just didn't copy down the getState() part onto here lol, I definitely have it in the script though. Hmm I'm gonna try to stick to using the store class. I was able to open the store, just not efficiently buy items :P

Link to comment
Share on other sites

Ohh well if that's the case, I just didn't copy down the getState() part onto here lol, I definitely have it in the script though. Hmm I'm gonna try to stick to using the store class. I was able to open the store, just not efficiently buy items :P

Want to post what you fixed so far? Also I am guessing you arn't actually putting "Item1" and instead the items id correct?

Link to comment
Share on other sites

Want to post what you fixed so far? Also I am guessing you arn't actually putting "Item1" and instead the items id correct?

 

Yes of course haha, just changed the items/npc to obscure it for now. I'm not home so can't post it, but the only thing I tried was creating separate cases for Buy and Talk(trade) so for one he'll trade with the npc, and then buy. It's just not going smoothly though. I must be messing something up when trying to buy multiple of different items.

Link to comment
Share on other sites

Yes of course haha, just changed the items/npc to obscure it for now. I'm not home so can't post it, but the only thing I tried was creating separate cases for Buy and Talk(trade) so for one he'll trade with the npc, and then buy. It's just not going smoothly though. I must be messing something up when trying to buy multiple of different items.

Shouldn't be necessary, my script buys and opens feather packs using three states BUY,OPEN,WAIT.

Link to comment
Share on other sites

Shouldn't be necessary, my script buys and opens feather packs using three states BUY,OPEN,WAIT.

 

Yeah I figured it doesn't need to be so complicated. Before I left I switched it back to just 3 simple Buy, Walk to Shop, and Bank. I'm gonna have to look at it and see what I can do when I get home. Currently clueless as to what to fix.

Link to comment
Share on other sites

Yeah I figured it doesn't need to be so complicated. Before I left I switched it back to just 3 simple Buy, Walk to Shop, and Bank. I'm gonna have to look at it and see what I can do when I get home. Currently clueless as to what to fix.

If you still need help after you have tried you can PM me your source and I will fix it.

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