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

TFS 1.2 Move Item For bp

lazarus321

Member
Joined
May 8, 2017
Messages
209
Reaction score
20
Do you have any function to move the equipped item to bp?
Ex. I use a spell that makes the equipped helmet go to bp.
Can you do that?
 
Solution
You can use a function like this:
Lua:
function Player.moveSlotToBackpack(self, slot)
    if slot == CONST_SLOT_BACKPACK then
        return false
    end
    local item = self:getSlotItem(slot)
    if item then
        local backpack = self:getSlotItem(CONST_SLOT_BACKPACK)
        if backpack then
            return item:moveTo(backpack)
        end
    end
    return false
end

Example:
Lua:
player:moveSlotToBackpack(CONST_SLOT_HEAD)
You can use a function like this:
Lua:
function Player.moveSlotToBackpack(self, slot)
    if slot == CONST_SLOT_BACKPACK then
        return false
    end
    local item = self:getSlotItem(slot)
    if item then
        local backpack = self:getSlotItem(CONST_SLOT_BACKPACK)
        if backpack then
            return item:moveTo(backpack)
        end
    end
    return false
end

Example:
Lua:
player:moveSlotToBackpack(CONST_SLOT_HEAD)
 
Last edited:
Solution
ok, I put the function in place. But when I do the spell call "player:moveSlotToBackpack(CONST_SLOT_HELMET)" nothing happens no erros. worked there right?
 
ok, I put the function in place. But when I do the spell call "player:moveSlotToBackpack(CONST_SLOT_HELMET)" nothing happens no erros. worked there right?
Yes, but your code must be unreachable (that statement is not being executed in your script), because I tested it and it works just fine. How are you using it in your script, and where?
 
just i put in the spell to run.

Code:
function onCastSpell(creature, variant)

    creature:moveSlotToBackpack(CONST_SLOT_HELMET)

    return true
end
 
Last edited:
You're making it more complicated than it has to be, it already checks if the item exists in that slot before moving it, stop using pushThing with the if condition.
 
Did you reload global / restart server? The code should work if you have an item in your backpack & helmet slots.
 
Back
Top