• 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!

Check if target item is weapon or armor

sawkagt

New Member
Joined
May 17, 2022
Messages
4
Reaction score
1
Hi,

I'm trying to create a tier system where I use an item on another item to increase target item's action ID.
Problem is, I want this system to work only with weapons and armors, but I didn't figure out how to check that (note that target item can be anywhere - ground, backpack, equipped, etc.)

So far, I am using the following code:

Lua:
local tierpotion = Action()

function tierpotion.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local targetItem = target.itemid
    if not targetItem then
        player:say("Process not started!",TALKTYPE_MONSTER_SAY)
        return true
    end

    -- if targetItem IS WEAPON OR ARMOR then
    
    local chance = math.random(100)   
        if chance >= 41 then
            if target.actionid == 0 then
                target:setActionId(1000)
                player:sendMagicEffect(CONST_ME_MAGIC_GREEN)
            else
                player:say("Process failed!",TALKTYPE_MONSTER_SAY)
                player:sendMagicEffect(CONST_ME_BLOCKHIT)
            end
            return item:remove(1)
        end
        
    -- end

end
tierpotion:id(36170)
tierpotion:register()

Any ideas? I don't mind reviewing the code to work with a list of IDs and check if target item ID is in the list or something like that, but I don't know how to do that as well.

Thanks!
 
Lua:
    local it = ItemType(targetItem:getId())
    if it:getWeaponType() ~= WEAPON_NONE or it:getArmor() ~= 0 then
        -- code
    end
 
Last edited:
Lua:
    local it = ItemType(targetItem:getId())
    if it:getWeaponType() ~= WEAPON_NONE or it:getArmor() then
        -- code
    end

Thanks!
It worked perfectly for weapons, a little fix I had to make was:

Lua:
    --local it = ItemType(targetItem:getId())
    local it = ItemType(target:getId())
    if it:getWeaponType() ~= WEAPON_NONE then
        -- code
    end

Since targetItem is already a ID, local it was resulting in an error, but changing from targetItem to target fixed it.
I'll be posting a complete guide on how to make this tier system I'm working on and credit you for helping out with the coding :)

For the armors, I had to make some changes but figured it out:

Code:
    local it = ItemType(target:getId())
    if it:getType() ~= ITEM_TYPE_ARMOR then
        player:say("Process not started! This item cannot be upgraded.",TALKTYPE_MONSTER_SAY)
        return true   
    end
 
Last edited:
For the armors, I had to make some changes but figured it out:
Code:
    local it = ItemType(target:getId())
    if it:getType() ~= ITEM_TYPE_ARMOR then
        player:say("Process not started! This item cannot be upgraded.",TALKTYPE_MONSTER_SAY)
        return true 
    end
Lua:
if target:usesSlot(CONST_SLOT_ARMOR) and it:getArmor() ~= 0 then
 
Back
Top