• 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+ How to show animated text when removing an object from a corpse

Mateus Robeerto

Excellent OT User
Joined
Jun 5, 2016
Messages
1,420
Solutions
75
Reaction score
806
Location
ლ(ಠ益ಠლ)
does anyone know this script? if yes, please convert to tfs 1.2
the script is simple, I like it
Lua:
function onRemoveItem(moveitem, tileitem, pos)
    if moveitem.itemid >= 1 and moveitem.itemid <= 30000 then
        doSendAnimatedText(pos,getItemName(moveitem.itemid), TEXTCOLOR_ORANGE)
    end
end



I put this area by accident, please can some adm or mods move it to another support area thanks
 
Last edited:
Solution
can i put it anywhere data/events/scripts/player.lua?
was that I put it at the end before end
and it didn't work in the game, nothing error on the console
That goes inside the onMoveItem event.
Here's an example:

Lua:
function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    -- onMoveItem Event
    if fromCylinder and fromCylinder:isItem() then
        if fromCylinder:getId() == 3065 then
            if toCylinder ~= fromCylinder then
                player:say(string.format("x%d %s", count, item:getName()), TALKTYPE_MONSTER_SAY, false, nil, fromCylinder:getPosition())
            end
        end
    end
    return true
end

You also need to activate the event in events.xml...
I did the RevScript here and tested it, it's working OK. Try it out in data/scripts.

Lua:
local allowedIds = {
    [30201] = true,
    [30200] = true,
    [30199] = true,
}

local ec = EventCallback

ec.onMoveItem = function(player, item, count, fromPosition, toPosition, fromCylinder, toCylinder)
    if fromCylinder and fromCylinder:isItem() then
        local itemId = item:getId()
        if allowedIds[itemId] then
            if toCylinder ~= fromCylinder then
                local text = string.format("x%d %s", count, item:getName())
                local position = fromCylinder:getPosition()
                local color = 198 -- orange color code
              
                Game.sendAnimatedText(text, position, color)
            end
        end
    end

    return true
end

ec:register(-61)
hmm its not really working, (no errors in console)


if i may ask, what's the (-61)?

im assuming i was suposed to remove the function from the player.lua and implementing your script into data/scripts
 
hmm its not really working, (no errors in console)


if i may ask, what's the (-61)?

im assuming i was suposed to remove the function from the player.lua and implementing your script into data/scripts
You can just do the same type of thing inside the ec.onDropLoot(monster, corpse) callback on line 96 of the autoloot script.
Something like (untested):
Lua:
function ec.onDropLoot(monster, corpse)
    if not corpse:getType():isContainer() then
        return
    end

    local corpseOwner = Player(corpse:getCorpseOwner())
    local corpsePosition = corpse:getPosition()
    local items = corpse:getItems()
    local warningCapacity = false
    local lootedIds = {}
    for _, item in pairs(items) do
        local itemId = item:getId()
        if hasPlayerAutolootItem(corpseOwner, itemId) then
            if currencyItems[itemId] then
                local worth = item:getWorth()
                corpseOwner:setBankBalance(corpseOwner:getBankBalance() + worth)
                corpseOwner:sendTextMessage(MESSAGE_STATUS_SMALL, string.format("Your balance increases by %d gold coins.", worth))
                item:remove()
                Game.sendAnimatedText(string.format("x%d %s", item:getCount(), item:getName()), corpsePosition, 198)
            elseif item:moveTo(corpseOwner, 0) then
                Game.sendAnimatedText(string.format("x%d %s", item:getCount(), item:getName()), corpsePosition, 198)
            else
                warningCapacity = true
            end
        end
    end

    if warningCapacity then
        corpseOwner:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You no have capacity.")
    end
end

This will put a message for every item that has been autolooted.
Although, it might be a better idea to store all the id's, and just write one message after the loop has finished...
 
Last edited:
You can just do the same type of thing inside the ec.onDropLoot(monster, corpse) callback on line 96 of the autoloot script.
Something like (untested):
Lua:
function ec.onDropLoot(monster, corpse)
    if not corpse:getType():isContainer() then
        return
    end

    local corpseOwner = Player(corpse:getCorpseOwner())
    local corpsePosition = corpse:getPosition()
    local items = corpse:getItems()
    local warningCapacity = false
    local lootedIds = {}
    for _, item in pairs(items) do
        local itemId = item:getId()
        if hasPlayerAutolootItem(corpseOwner, itemId) then
            if currencyItems[itemId] then
                local worth = item:getWorth()
                corpseOwner:setBankBalance(corpseOwner:getBankBalance() + worth)
                corpseOwner:sendTextMessage(MESSAGE_STATUS_SMALL, string.format("Your balance increases by %d gold coins.", worth))
                item:remove()
                Game.sendAnimatedText(string.format("x%d %s", item:getCount(), item:getName()), corpsePosition, 198) --not sure if this is really needed...
            elseif item:moveTo(corpseOwner, 0) then
                Game.sendAnimatedText(string.format("x%d %s", item:getCount(), item:getName()), corpsePosition, 198)
            else
                warningCapacity = true
            end
        end
    end

    if warningCapacity then
        corpseOwner:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You no have capacity.")
    end
end

This will put a message for every item that has been autolooted.
Although, it might be a better idea to store all the id's, and just write one message after the loop has finished...
My god you are an ANGEL!

tested and works very well, i was playing around with the autoloot to see if i could make it work, this saved me so much time!

really appreciate it thanks!

@Mateus Robeerto and thank you also for taking your time to try to help me!<3
 
Back
Top