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

Only allow using item if it's equipped

pink_panther

Excellent OT User
Joined
Sep 10, 2016
Messages
1,171
Solutions
13
Reaction score
613
Location
Kazordoon
Is there a way to have a use action for using an item, but only allow it to work if the item is in a certain equipment slot?

Eg a Armor item that has a use option, but only while it's in your armor slot?
 
Lua:
local armor = player:getSlotItem(CONST_SLOT_ARMOR)
if armor and armor:getId() == ARMOR_ID then
—- script —-
end
This doesn't actually check if the item being used is equipped tho.

This should do the trick
Lua:
local usuableArmors = {
--[itemid]
    [1111] = {slot = CONST_SLOT_ARMOR}
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pos = item:getPosition()
    if usuableArmors[item:getId()].slot == pos.y then
        -- do action
    end
    return true
end

for v, k in pairs(usuableArmors) do
    action:id(v)
end
action:register()
 
This doesn't actually check if the item being used is equipped tho.

This should do the trick
Lua:
local usuableArmors = {
--[itemid]
    [1111] = {slot = CONST_SLOT_ARMOR}
}

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pos = item:getPosition()
    if usuableArmors[item:getId()].slot == pos.y then
        -- do action
    end
    return true
end

for v, k in pairs(usuableArmors) do
    action:id(v)
end
action:register()

Not specifically the the item being worn, i think it checks if the same item you're using is also in that slot though?

So technically you could be wearing the item and have a 2nd one somewhere else and it would still allow you to use it.

For your action, im using TFS 1.2, so i dont think i can do that.
 
Not specifically the the item being worn, i think it checks if the same item you're using is also in that slot though?

So technically you could be wearing the item and have a 2nd one somewhere else and it would still allow you to use it.

For your action, im using TFS 1.2, so i dont think i can do that.
lol it's such an easy conversion. just delete a few lines ;)

Lua:
local usuableArmors = {
--[itemid]
    [1111] = {slot = CONST_SLOT_ARMOR}
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local pos = item:getPosition()
    if usuableArmors[item:getId()].slot == pos.y then
        -- do action
    end
    return true
end
 
Back
Top