• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua How to check if an item is two-handed or not

Memerto

PHP, JS, LUA, HTML...
Joined
Oct 18, 2009
Messages
131
Solutions
6
Reaction score
25
Hi community!

I'm looking for a way to check if an item(weapon) is two-handed or not. Used the search but got no results for my request. Do you know any function to do that? Didn't know if this is done or not, that's why I put it here and not in the Requests forum. Btw, I'm using tfs 0.3.6pl1.

Thx for reading!
 
Last edited:
Hi community!

I'm looking for a way to check if an item(weapon) is two-handed or not. Used the search but got no results for my request. Do you know any function to do that? Didn't know if this is done or not, that's why I put it here and not in the Requests forum.

Thx for reading!

Look in items.xml to see if it two handed
 
Well, I mean I need a way to check it when I'm scripting. I can make a table with itemid of all two-handed items but I thought maybe there's a quick way to check this.
 
He is looking for something similiar to example:

Code:
if isTwoHanded(2400) then
    -- Weapons is two handed
end
I asume 2400 is the id of a item. So instead of repeating the process or even looking for their ids, he can just use tibia.wikia. He even gets pictures and other neat stuff. After that just ctrl + f in your items.xml. I am 100% sure he already would have finished instead of trying to find a "easier" way of doing it.

The shortest way is the way you know best.
 
The shortest way is the way you know best.

Ofcourse, but we have to explore other ways so we can learn.
However, did some digging in TFS 1.X and tried something like:

Code:
local item = ItemType(itemid)

local slot = item:getSlotPosition() -- gives me 2096 on two handed and 48 on onehanded and other items
if (slot == 2096) then
    -- is two handed
end

I have no clue if this is right way, someone more experienced could probably answer about this little code lol.
 
Alright, I'm looking for a function that cheks it, I need to know if an item is two-handed for a c++/lua system I've made, this is the only point I don't know how to handle.

I've tried getItemInfo(item).slotType, but it doesn't work. Btw, I'm using tfs 0.3.6pl1.
 
Alright, I'm looking for a function that cheks it, I need to know if an item is two-handed for a c++/lua system I've made, this is the only point I don't know how to handle.

I've tried getItemInfo(item).slotType, but it doesn't work. Btw, I'm using tfs 0.3.6pl1.
There is another way @zbizu item parser, you could use that parser in conjunction with a function, some might argue that parsing the items.xml file will use up excessive resources but that really isn't the case when most functions that deal with tiles parse it anyway, im sure it could be altered to accommodate your needs.

https://otland.net/threads/tfs-1-1-items-parser-useful-for-searching-ids.228705/
 
there might be easier way to do that, but I don't know 0.3.6 well so I'll just leave a function which should work on every version of ots here

Code:
two_handed_melee = {
                2377, -- two handed sword
                2378, -- battle axe
                2381, -- halberd
                2387, -- double axe
                2390, -- magic longsword
                2391, -- war hammer
                2393, -- giant sword
                2401, -- staff
                2408, -- warlord sword
                2413, -- broadsword
                2414, -- dragon lance
                2415, -- great axe
                2425, -- obsidian lance
                2426, -- naginata
                2427, -- guardian halberd
                2433, -- enchanted staff
                2440, -- daramian waraxe
                2443, -- ravager's axe
                2444, -- hammer of wrath
                2447, -- twin axe
                2452, -- heavy mace
                2453, -- arcane staff
                2454, -- war axe
                2455, -- crossbow
                2456, -- bow
                2550, -- scythe
                3964, -- ripper lance
                5803, -- arbalest
                6528, -- the avenger
                6553, -- ruthless axe
                7379, -- brutetamer's staff
                7382, -- demonrage sword
                7386, -- mercenary sword
                7391, -- thaian sword
                7392, -- orcish maul
                7402, -- dragon slayer
                7403, -- berserker
                7405, -- havoc blade
                7406, -- blacksteel sword
                7407, -- haunted blade
                7413, -- titan axe
                7414, -- abyss hammer
                7423, -- skullcrusher
                7424, -- lunar staff
                7425, -- taurus mace
                7426, -- amber staff
                7427, -- chaos mace
                7428, -- bonebreaker
                7436, -- angelic axe
                7449, -- crystal sword
                7450, -- hammer of prophecy
                7452, -- spiked squelcher
                7453, -- executioner
                7454, -- glorious axe
                7747, -- fiery blacksteel sword
                7748, -- fiery dragon slayer
                7752, -- fiery headchopper
                7753, -- fiery war axe
                7757, -- fiery orcish maul
                7758, -- fiery war hammer
                7766, -- icy blacksteel sword
                7767, -- icy dragon slayer
                7771, -- icy headchopper
                7772, -- icy war axe
                7776, -- icy orcish maul
                7777, -- icy war hammer
                7857, -- earth blacksteel sword
                7858, -- earth dragon slayer
                7862, -- earth headchopper
                7863, -- earth war axe
                7867, -- earth orcish maul
                7868, -- earth war hammer
                7872, -- energy blacksteel sword
                7873, -- energy dragon slayer
                7877, -- energy headchopper
                7878, -- energy war axe
                7882, -- energy orcish maul
                7883, -- energy war hammer
                8926, -- demonwing axe
                8929, -- the stomper
                8932, -- the calamity
                10301, -- scythe of the reaper
                10303, -- farmer's avenger
                11305, -- drakinata
                11306, -- sai
                11308, -- drachaku
                11309, -- twin hooks
                11323, -- Zaoan halberd
                12613, -- twiceslicer
                13838, -- heavy trident
                13873, -- shimmer bow
                15400, -- deepling staff
                15454, -- guardian axe
                20108, -- pair of iron fists
                22401, -- crude umbral slayer
                22402, -- umbral slayer
                22403, -- umbral master slayer
                22407, -- crude umbral chopper
                22408, -- umbral chopper
                22409, -- umbral master chopper
                22413, -- crude umbral hammer
                22414, -- umbral hammer
                22415, -- umbral master hammer
        }

function isItemTwoHanded(itemid)
return isInArray(two_handed_melee, itemid)
end

if isItemTwoHanded(itemid) then
-- code
end
 
there might be easier way to do that, but I don't know 0.3.6 well so I'll just leave a function which should work on every version of ots here

Code:
two_handed_melee = {
                2377, -- two handed sword
                2378, -- battle axe
                2381, -- halberd
                2387, -- double axe
                2390, -- magic longsword
                2391, -- war hammer
                2393, -- giant sword
                2401, -- staff
                2408, -- warlord sword
                2413, -- broadsword
                2414, -- dragon lance
                2415, -- great axe
                2425, -- obsidian lance
                2426, -- naginata
                2427, -- guardian halberd
                2433, -- enchanted staff
                2440, -- daramian waraxe
                2443, -- ravager's axe
                2444, -- hammer of wrath
                2447, -- twin axe
                2452, -- heavy mace
                2453, -- arcane staff
                2454, -- war axe
                2455, -- crossbow
                2456, -- bow
                2550, -- scythe
                3964, -- ripper lance
                5803, -- arbalest
                6528, -- the avenger
                6553, -- ruthless axe
                7379, -- brutetamer's staff
                7382, -- demonrage sword
                7386, -- mercenary sword
                7391, -- thaian sword
                7392, -- orcish maul
                7402, -- dragon slayer
                7403, -- berserker
                7405, -- havoc blade
                7406, -- blacksteel sword
                7407, -- haunted blade
                7413, -- titan axe
                7414, -- abyss hammer
                7423, -- skullcrusher
                7424, -- lunar staff
                7425, -- taurus mace
                7426, -- amber staff
                7427, -- chaos mace
                7428, -- bonebreaker
                7436, -- angelic axe
                7449, -- crystal sword
                7450, -- hammer of prophecy
                7452, -- spiked squelcher
                7453, -- executioner
                7454, -- glorious axe
                7747, -- fiery blacksteel sword
                7748, -- fiery dragon slayer
                7752, -- fiery headchopper
                7753, -- fiery war axe
                7757, -- fiery orcish maul
                7758, -- fiery war hammer
                7766, -- icy blacksteel sword
                7767, -- icy dragon slayer
                7771, -- icy headchopper
                7772, -- icy war axe
                7776, -- icy orcish maul
                7777, -- icy war hammer
                7857, -- earth blacksteel sword
                7858, -- earth dragon slayer
                7862, -- earth headchopper
                7863, -- earth war axe
                7867, -- earth orcish maul
                7868, -- earth war hammer
                7872, -- energy blacksteel sword
                7873, -- energy dragon slayer
                7877, -- energy headchopper
                7878, -- energy war axe
                7882, -- energy orcish maul
                7883, -- energy war hammer
                8926, -- demonwing axe
                8929, -- the stomper
                8932, -- the calamity
                10301, -- scythe of the reaper
                10303, -- farmer's avenger
                11305, -- drakinata
                11306, -- sai
                11308, -- drachaku
                11309, -- twin hooks
                11323, -- Zaoan halberd
                12613, -- twiceslicer
                13838, -- heavy trident
                13873, -- shimmer bow
                15400, -- deepling staff
                15454, -- guardian axe
                20108, -- pair of iron fists
                22401, -- crude umbral slayer
                22402, -- umbral slayer
                22403, -- umbral master slayer
                22407, -- crude umbral chopper
                22408, -- umbral chopper
                22409, -- umbral master chopper
                22413, -- crude umbral hammer
                22414, -- umbral hammer
                22415, -- umbral master hammer
        }

function isItemTwoHanded(itemid)
return isInArray(two_handed_melee, itemid)
end

if isItemTwoHanded(itemid) then
-- code
end
nice
 
Just use getPlayerSlotItem to check if the item is there in 1 hand, and if there's no item in the other hand.
This is for 0.3.6, but you catch my drift:
Code:
if (getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid ~= 0 and getPlayerSlotItem(cid,CONST_SLOT_RIGHT).itemid == 0) or (getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == 0 and getPlayerSlotItem(cid,CONST_SLOT_RIGHT).itemid ~= 0) then
-- item is worn in 1 hand
end
 
Just use getPlayerSlotItem to check if the item is there in 1 hand, and if there's no item in the other hand.
This is for 0.3.6, but you catch my drift:
Code:
if (getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid ~= 0 and getPlayerSlotItem(cid,CONST_SLOT_RIGHT).itemid == 0) or (getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == 0 and getPlayerSlotItem(cid,CONST_SLOT_RIGHT).itemid ~= 0) then
-- item is worn in 1 hand
end
But that doesn't really tell you if the item you have in your hand is 2 handed, there could be a number of reasons why the OP would want a function that would check if an item is 1 or 2 handed.

When programming we must consider all possibilities not just the convenient ones :)
 
But that doesn't really tell you if the item you have in your hand is 2 handed, there could be a number of reasons why the OP would want a function that would check if an item is 1 or 2 handed.

When programming we must consider all possibilities not just the convenient ones :)

I'm just throwing an idea that might be convenient for the OP. He hasn't said what exactly he wants to use this function for, but this could help in one case or another. In my case, I did this on many occassions when I needed to check if some two handed weapon is worn as a condition.

I also don't know if this would work since i haven't checked what exact kind of values getItemInfo array can return, but I think if getItemInfo(uid).article can return the item's article as written in XML, maybe getItemInfo(uid).slotType could return if it's two handed or not.
 
in tfs 1.2, SLOTP_TWO_HAND = 1 << 11,
I found this by searching the source for the string "both hands" (as in Both hands need to be free) which led me to the return type RETURNVALUE_BOTHHANDSNEEDTOBEFREE, which I then searched for within the source again, which led me to a check in player.cpp within the queryAdd function (called when adding an item to a slot) which contains the condition SLOTP_TWO_HAND
All it takes is a little digging, and I'm sure 0.3.6 would have a similar result, leading to the solution or at least to an answer as to whether such a slot exists in that version.
 
Ofcourse, but we have to explore other ways so we can learn.
However, did some digging in TFS 1.X and tried something like:

Code:
local item = ItemType(itemid)

local slot = item:getSlotPosition() -- gives me 2096 on two handed and 48 on onehanded and other items
if (slot == 2096) then
    -- is two handed
end

I have no clue if this is right way, someone more experienced could probably answer about this little code lol.
48 will trigger for anything that doesn't doesn't have a slotType, as far as I can tell.

So you'd want to getWeaponType..
0 = random object
4 = shield
anything else = weapon

and then use getSlotPosition == 2096 -- to confirm if it's a two handed weapon or not.

soo... here's a usuable function
Lua:
function Item:isItemTwoHandedWeapon()
    local itemId = self:getId()
    local weaponType = ItemType(itemId):getWeaponType()
    if weaponType ~= 0 and weaponType ~= 4 and ItemType(itemId):getSlotPosition() == 2096 then
        return true
    end
    return false
end

But then again, that's just 'to be safe'.

You can probably get away with just the 1 check.
Lua:
function Item:isItemTwoHanded()
    if ItemType(self:getId()):getSlotPosition() == 2096 then
        return true
    end
    return false
end
 
Back
Top