• 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.X+ corpse:getItemCountById() dosen't works

Gorillaz

New Member
Joined
Nov 6, 2016
Messages
8
Reaction score
1
Location
Brazil
TFS 1.3
Hello, guys.

Well, I'm trying to make a simple script when a monster dies, I do something with a item from loot.

For example, rat drops gold coins, right?
If I check if he (rat) has gold coin by the function corpse:getItemCountById(2148), it returns 0 (even he dropped). I tried other things like corpse:addItem(2160, 1) and it works.
Oh, I'm using function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)

Someone can help me?
 
Solution
Ok, so, apparentely death event is launched before items are added to a corpse.
You would have to rewrite it to addEvent and give it some minor delay.
corpse is a container right? did you tried to do Item(corpse):getItemCountById(2148)? As long as I remember the method getItemCountById is only valid for item and not for containers. (I'm at work so I can't really check in luascript.cpp to confirm this info)
 
corpse is a container right? did you tried to do Item(corpse):getItemCountById(2148)? As long as I remember the method getItemCountById is only valid for item and not for containers. (I'm at work so I can't really check in luascript.cpp to confirm this info)
I got an error using Item(corpse):getItemCountById(2148), I checked in https://github.com/otland/forgottenserver/blob/master/src/luascript.cpp, and yeah, this method exists from containers too, :/

Other methods like corpse:getSize() returns 0, but when I use corpse:getCapacity() returns 5 (using rat as example).
 
Do you wanna show us the script?
Code:
for i = corpse:getCapacity() - 1, 0, -1 do
    local item = corpse:getItem(i)
    if (item and config.ids_dinheiro[item:getId()]) then
        local mult, qntd = config.ids_dinheiro[item:getId()], item:getCount() * mult
        killer:addMoney(qntd)
        item:remove()
        killer:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, string.format(config.msg_add, qntd))
    end
end

Sure, look, I'm trying to get an item using corpse:getItem(i), but variable item always is nil, even monster dropping items.
 
Last edited:
Ok, so, apparentely death event is launched before items are added to a corpse.
You would have to rewrite it to addEvent and give it some minor delay.
 
Solution
Back
Top