Joseph Posted September 5, 2014 Share Posted September 5, 2014 How do i add my own listener onto one of my scripts? Link to comment Share on other sites More sharing options...
Dog_ Posted September 5, 2014 Share Posted September 5, 2014 pls elaborate Link to comment Share on other sites More sharing options...
Joseph Posted September 5, 2014 Author Share Posted September 5, 2014 pls elaborate I would like to add in a inventory Listener Link to comment Share on other sites More sharing options...
Wizard Posted September 5, 2014 Share Posted September 5, 2014 add me on skype, i can show you how. Link to comment Share on other sites More sharing options...
Dog_ Posted September 5, 2014 Share Posted September 5, 2014 I would like to add in a inventory Listener could just run it on a different thread 2 Link to comment Share on other sites More sharing options...
Mysteryy Posted September 6, 2014 Share Posted September 6, 2014 I would like to add in a inventory Listener If you know how to multithread you can easily make a listener in a new class that implements Runnable. You can basically make this new thread constantly watch your inventory slots and check if anything changes, or whatever you are trying to make it do. Just make a new class that implements Runnable, make that class do whatever you want, then in Script thread, Thread thread = new Thread(ClassName) then start the thread. I haven't used that in a while, but its something like that. Just look up the basics of multi threading and you can easily find how to make it. ^_^ Link to comment Share on other sites More sharing options...
Swizzbeat Posted September 6, 2014 Share Posted September 6, 2014 Whatever you do, at least add a small sleep in between inventory updates. You don't want to kill your CPU because you want to be notified the exact millisecond your inventory changes. Waiting for even just a second will consume such little resources it won't even make a noticeable impact on the CPU usage of your script. Link to comment Share on other sites More sharing options...
Joseph Posted September 6, 2014 Author Share Posted September 6, 2014 Whatever you do, at least add a small sleep in between inventory updates. You don't want to kill your CPU because you want to be notified the exact millisecond your inventory changes. Waiting for even just a second will consume such little resources it won't even make a noticeable impact on the CPU usage of your script. How big of a sleep you think it's good, 200 mil second Link to comment Share on other sites More sharing options...
Swizzbeat Posted September 6, 2014 Share Posted September 6, 2014 How big of a sleep you think it's good, 200 mil secondMore like 1200 milliseconds (2 game ticks) unless you absolutely need to be notified of a change right away. Link to comment Share on other sites More sharing options...
Botre Posted September 6, 2014 Share Posted September 6, 2014 Just curious, what exactly would it be listening for ? :| Link to comment Share on other sites More sharing options...
Joseph Posted September 6, 2014 Author Share Posted September 6, 2014 (edited) Just curious, what exactly would it be listening for ? :| when you have a change of items in the inventory. tbh im still a little confused on how to set it up. Ive tried so many different things Edited September 6, 2014 by josedpay Link to comment Share on other sites More sharing options...
Botre Posted September 6, 2014 Share Posted September 6, 2014 (edited) when you have a change of items in the inventory. tbh im still a little confused on how to set it up. Ive tried so many different things If you are going to compare inventories for equality, couldn't you just use these lines (at appropriate places of course,not stacked like this )? Item[] compareThis = getInventory().getItems(); Item[] withThis = getInventory().getItems(); boolean equaliThis = compareThis != null && withThis != null && Arrays.equals(compareThis , withThis); Edited September 6, 2014 by Botrepreneur Link to comment Share on other sites More sharing options...
Dog_ Posted September 6, 2014 Share Posted September 6, 2014 when you have a change of items in the inventory. tbh im still a little confused on how to set it up. Ive tried so many different things Cache them and then compare the cache to the current items 1 Link to comment Share on other sites More sharing options...
Swizzbeat Posted September 7, 2014 Share Posted September 7, 2014 when you have a change of items in the inventory. tbh im still a little confused on how to set it up. Ive tried so many different things Depends what you're attempting to monitor and how you want to receive notifications about changes. This should help you get started (or provide an answer for you): http://osbot.org/forum/topic/51856-inventory-monitor-keep-live-track-of-your-items/ Link to comment Share on other sites More sharing options...
Joseph Posted September 7, 2014 Author Share Posted September 7, 2014 I already created my own listener, it just people were telling me to put it in a thread, which make sences. And have the thread loop it's self. So far I have created the thread started it once. And that's it -.- Link to comment Share on other sites More sharing options...