onLeaveCombat event for Waypoint files
Posted: Tue May 29, 2012 1:34 pm
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.
Code: Select all
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