onLeaveCombat event for Waypoint files

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
Hedon
Posts: 5
Joined: Mon May 28, 2012 8:16 am

onLeaveCombat event for Waypoint files

#1 Post by Hedon » 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

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: onLeaveCombat event for Waypoint files

#2 Post by rock5 » Tue May 29, 2012 1:52 pm

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.

Code: Select all

function settings.profile.events.onLeaveCombat()
  ...
  ...
  ...
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.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Hedon
Posts: 5
Joined: Mon May 28, 2012 8:16 am

Re: onLeaveCombat event for Waypoint files

#3 Post by Hedon » Tue May 29, 2012 4:22 pm

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.

Code: Select all

<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>

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: onLeaveCombat event for Waypoint files

#4 Post by lisa » Tue May 29, 2012 5:45 pm

--=== moved ===--
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: onLeaveCombat event for Waypoint files

#5 Post by rock5 » Tue May 29, 2012 11:36 pm

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,

Code: Select all

   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.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest