• 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.5] - Problem with drop loot

SaadPro

Member
Joined
Dec 25, 2022
Messages
37
Reaction score
18
Location
Egypt
The engine don't give any errors
data/events/scripts/monster.lua
Lua:
function Monster:onDropLoot(corpse)
    if hasEventCallback(EVENT_CALLBACK_ONDROPLOOT) then
        EventCallback(EVENT_CALLBACK_ONDROPLOOT, self, corpse)
    end
end

function Monster:onSpawn(position, startup, artificial)
    if hasEventCallback(EVENT_CALLBACK_ONSPAWN) then
        return EventCallback(EVENT_CALLBACK_ONSPAWN, self, position, startup, artificial)
    else
        return true
    end
end


    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local player = Player(corpse:getCorpseOwner())

    if not player or player:getStamina() <= 840 then
        local monsterLoot = mType:getLoot()

        local percentLoot = 0
        if player:getStorageValue(STORAGEVALUE_LOOT_TEMPO) > os.time() then
            local potion = lootPotion[player:getStorageValue(STORAGEVALUE_LOOT_ID)]
            if potion then
                percentLoot = potion.exp / 100
            end
        end

        local percent = 0
        if mType:getName():lower() == boostCreature[1].name:lower() then
            percent = boostCreature[1].loot / 100
        end

        for i = 1, #monsterLoot do
            monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * percent) + (monsterLoot[i].chance * percentLoot)
            local item = corpse:createLootItem(monsterLoot[i])
            if not item then
                print(string.format('[Warning] DropLoot: Could not add loot item to corpse. [Monster: %s]', mType:getName()))
            end
        end

        if player then
            local text = ("Loot de %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
            local party = player:getParty()
            if party then
                party:broadcastPartyLoot(text)
            else
                if player:getStorageValue(STORAGEVALUE_LOOT) == 1 then
                    sendChannelMessage(11, TALKTYPE_CHANNEL_O, text)
                else
                    player:sendTextMessage(MESSAGE_INFO_DESCR, text)
                end
            end
        end
    else
        local text = ("Loot de %s: nothing (due to low resistance)"):format(mType:getNameDescription())
        local party = player:getParty()
        if party then
            party:broadcastPartyLoot(text)
        else
            if player:getStorageValue(STORAGEVALUE_LOOT) == 1 then
                sendChannelMessage(11, TALKTYPE_CHANNEL_O, text)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, text)
            end
        end
    end
end

function Monster:onSpawn(position, startup, artificial)
    return true
end


Monsters dont drop any loot
data/scripts/eventcallbacks/monster/default_onDropLoot
Code:
local ec = EventCallback

ec.onDropLoot = function(self, corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    if not player or player:getStamina() > 840 then
        local monsterLoot = mType:getLoot()
        for i = 1, #monsterLoot do
            local item = corpse:createLootItem(monsterLoot[i])
            if not item then
                print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
            end
        end

        if player then
            local text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
            local party = player:getParty()
            if party then
                party:broadcastPartyLoot(text)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, text)
            end
        end
    else
        local text = ("Loot of %s: nothing (due to low stamina)"):format(mType:getNameDescription())
        local party = player:getParty()
        if party then
            party:broadcastPartyLoot(text)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, text)
        end
    end
end

ec:register()
HELP ME
 

This function already exists, yes, but only for TFS 1.5 Nekiro. He's using some old datapacks from TFS 1.3. He needs to switch to the original TFS 1.5 Nekiro datapacks, and then it will work normally.

In his data/events/scripts/monster.lua he has 2 onSpawn functions, line 7 and line 74
Lua:
function Monster:onSpawn(position, startup, artificial)
    if hasEventCallback(EVENT_CALLBACK_ONSPAWN) then
        return EventCallback(EVENT_CALLBACK_ONSPAWN, self, position, startup, artificial)
    else
        return true
    end
end

function Monster:onSpawn(position, startup, artificial)
    return true
end

Lines 16 to 72 has no function definition (what is this function called, what are the parameters):
Lua:
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end

    local player = Player(corpse:getCorpseOwner())

    if not player or player:getStamina() <= 840 then
        local monsterLoot = mType:getLoot()

        local percentLoot = 0
        if player:getStorageValue(STORAGEVALUE_LOOT_TEMPO) > os.time() then
            local potion = lootPotion[player:getStorageValue(STORAGEVALUE_LOOT_ID)]
            if potion then
                percentLoot = potion.exp / 100
            end
        end

        local percent = 0
        if mType:getName():lower() == boostCreature[1].name:lower() then
            percent = boostCreature[1].loot / 100
        end

        for i = 1, #monsterLoot do
            monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * percent) + (monsterLoot[i].chance * percentLoot)
            local item = corpse:createLootItem(monsterLoot[i])
            if not item then
                print(string.format('[Warning] DropLoot: Could not add loot item to corpse. [Monster: %s]', mType:getName()))
            end
        end

        if player then
            local text = ("Loot de %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
            local party = player:getParty()
            if party then
                party:broadcastPartyLoot(text)
            else
                if player:getStorageValue(STORAGEVALUE_LOOT) == 1 then
                    sendChannelMessage(11, TALKTYPE_CHANNEL_O, text)
                else
                    player:sendTextMessage(MESSAGE_INFO_DESCR, text)
                end
            end
        end
    else
        local text = ("Loot de %s: nothing (due to low resistance)"):format(mType:getNameDescription())
        local party = player:getParty()
        if party then
            party:broadcastPartyLoot(text)
        else
            if player:getStorageValue(STORAGEVALUE_LOOT) == 1 then
                sendChannelMessage(11, TALKTYPE_CHANNEL_O, text)
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, text)
            end
        end
    end
end

I understand he just copying and pasting from some place
 
You are trying to implement code in wrong function,
"onSpawn" its not a callback for monster death

in general you have no idea what you are doing

u should mention that you edit files and this is not a original TFS problem, you can't add code like that
 
Back
Top