Jump to content

Npc If Clause


RDM

Recommended Posts

Trying to make a script that buys from an npc and not sure how to get the clause right. I know how to steal from a stall(below), how would i change it to get it into trading and buying from an npc?

private State getState() {

Entity stall = object.closest("Tea Stall")

if (!inventory.isEmpty())

return State.DROP;

if (stall != null)

return State.STEAL;

return State.WAIT;

}

Also how would i make it ao when the script as finished opening feather packs that it wont drop the gold stack?

What I have so far...

private State getState() {

Entity npc = object.closest("NPC NAME")

Not even sure if this is right lol.

private enum State {

TRADE, OPEN

};

Thank you

Link to comment
Share on other sites

Logic is a fundamental part of programming, it really can't be taught. Just add more checks and if statements before actually returning steal or drop.

 

Pseudo code example:

 

boolean shouldTrade = false;

 

if(!shouldTrade){

      if(!inventory.isFull(){

         return State.Steal;

       } else { return State.Drop }

} else {

return State.Trade;

}

Link to comment
Share on other sites

					if (p.getInterfaces().get(300).isValid() && p.getInterfaces().get(300).isVisible()) {
						// store is open
						if (p.getStore().contains(1337)) {
							if (p.getStore().buy("czar", 1)) {
								return 1000;
							}
						}
					} else {
						Entity shopkeeper = p.npcs.closest("Shopkeeper");
						if (shopkeeper != null) {
							if (shopkeeper.interact("Trade")) {
								return 1000;
							}
						}
					}

 

That's for buying something from shop,

 

As for the 'dropping gold', check if inventory is full, not if inventory isn't empty

 

!getInventory().isEmpty()        -->>> getInventory().isFull()

 

PM me if you need more help :D

Edited by Czar
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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