Check if weapon is 1-h or 2-h

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

Check if weapon is 1-h or 2-h

#1 Post 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
Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

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

#2 Post 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
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

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

#3 Post 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.
  • 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
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

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

#4 Post 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
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
Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

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

#5 Post 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-)
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

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

#6 Post 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?
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
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

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

#7 Post 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.
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
Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

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

#8 Post 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!
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

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

#9 Post 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.
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: Check if weapon is 1-h or 2-h

#10 Post 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.
  • 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
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

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

#11 Post 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.
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
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

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

#12 Post 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.
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: Check if weapon is 1-h or 2-h

#13 Post 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.
  • 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
Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

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

#14 Post 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?
Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

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

#15 Post by Mushroomstamp »

Also, how can I make it recognize a weapon change without restarting the bot?
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

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

#16 Post 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.
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
Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

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

#17 Post 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. =)
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

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

#18 Post by lisa »

that means the required buff isnt working then, hmmm
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
Mushroomstamp
Posts: 210
Joined: Wed Oct 27, 2010 11:34 am

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

#19 Post 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
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

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

#20 Post 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.
  • 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