Page 1 of 1

onPreSkillCast event

Posted: Wed May 26, 2010 7:48 pm
by KillerTHC
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

Re: onPreSkillCast event

Posted: Wed May 26, 2010 8:32 pm
by Administrator
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.

Re: onPreSkillCast event

Posted: Wed May 26, 2010 9:05 pm
by KillerTHC
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.

Re: onPreSkillCast event

Posted: Wed May 26, 2010 9:51 pm
by Administrator
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.

Re: onPreSkillCast event

Posted: Thu May 27, 2010 10:57 am
by KillerTHC
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.

Re: onPreSkillCast event

Posted: Fri May 28, 2010 6:13 pm
by Administrator
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.

Re: onPreSkillCast event

Posted: Fri May 28, 2010 7:31 pm
by KillerTHC
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.

Re: onPreSkillCast event

Posted: Sun May 30, 2010 2:26 am
by filipsworks
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"...

Re: onPreSkillCast event

Posted: Tue Jun 01, 2010 3:10 pm
by KillerTHC
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.