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

Solved Only use item X if you have nothing equipped

freaked1

Active Member
Joined
Jan 30, 2008
Messages
486
Solutions
5
Reaction score
29
Location
Sweden
Hello again!
EDIT: TFS 1.1
I stumble upon another problem with getting a lua script to work for me.
I want the script to check if you have anything equipped (except backpack).

If you have something equipped in either slot for example ring, amulet or weapon/shield you can't use the item to increase your max health/mana.

Script:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
local player = Player(cid)
local config = {
addmana=20,
addhealth=20,
}
player:setMaxHealth(player:getMaxHealth()+config.addhealth)
player:setMaxMana(player:getMaxMana()+config.addmana)
doPlayerSendTextMessage(cid, 22, "Your max health has been increased by "..config.addhealth.." and your max mana by "..config.addmana.."!")
doRemoveItem(item.uid,1)
return TRUE
end

I have not managed to get the right, tried
"if getPlayerSlotItem(cid, 5) ==" I don't know if 5 is weapon slot or what and I think that requires a specific itemID. I want it to check if you have any item what so ever in either slot except backpack slot and if you have it will not continue.

Sorry if this is posted at the wrong place and should be posted under requests, I couldn't tell as it is kind of fits on both places.

Thank you so much in advance!
 
Last edited:
Solution
try this
Code:
local config = {
    healthGain = 20,
    manaGain = 20
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    local unEquipped = true
    local playerPos = player:getPosition()
    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        if (slot ~= CONST_SLOT_BACKPACK) then
            if player:getSlotItem(slot) then
                unEquipped = false
                break
            end
        end
    end
    if unEquipped then
        player:setMaxHealth(player:getMaxHealth() + config.healthGain)
        player:setMaxMana(player:getMaxMana() + config.manaGain)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("Your max health has increased by %d, and your max mana...
try this
Code:
local config = {
    healthGain = 20,
    manaGain = 20
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    local player = Player(cid)
    local unEquipped = true
    local playerPos = player:getPosition()
    for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
        if (slot ~= CONST_SLOT_BACKPACK) then
            if player:getSlotItem(slot) then
                unEquipped = false
                break
            end
        end
    end
    if unEquipped then
        player:setMaxHealth(player:getMaxHealth() + config.healthGain)
        player:setMaxMana(player:getMaxMana() + config.manaGain)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, ("Your max health has increased by %d, and your max mana has increased by %d."):format(config.healthGain, config.manaGain))
        playerPos:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        item:remove(1)
    else
        player:sendCancelMessage("You must unequip all items first.")
        playerPos:sendMagicEffect(CONST_ME_POFF)
    end
    return true
end
 
Last edited:
Solution
Back
Top