Jump to content

Shop Interface (just like Bank but then for shops!)


Merccy

Recommended Posts

i get this error when i try to start script

java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.osbot.script.engine.ScriptManager.startScript(ci:115)
	at org.osbot.xB.run(vg:4)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
	at Shop.isOpen(Shop.java:36)
	at Shop.getAllShopItems(Shop.java:80)
	at Buyer.<init>(Buyer.java:39)
	... 9 more
Link to comment
Share on other sites

I've just started to try out some bot programming. I've got a little bit of programming knowledge, but I'm finding it kind of hard to get going. I don't understand how to set up a new shop, or what a script object even is. I tried looking at the API but even that I'm having trouble understanding. If anybody could help explain some of these things to me that would be awesome. 

Link to comment
Share on other sites

I've just started to try out some bot programming. I've got a little bit of programming knowledge, but I'm finding it kind of hard to get going. I don't understand how to set up a new shop, or what a script object even is. I tried looking at the API but even that I'm having trouble understanding. If anybody could help explain some of these things to me that would be awesome. 

 

Create a global instance of shop in your script.

 

To do so, place this above your onStart method:

Shop shop = new Shop(this);

 

Here is an example of how you can use the shop after you have have created the global instance:

 

if (shop.isOpen()) {
    ShopItem fireRune = shop.getShopItem(FIRE_RUNE_ID); //FIRE_RUNE_ID is a global int with value of 554
    if (fireRune != null && fireRune.getAmount() > 0) {
        fireRune.buy10();
    }
}
  • Like 1
Link to comment
Share on other sites

 

I've just started to try out some bot programming. I've got a little bit of programming knowledge, but I'm finding it kind of hard to get going. I don't understand how to set up a new shop, or what a script object even is. I tried looking at the API but even that I'm having trouble understanding. If anybody could help explain some of these things to me that would be awesome. 

 

Create a global instance of shop in your script.

 

To do so, place this above your onStart method:

Shop shop = new Shop(this);

Here is an example of how you can use the shop after you have have created the global instance:

if (shop.isOpen()) {
    ShopItem fireRune = shop.getShopItem(FIRE_RUNE_ID); //FIRE_RUNE_ID is a global int with value of 554
    if (fireRune != null && fireRune.getAmount() > 0) {
        fireRune.buy10();
    }
}

Thank you, this helps a lot, time to start coding :D

 

Link to comment
Share on other sites

In my experience, getting the amount from the ShopItem and keeping the item up to date can be a bit tricky depending on connection quality and other performance factors. I personally use the slotId to get the amount of items in the slot using this method:

public int getAmountForSlot(int slotId) throws InterruptedException
{
        return this.scr.client.getInterface(this.parentID).getChild(this.childID).getInvStackSizes()[slotId];
}

This will return the correct data even when shop.isOpen() returns false. I was running into a lot of problems when refreshing ShopItems and they would become null due to what I could only conclude was networking issues. This took care of it nicely.

 

And with this you could also do something like this:

public int getAmountForItemId(int itemId) throws InterruptedException
{		
	ShopItem shopItem = this.getShopItemByID(itemId);
	
	if (shopItem == null)
		return -1;
	
	return this.getAmountForSlot(shopItem.slotID);
}

And actually, because the getShopItemByName and getShopItemByID use the getAllShopItems() which seemed to be somewhat sluggish, I wrote a getShopItemByItemId() method:

public ShopItem getShopItemByItemId(int itemId)
{
    if (this.isOpen())
    {
        Item[] items = this.scr.client.getInterface(this.parentID).getItems(this.childID);
        
        for (int slotId = 0; slotId < items.length; slotId++)
        {
            if (items[slotId].getId() == itemId)
            {
                ShopItem shopItem = new ShopItem(this.scr, slotId);
                shopItem.name = items[slotId].getName();
                shopItem.id = items[slotId].getId();
                shopItem.amount = items[slotId].getAmount();
                return shopItem;
            }
        }
    }
    return null;
}
Edited by bfir3
Link to comment
Share on other sites

I'm getting a similar error to one somebody else posted. Does anybody know what this is caused by? I can't seem to find any solution for it.

 

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.osbot.script.engine.ScriptManager.startScript(wh:97)
at org.osbot.yA.run(mo:408)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: com/merccy/Shop/Shop
Link to comment
Share on other sites

I'm getting a similar error to one somebody else posted. Does anybody know what this is caused by? I can't seem to find any solution for it.

java.lang.reflect.InvocationTargetException

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.osbot.script.engine.ScriptManager.startScript(wh:97)

at org.osbot.yA.run(mo:408)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: java.lang.NoClassDefFoundError: com/merccy/Shop/Shop

I got the same thing, it could be on how we've imported those files (shop, and shop item)

Link to comment
Share on other sites

In my experience, getting the amount from the ShopItem and keeping the item up to date can be a bit tricky depending on connection quality and other performance factors. I personally use the slotId to get the amount of items in the slot using this method:

public int getAmountForSlot(int slotId) throws InterruptedException
{
        return this.scr.client.getInterface(this.parentID).getChild(this.childID).getInvStackSizes()[slotId];
}
This will return the correct data even when shop.isOpen() returns false. I was running into a lot of problems when refreshing ShopItems and they would become null due to what I could only conclude was networking issues. This took care of it nicely.

 

And with this you could also do something like this:

public int getAmountForItemId(int itemId) throws InterruptedException
{		
	ShopItem shopItem = this.getShopItemByID(itemId);
	
	if (shopItem == null)
		return -1;
	
	return this.getAmountForSlot(shopItem.slotID);
}

And actually, because the getShopItemByName and getShopItemByID use the getAllShopItems() which seemed to be somewhat sluggish, I wrote a getShopItemByItemId() method:

public ShopItem getShopItemByItemId(int itemId)
{
    if (this.isOpen())
    {
        Item[] items = this.scr.client.getInterface(this.parentID).getItems(this.childID);
        
        for (int slotId = 0; slotId < items.length; slotId++)
        {
            if (items[slotId].getId() == itemId)
            {
                ShopItem shopItem = new ShopItem(this.scr, slotId);
                shopItem.name = items[slotId].getName();
                shopItem.id = items[slotId].getId();
                shopItem.amount = items[slotId].getAmount();
                return shopItem;
            }
        }
    }
    return null;
}

Where would I put this At. Shopitem.java

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