Page 1 of 1

Triggering event directly after Pause

Posted: Wed Jul 31, 2013 6:26 am
by amalia
I wonder if there is a possibility to trigger an event directly after resuming the bot manually from pause.

e.g. searching for nearest waypoint, after playing manually for a while.
The onskillcastevent is not so useful it force you to dismount and messes up since is always called.
Maybe the eventmonitor can used for it but I dont know how.

Edit
Following code added to the onload section of a waypoint works well.
Don“t use it in selfcrossing waypoints and demand of continously doing things.


Code: Select all

<onload>
<!--- ......--->

function myResumeCallback()
resumeCallback()  
 player:updateXYZ();
    __WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z));
end
atResume(myResumeCallback) -- sets the resume callback function
</onload>

Re: Triggering event directly after Pause

Posted: Wed Jul 31, 2013 6:51 am
by rock5
MM is set up to execute what are called callback functions when a script is paused, resumed, errors or terminates normally. So it's very easy to do. Here is some sample code.

Code: Select all

function myResumeCallback()
    resumeCallback() -- call the original callback function.
    -- your code here
end
atResume(myResumeCallback) -- sets the resume callback function

Re: Triggering event directly after Pause

Posted: Wed Jul 31, 2013 9:51 am
by amalia
hey rock

I gave it a try lik that in my waypointfile

Code: Select all

<onload>
.......

function myResumeCallback()
      print("function called");
      __WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z));
end
atResume(myResumeCallback) -- sets the resume callback function
</onload>
edit
then i paused, walked away near to another waypoint and resumed. the bot still tries to continue where it was last time. Debug message IS printed.
Do I use it wrong?


update
When I pause the game and resume it once, no new waypoint is set.
If I pause it, resume it, pause it and resume it again then it works as it should.

It works for me but it feels strange.
So thank you for the hint.

Re: Triggering event directly after Pause

Posted: Wed Jul 31, 2013 1:14 pm
by rock5
You need to update the player coordinates. Add a

Code: Select all

player:updateXYZ()
before the setWaypointIndex.

Re: Triggering event directly after Pause

Posted: Wed Jul 31, 2013 1:55 pm
by Ego95
I like your idea. Wouldn't is be best to add this as default to the bot?

AlterEgo95

Re: Triggering event directly after Pause

Posted: Wed Jul 31, 2013 2:08 pm
by rock5
Not really. There are times when this would cause problems. Example, when you have a complex waypoint file that crisscrosses the same area multiple times. If you pause the script you wouldn't want it to jump to another part of the waypoint file just because the waypoint is closer and bypass necessary waypoints. We are usually very wary about using "__WPL:setWaypointIndex(__WPL:getNearestWaypoint(player.X, player.Z));" for that reason.

Re: Triggering event directly after Pause

Posted: Wed Jul 31, 2013 2:29 pm
by Ego95
Ok, I agree with you. Then maybe add it to the bot and add a profile option which is set to false by default :P

Really great idea. I'll add this to all my scripts :) thanks

Re: Triggering event directly after Pause

Posted: Wed Jul 31, 2013 2:47 pm
by rock5
Ideally it would depend on the waypoint file. You wouldn't want it enabled on complex files but you might want it enabled on simpler files. I'm happy to leave it as it is. It's easy enough to add the above code to the waypoint files and allows the user customize the waypoint selection based on that waypoint file, if they wish.

Re: Triggering event directly after Pause

Posted: Wed Jul 31, 2013 5:38 pm
by amalia
Just for the reason of copy and paste.

I edited the first post with the perfectly working code. Thanks to rock.

Re: Triggering event directly after Pause

Posted: Wed Jul 31, 2013 6:02 pm
by lisa
you forgot to add in the

Code: Select all

resumeCallback()

Re: Triggering event directly after Pause

Posted: Fri Aug 02, 2013 3:07 am
by amalia
I thought somehow this was optional since it is "the orginal one" and I want another one.
Ok I added and changed in working code

Thanks

Re: Triggering event directly after Pause

Posted: Fri Aug 02, 2013 3:21 am
by rock5
You could leave it out but the original function does some things that you would still want it to do.