onPreSkillCast event

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
KillerTHC
Posts: 63
Joined: Tue May 25, 2010 8:49 pm

onPreSkillCast event

#1 Post by KillerTHC » Wed May 26, 2010 7:48 pm

I was on my knight and found a nice 2-h sword so i equiped it and ran RoM-Bot and it tried using the skills requiring my shield! So I though we should have a onPreSkillCast event, so i made it! Gotta love open source!

Okay so it gets triggered before every skill cast so you can check if you have a shield equipped etc... It recieves a value called arg1 which is the spell that is going to be cast. I also added a new function to the inventory class called isEquipped() it returns true or false if the slot you entered currently has an item in it with greater than 0 durability. The slot can be head, gloves, boots, shirt, pants, cloak, belt, shoulder, necklace, ammo, bow, rightring, leftring, rightearring, leftearring, mainhand, offhand, trinket, talisman1, talisman2, talisman3.

talisman1 is slot next to necklace
talisman2 is the first slot under necklace next to shoulder
talisman3 first slot under talisman2 next to gloves

Also with the addition of a new event I added a new test, it tests the return value to be either true of false; if it returns false then the skill that was supposed to be cast will be skipped in the rotation.

Example usage:

Code: Select all

<onPreSkillCast>
local space = "offhand"
	if( arg1.Name == "KNIGHT_SHIELD_OF_ATONEMENT" or arg1.Name == "KNIGHT_WHIRLWIND_SHIELD" ) then
		if( inventory:isEquipped(space) == true) then
			print("Your " ..space.. " is equipped!");
			return true; --Cast the skill like normal
		else 
			print("Your " ..space.. " is'nt equipped!");
			return false; --Not equipped don't cast the skill!
		end
	else
		return true; --We are not interested in this spell so cast it like normal
	end
</onPreSkillCast>
To install just update with SVN!

P.S. Feel free to add this to the official release just add me into the credits :P
Last edited by KillerTHC on Wed Jun 09, 2010 3:42 pm, edited 2 times in total.

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: onPreSkillCast event

#2 Post by Administrator » Wed May 26, 2010 8:32 pm

It would help if you could provide a patch file (if you're using Tortoise SVN, just right click the folder, go to Tortoise SVN, then select Create patch), or could outline all of the changes here. I'll merge it from there.

KillerTHC
Posts: 63
Joined: Tue May 25, 2010 8:49 pm

Re: onPreSkillCast event

#3 Post by KillerTHC » Wed May 26, 2010 9:05 pm

I created the patch file, rar'ed it and uploaded it here. It wouldn't let me upload a .patch file so I that's why I compressed it. The changes are in settings just adding USE_SKILL in the options, as well as in player I added the code to execute a pcall after the script has the skill but before it casts it, then I encapsulated the whole cast and wait sequence in an if that tests USE_SKILL, then I added the isEquipped function to the inventory class.

I have tested the code and it works haven't seen any bugs yet, however the code has not been tested more than 24hrs. Leaving <onPreSkillCast> blank has no affect on the bot.
Attachments
onPreSkillCast.rar
(3.08 KiB) Downloaded 216 times

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: onPreSkillCast event

#4 Post by Administrator » Wed May 26, 2010 9:51 pm

Can you give more clarification on USE_SKILL? Is it supposed to be used like a state-machine? That is, once it's set in your profile, you're done, or does it automatically reset back to it's default state after each pre-skill event so that you can use this to cancel a skill cast?

If it's the later, then I think simply returning true or false would be a cleaner, easier solution.

KillerTHC
Posts: 63
Joined: Tue May 25, 2010 8:49 pm

Re: onPreSkillCast event

#5 Post by KillerTHC » Thu May 27, 2010 10:57 am

USE_SKILL is default set at true and gets set automatically to true after every onPreSpellCast event. It's their so you can stop the bot from casting a spell. Your solution does sound cleaner and easier just I never thought of it lol, I'm also slightly new to Lua so that's why I wouldn't think of it.

User avatar
Administrator
Site Admin
Posts: 5306
Joined: Sat Jan 05, 2008 4:21 pm

Re: onPreSkillCast event

#6 Post by Administrator » Fri May 28, 2010 6:13 pm

I've committed this change with revision 447. The only change I've made is that you will return false to cancel spell casting. Thanks for your work on this.

KillerTHC
Posts: 63
Joined: Tue May 25, 2010 8:49 pm

Re: onPreSkillCast event

#7 Post by KillerTHC » Fri May 28, 2010 7:31 pm

Sounds good. I plan to continue to help develop this bot because I use it so anything I come across that is not there I will try to add.

filipsworks
Posts: 53
Joined: Mon May 10, 2010 10:37 am

Re: onPreSkillCast event

#8 Post by filipsworks » Sun May 30, 2010 2:26 am

Can U use language codes in

Code: Select all

 print("Your " ..space.. " is equipped!"); or  print("Your " ..space.. " isn't equipped!");
? This will make it easier to translate and makes bot more "compact"...

KillerTHC
Posts: 63
Joined: Tue May 25, 2010 8:49 pm

Re: onPreSkillCast event

#9 Post by KillerTHC » Tue Jun 01, 2010 3:10 pm

Those commands are in your actual profile so I shouldn't be adding things to the language file. You can simply stick the string in google translate to get an easy translation. Sorry if that doesn't help.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 29 guests