• 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 remove items from corpse monster

darkmu

Well-Known Member
Joined
Aug 26, 2007
Messages
274
Solutions
1
Reaction score
50
Location
Paraná,Brazil
I'm having problems with the moveTo function, in which not only the primary backpack fills and the secondary backpacks don't fill, so I changed the function to addItem, however what happens and the items still remain in the body of the trash, as I do for remove it from the body?

TFS 1.X

Lua:
 local strLoot = ''
        local lootList = self.players[playerId].lootList
        if lootList then
            for a = corpse:getSize() - 1, 0, -1 do
                local containerItem = corpse:getItem(a)
                if containerItem then
                    local containerItemId = containerItem:getId()
                    for i = 1, #lootList do
                        if lootList[i].item_id == containerItemId then
                            local itemCount = containerItem:getCount()
                            local itemName = containerItem:getName()
                            
                            local moveItem = player:addItem(lootList[i].item_id, itemCount)
                            if moveItem then
                                strLoot = string.format('%s%dx %s, ', strLoot, itemCount, itemName)
                            end
                        end
                    end
                end
            end

            if strLoot ~= '' then
                strLoot = strLoot:sub(1, #strLoot-2)
                if strLoot:len() >= 250 then
                    strLoot:sub(1, 250)
                    strLoot = strLoot .. " ..."
                end
                
                player:sendTextMessage(MESSAGE_STATUS_SMALL, string.format('Loot recolhido: %s', strLoot))
            end
        end
 
After adding the item to the player, just do containerItem:remove().

It worked out !! Will I be able to validate if he doesn't have a slot in the backpacks anymore, he doesn't take the items? What happens is that when the backpacks are full it starts to fall on the floor and I think this can bug you?
 
It worked out !! Will I be able to validate if he doesn't have a slot in the backpacks anymore, he doesn't take the items? What happens is that when the backpacks are full it starts to fall on the floor and I think this can bug you?
If you don't want the items to drop on the ground, you can pass the canDropOnMap argument to player:addItem() like this:
Lua:
-- player:addItem(itemId[, count = 1[, canDropOnMap = true[, subType = 1[, slot = CONST_SLOT_WHEREEVER]]]])
local moveItem = player:addItem(lootList[i].item_id, itemCount, false)
if moveItem then
    containerItem:remove()
    strLoot = string.format('%s%dx %s, ', strLoot, itemCount, itemName)
end
This way player:addItem() should return nil if it couldn't add the item to the player, and then it will be left in the corpse.
 
Back
Top