Page 1 of 1

Check if weapon is 1-h or 2-h

Posted: Fri Jul 15, 2011 10:08 am
by Mushroomstamp
I want my character to cast Tactical Attack after casting Slash only if I have a 2-h weapon equipped. Conversely, cast Thunder after Open Flank, if I have a one handed weapon equipped. What code will make that happen?

Code: Select all

if arg1.Name == "WARRIOR_PROBING_ATTACK" then
    player:cast("WARRIOR_OPEN_FLANK")
    -- if 1h weapon then
        player:cast("WARRIOR_THUNDER")
    end
    -- yrest needed?          
elseif arg1.Name == "WARRIOR_SLASH" then
    -- if 2h weapon then  
        player:cast("WARRIOR_TACTICAL_ATTACK")
    end        		
    -- yrest needed?
end

Re: Check if weapon is 1-h or 2-h

Posted: Fri Jul 15, 2011 11:36 am
by Mushroomstamp
I found GetInventoryItemType browsing the Wiki and I think that might be the answer.

Code: Select all

local eqType = GetInventoryItemType(unit, invPos) 
It will check my off-hand, (invPos=16), and return 0 for equipped armor, 1 for equipped weapon, and -1 if the slot is empty. Four questions;
Will it see 0 as being greater than -1, or do I need to make the if statement "not >= 0"?
Do I need the local line, or can I go right into the "if" statment?
What should be where "unit" is, in the code?
And is the yrest needed?

Code: Select all

if arg1.Name == "WARRIOR_SLASH" then
    local eqType = GetInventoryItemType(unit, 16)
    if 0 > GetInventoryItemType(unit, 16) then
       player:cast("WARRIOR_TACTICAL_ATTACK")
    end
    yrest(100)
end

Re: Check if weapon is 1-h or 2-h

Posted: Fri Jul 15, 2011 11:38 pm
by rock5
I don't know how that function will help you. It's doesn't distinguish between types of weapons. I don't think you can get sub types from any game function.

I could probably come up with a solution for inventory items because they have 3 levels of "types" but not equiped items.

Soon I will be making a general purpose item class that "inventoryitem", "equipeitem" and "bankitem" will share. When I do that, then it will be possible. I don't think it's possible at the moment.

Re: Check if weapon is 1-h or 2-h

Posted: Fri Jul 15, 2011 11:55 pm
by lisa
I think the theory was if there is something in offhand(possibly shield) then he is probably using a 1 hand weapon. If nothing in offhand then he is probably using a 2 hand weapon.

If it was me I would just check the name of the weapon equiped, since you know your own weapons you would know which skills can be used with which weapon. Name is something you can deff get.


Your code should look something like this, I added in a print so you can see what the type actually is, for troubleshooting.

Code: Select all

if arg1.Name == "WARRIOR_SLASH" then
    local eqType = RoMScript('GetInventoryItemType("player", 16)')
printf("Type is "..eqType.."\n")
    if 0 > eqType  then
       player:cast("WARRIOR_TACTICAL_ATTACK")
    end
    yrest(100)
end

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 12:11 am
by Mushroomstamp
Lisa is right. I figured I just need to check the off-hand. If nothing is equipped, skip Thunder and use Tactical Attack... and vice-versa.

I want a "copy-and-paste" code to cover all my characters, so I don't consider checking the name to be an option.

So back to the code... if I can confirm whether or not I need to replace "unit" with something, (and what it needs replaced with, if something), I can get to testing. 8-)

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 12:37 am
by lisa
unit is for "player" "target" "party1" "focus"

in your case "player" which you can see in the code I did in my last post, did you try it?

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 12:46 am
by lisa
If you are using it for multiple characters then I would suguest doing a userfunction and calling it on load.

Code: Select all

function checkwarrskills()
local eqType = RoMScript('GetInventoryItemType("player", 16)')

if eqType ~= 0 and eqType ~= 1 then -- 2 hand weapon.
--=== set weapon skills to true and false accordingly===--
settings.profile.skills.WARRIOR_***.AutoUse = false -- change *** to the skill you don't want to use.
settings.profile.skills.WARRIOR_***.AutoUse = true -- change *** to the skill you do want to use.

else -- 1 hand weapon

settings.profile.skills.WARRIOR_***.AutoUse = false -- change *** to the skill you don't want to use.
settings.profile.skills.WARRIOR_***.AutoUse = true -- change *** to the skill you do want to use.
end
end
hopefully you get the idea.

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 1:38 am
by Mushroomstamp
Wow, I apologize. I would have bet my life that code was not in your post before I posted! I don't know how I missed it. :oops: I need to go to bed. Thanks for the help!

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 2:37 am
by lisa
I have a bad habbit of editing posts =(

I haven't tested that code but I am thinking it might need to be

Code: Select all

settings.profile.skills[WARRIOR_***].AutoUse = false
notice the [ ]

so if the code doesn't work the way I posted previously then try using this format.

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 11:02 am
by rock5
lisa wrote:I think the theory was if there is something in offhand(possibly shield) then he is probably using a 1 hand weapon. If nothing in offhand then he is probably using a 2 hand weapon.
Sorry, didn't pick up on that. Probably read the post too quick.
lisa wrote:local eqType = RoMScript('GetInventoryItemType("player", 16)')
Why use a RoMScript command? If all you want to do is see if you have something in your off hand just check inventory.EquipSlots[17].

Code: Select all

if inventory.EquipSlots[17].Empty then -- 2 hand weapon
  ...
else -- 1 hand weapon
  ...
end
lisa wrote:I haven't tested that code but I am thinking it might need to be

Code: Select all

settings.profile.skills[WARRIOR_***].AutoUse = false
notice the [ ]
Neither will work. The skills are listed by number, ie. [1],[2],[3],[4] etc. You would have to search for the skill and then change it's value.

Wasn't there a discusion about making a function to change skill values? If not we should probably add one. It would be easy enough to do.

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 11:43 am
by lisa
So something like this?

Code: Select all

<onload>
local tactical
local thunder

for k,v in pairs(settings.profile.skills) do
if v == "WARRIOR_TACTICAL_ATTACK" then tactical = k end
if v == "WARRIOR_THUNDER" then thunder = k end
end

if inventory.EquipSlots[17].Empty then
--=== 2 hand weapon ===--
settings.profile.skills[tactical].AutoUse = true
settings.profile.skills[thunder].AutoUse = false
else
--=== 1 hand weapon ===--
settings.profile.skills[thunder].AutoUse = true
settings.profile.skills[tactical].AutoUse = false
end
</onload>
Which is all nice and fine but back to the original question, I got side tracked sorry =)

Now bit I have concerns with is that it won't use the skill until after the code is done. So would doing a player:cast of the same skill create a loop??
If so then how to make it use the skill without creating a loop?

Code: Select all

if arg1.Name == "WARRIOR_PROBING_ATTACK" then
player:cast("WARRIOR_PROBING_ATTACK")
player:cast("WARRIOR_OPEN_FLANK")
if not inventory.EquipSlots[17].Empty then
player:cast("WARRIOR_THUNDER")
return false
end

if arg1.Name == "WARRIOR_SLASH" then
if inventory.EquipSlots[17].Empty then
player:cast("WARRIOR_SLASH")
player:cast("WARRIOR_TACTICAL_ATTACK")
else
return true
end
end
I feel like there should be a better way, maybe just add in a buffrequirement?? or debuff as the case may be.

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 11:48 am
by lisa
I'm trying to kick the edit habbit, so posting again lol

Turns out WARRIOR_THUNDER has a required buff, so just setting it to autouse or not should do the trick.

So maybe just add a buff requirement for WARRIOR_TACTICAL_ATTACK ??

and then just use the onload that sets autouse for you.

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 12:37 pm
by rock5
lisa wrote:So something like this?
Yes, but it should be

Code: Select all

if v.Name == "WARRIOR_TACTICAL_ATTACK" then
etc...
lisa wrote:Now bit I have concerns with is that it won't use the skill until after the code is done. So would doing a player:cast of the same skill create a loop??
I don't think so. I believe the onSkillCast event is not triggered when the skill is cast from whithin the onSkillCast event.

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 1:05 pm
by Mushroomstamp
lisa wrote:Turns out WARRIOR_THUNDER has a required buff, so just setting it to autouse or not should do the trick.
I wish... I've never had any luck letting MM take care of the skill rotation. Example from yesterday, without my onSkillCast code, bot would often call Open Flank as a first attack, even though the mob was not "Vulnerable". I've had the same issue with other skills as well, so I now just use onSkillCast to be sure mob is debuffed, and all skills requiring debuffs are set to autouse="false".

So it's working with;

Code: Select all

		if arg1.Name == "WARRIOR_PROBING_ATTACK" then
			player:cast("WARRIOR_OPEN_FLANK")
			if not inventory.EquipSlots[17].Empty then
				player:cast("WARRIOR_THUNDER")
			end
			yrest(100)
		elseif arg1.Name == "WARRIOR_SLASH" then
			if inventory.EquipSlots[17].Empty then
				player:cast("WARRIOR_TACTICAL_ATTACK")
			end
			yrest(100)
		end
... except when something is on cooldown, obviously. How could I implement GetSkillCooldown in onPreSkillCast to cancel the skill call?

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 9:09 pm
by Mushroomstamp
Also, how can I make it recognize a weapon change without restarting the bot?

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 9:14 pm
by lisa
Mushroomstamp wrote: I wish... I've never had any luck letting MM take care of the skill rotation. Example from yesterday, without my onSkillCast code, bot would often call Open Flank as a first attack, even though the mob was not "Vulnerable"
did it use the skill or just try to use it?
trying to use it is fine aslong as it only actually uses it if the required buff exists.

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 9:53 pm
by Mushroomstamp
lisa wrote:did it use the skill or just try to use it?
It calls it in MM and I get the skill requirement error in-game. Harmless I know, but I'd rather it not happen. =)

Re: Check if weapon is 1-h or 2-h

Posted: Sat Jul 16, 2011 10:17 pm
by lisa
that means the required buff isnt working then, hmmm

Re: Check if weapon is 1-h or 2-h

Posted: Sun Jul 17, 2011 12:17 am
by Mushroomstamp
lisa wrote:that means the required buff isnt working then, hmmm
Yeah, never has... hence onSkillCast. =)

Will GetSkillCooldown work like this?

Code: Select all

		if arg1.Name == "WARRIOR_SLASH" then
			if inventory.EquipSlots[17].Empty and
			1 > ("GetSkillCooldown(4,4)") and
			player.Rage > 14 then
				player:cast("WARRIOR_TACTICAL_ATTACK")
			end
			yrest(100)
		end

Re: Check if weapon is 1-h or 2-h

Posted: Sun Jul 17, 2011 10:36 am
by rock5
GetSkillCooldown is an in game function so try

Code: Select all

         1 > RoMScript("GetSkillCooldown(4,4)") and
Also, because this will take the longest time, I would do it last after the rage check.