Page 1 of 1

Does this event exist?

Posted: Sun Jan 02, 2011 2:17 pm
by Dayquil
I was wondering if there is currently an event sort of like onLoad in the waypoint file.
Except this event would fire every time a waypoint is completed/processed, something like onWaypoint.

This would be useful to check for things as each waypoint gets processed, and not have to repeat the code in each waypoint, for instance if a daily gets done after harvesting at a certain item, then you can use the event to see if it that completed the quest and then redirect the character to another indexed return path dynamically. Or if you want to make sure a buff is on your character at all possible times, like rouge's hide for example. Checking as you go through each waypoint that you are hidden, and reapply hide if something like going into combat temporarily took you out of hide mode.

There may be something already like this, if so is please provide an example.

Re: Does this event exist?

Posted: Sun Jan 02, 2011 8:11 pm
by rock5
I thought of something like this too but it's not really practical.

An easy solution I use is to add a function to the onLoad section of the waypoint file where you include all the commands you want to repeat at the waypoints, then just add the function to all the waypoints you want to do those commands. eg,

Code: Select all

<waypoints>
    <onLoad>
        function commands()
            ....
            ....
            ....
        end
    </onLoad>
    <waypoint x="nn" z="nn"> commands() </waypoint>
    <waypoint x="nn" z="nn"> commands() </waypoint>
    <waypoint x="nn" z="nn"> commands() </waypoint>
    <waypoint x="nn" z="nn">  </waypoint>
    <waypoint x="nn" z="nn"> commands() </waypoint>
</waypoints>
This also gives you more control as you can choose not to add it to certain waypoints, for example waypoints that don't have clear access to the return path.

Re: Does this event exist?

Posted: Sun Jan 02, 2011 8:56 pm
by jduartedj
I must say that in my point of view a profile <onWaypoint> event would make a lot of sense, mostly for checking some stuff and so on.
Take using this:

Code: Select all

UseFood("Potion: Unbridled Enthusiasm","Unbridled Enthusiasm");
if the waypoint file has no combat, where can i put it?
onload? what if if lasts for more than 1h?
onskillcast? what if I don't use buffs?

I think many of use are checking/using stuff in the onCombat event because we have no other reliable 'frequent' event to check/use it.

in such case onWaypoint would make sense to me.

Re: Does this event exist?

Posted: Sun Jan 02, 2011 9:29 pm
by Dayquil
Yea rock that seems like a good enough work around. I guess I could just make an addon if I wanted the checks to be reusable and create a function in the onLoad event for specific waypoint situations.

Thanks.

Re: Does this event exist?

Posted: Mon Jan 03, 2011 12:11 am
by rock5
jduartedj wrote:if the waypoint file has no combat, where can i put it?
onload? what if if lasts for more than 1h?
onskillcast? what if I don't use buffs?
True, but then, if you really think about it, what you want is not to execute some commands at the waypoints but to execute some commands on a regular basis. Maybe what we need is some option to setup timed events. Wait a second, aren't there timed events? I believe you use registerTimer to set them up. You could probably use it anywhere like the onLoad section of a profile or waypoint file. I'm not sure how we could change rombot to make user friendly options to set them up, though.

Re: Does this event exist?

Posted: Mon Jan 03, 2011 7:51 am
by jduartedj
maybe a Timed (or Timer) event is in order?

Code: Select all

<Timed time="xxxx">
-- since onLoad this event is fired at every xxxx ms
-- this is used for a used-based regular event
</Timed>
And from here you'd create this event upon the profile creation and enable it when the bot starts.

Only issue I see here is if people want different intervals? add an even id?

Code: Select all

<Timed time="xxxx" id="#"> </Timed>
or maybe it really isn't necessary it'd stack up all occurrences of the Timed XML tag and make the events from that stack.

What may be usefull is a time offset.

Code: Select all

<Timed time="xxxx" offset="xxxx"></Timed>
but only as optional ofc.

Re: Does this event exist?

Posted: Mon Jan 03, 2011 11:13 am
by rock5
I'm not sure what you mean by stacks and offsets but, yes, we would probably need to be able to create multiple timed events with different durations. Or maybe that would be too complex. Maybe having the ability to set up 1 timed event, like your example above, in your profile or waypoint file would be enough?

The way I think registerTimer works is to allow you to register multiple timers and checks them whenever yrest is used. Which raises a concern. What if a timed event takes awhile to execute like with some RoMScript commands? It's possible it could play havoc with the regular running of the bot.

Re: Does this event exist?

Posted: Mon Jan 03, 2011 4:34 pm
by jduartedj
rock5 wrote:I'm not sure what you mean by stacks and offsets but, yes, we would probably need to be able to create multiple timed events with different durations. Or maybe that would be too complex. Maybe having the ability to set up 1 timed event, like your example above, in your profile or waypoint file would be enough?

The way I think registerTimer works is to allow you to register multiple timers and checks them whenever yrest is used. Which raises a concern. What if a timed event takes awhile to execute like with some RoMScript commands? It's possible it could play havoc with the regular running of the bot.
Good point, Lua doesn't have 'true' threads! it might slow down the bot a little but for knowledge sake I think we should at least test this. do a simple thing, 1 timed event on the profile that is triggered at the bot start. We can even make it simpler by making it a fixed value like 2500ms for test sake. So if the XML parses a "<Timed>" tag the th bot fires a Timer that execute whatever is inside those tags every 2.5 secs.

P.S.: By stack I mean having loads of timed eventes stored in memory to be executed a "stack of events", and by offset I mean that it starts with an offset and not at T=0 ms, so event 'A' starts at 0 but event 'B' (offset=250ms) starts at 250ms.