I was looking at ways to add this event to waypoints without modding the library classes but came up short. Here's a patch to player.lua and waypointlist.lua that allows you to define <onLeaveCombat> in your waypoint file just like <onLoad>. As with the player profile <onLeaveCombat> definition it is called every time you leave combat as well.
Index: classes/player.lua
===================================================================
--- classes/player.lua (revision 718)
+++ classes/player.lua (working copy)
@@ -1613,6 +1613,15 @@
error(msg);
end
end
+
+ -- check for onLeaveCombat in waypoint file
+ if (type(__WPL.onLeaveCombatEvent) == "function") then
+ local status,err = pcall(__WPL.onLeaveCombatEvent);
+ if( status == false ) then
+ local msg = sprintf(language[85], err);
+ error(msg);
+ end
+ end
-- give client a little time to update battle flag (to come out of combat),
Index: classes/waypointlist.lua
===================================================================
--- classes/waypointlist.lua (revision 718)
+++ classes/waypointlist.lua (working copy)
@@ -17,6 +17,8 @@
self.Type = 0; -- UNSET
self.ForcedType = 0; -- Wp type to overwrite current type, can be used by users in WP coding
+
+ self.onLeaveCombatEvent = nil;
end
);
@@ -86,6 +88,15 @@
self.onLoadEvent = nil;
end;
end
+ elseif( string.lower(name) == "onleavecombat" ) then
+ if( string.len(action) > 0 and string.find(action, "%w") ) then
+ self.onLeaveCombatEvent = loadstring(action);
+ assert(self.onLoadEvent, sprintf(language[152]));
+
+ if( _G.type(self.onLeaveCombatEvent) ~= "function" ) then
+ self.onLeaveCombatEvent = nil;
+ end;
+ end
end
end
Doesn't really make sense to add an onLeaveCombat to the waypoint file. If all you want to do is edit the profile onLeaveCombat function, you can edit it in the onLoad section. You just need to know where it is. The profile events are stored in settings.profile.events. So you can do this.
Now that's slick. I wanted to save the profile event too so came up with this in my waypoint onLoad. The original definition is saved and called in the waypoint redefinition.
<onLoad>
--save the original profile function pointer if its defined or define a blank function if not
if (type(settings.profile.events.onLeaveCombat) ~= "function") then
onLeaveCombatProfile = function (unused) return; end;
else
onLeaveCombatProfile = settings.profile.events.onLeaveCombat;
end
function settings.profile.events:onLeaveCombat()
onLeaveCombatProfile();
... waypoint event handling definition here
end
</onLoad>
That's the way to do it except I usually check if the function exists first or else it will be nesting the onleavecombat function if the script restarts itself such as when it changes character. So,
If not onLeaveCombatProfile then
if (type(settings.profile.events.onLeaveCombat) ~= "function") then
onLeaveCombatProfile = function (unused) return; end;
else
onLeaveCombatProfile = settings.profile.events.onLeaveCombat;
end
end
Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.