• 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 quick help on this script

kfalls

New Member
Joined
Jan 11, 2018
Messages
16
Reaction score
1
add this message (boosted loot) in this script, when the monster is killed.
ex: Loot of a bear: meat (boosted loot).




local BOOSTED_MONSTER = 56404
local boostedMonstersList = {"rat"}
local experienceBonus = 8.0

function onDeath(cid, corpse, deathList)

local master = getCreatureMaster(cid)
if (master and master ~= cid) then
return true
end

local boostedMonster = boostedMonstersList[getGlobalStorageValue(BOOSTED_MONSTER)]
if getCreatureName(cid):lower() == boostedMonster then

for i = 1, #deathList do

-- exp bonus
local bonusExperience = getMonsterInfo(getCreatureName(cid)).experience/i * getPlayerRates(deathList)[SKILL__LEVEL] * experienceBonus
doPlayerAddExperience(deathList, bonusExperience)
doSendAnimatedText(getPlayerPosition(deathList), bonusExperience, 215)


-- loot bonus
local lootList = getMonsterLootList(getCreatureName(cid))
for i, _ in pairs(lootList) do
if lootList.count > 1 then
local numb = math.random(1, lootList.count)
doAddContainerItem(corpse.uid, lootList.id, numb)
elseif math.random(1,100000) <= lootList.chance then
doAddContainerItem(corpse.uid, lootList.id, 1)
end
end

end

end
return true
end
 
Not really possible from here.
You'd have to edit the function that normally does the loot, as that's where it sends the message.

Not at a pc, but I think it's in data/lib/core/container.lua
 
Not really possible from here.
You'd have to edit the function that normally does the loot, as that's where it sends the message.

Not at a pc, but I think it's in data/lib/core/container.lua
I used A.I to do it and it did it, but it is displaying two messages and I didn't want it to display two messages but only the one that corresponds to the script and with the message (boosted loot)
imagem_2024-12-24_133341384.webp
It was supposed to display only the second loot and put the (boosted loot) in the second one and not display the first one.


local BOOSTED_MONSTER = 56404
local boostedMonstersList = {"rat"}
local experienceBonus = 8.0

function onDeath(cid, corpse, deathList)
local master = getCreatureMaster(cid)
if (master and master ~= cid) then
return true
end

local boostedMonster = boostedMonstersList[getGlobalStorageValue(BOOSTED_MONSTER)]
if getCreatureName(cid):lower() == boostedMonster then
-- Inicializa a mensagem de loot
local lootMessage = "Loot of " .. getCreatureName(cid):lower() .. ": "
local lootAdded = false

for i = 1, #deathList do
-- Experiência bônus
local bonusExperience = getMonsterInfo(getCreatureName(cid)).experience / i * getPlayerRates(deathList)[SKILL__LEVEL] * experienceBonus
doPlayerAddExperience(deathList, bonusExperience)
doSendAnimatedText(getPlayerPosition(deathList), bonusExperience, 215)

-- Iteração sobre o loot
local lootList = getMonsterLootList(getCreatureName(cid))
for _, loot in pairs(lootList) do
if loot.count > 1 then
local numb = math.random(1, loot.count)
doAddContainerItem(corpse.uid, loot.id, numb)
if not lootAdded then
lootMessage = lootMessage .. numb .. " " .. getItemNameById(loot.id) .. ", "
lootAdded = true
end
elseif math.random(1, 100000) <= loot.chance then
doAddContainerItem(corpse.uid, loot.id, 1)
if not lootAdded then
lootMessage = lootMessage .. getItemNameById(loot.id) .. ", "
lootAdded = true
end
end
end
end

-- Adiciona "(boosted loot)" ao final da mensagem
lootMessage = lootMessage .. "(boosted loot)"

-- Envia a mensagem de loot para todos os jogadores
for i = 1, #deathList do
doPlayerSendTextMessage(deathList, MESSAGE_INFO_DESCR, lootMessage)
end
end

return true
end

 
Like I said earlier, this is not the correct spot to do this, which is why you're getting 2 loot messages.
You should move the logic of the code into data/scripts/events/monster/default_onDropLoot.lua
Specifically here, is where it displays the loot.
LUA:
if party then
    party:broadcastPartyLoot(text)
else
    player:sendTextMessage(MESSAGE_LOOT, text)
end
-------------
and please use proper code tags. otherwise the text of your script is useless to read, due to formatting.

46010-58ddc85cdd7b4a2afb96f042cc6ed4c2.data

`
Post automatically merged:

This will likely get merged with above, but this is how I'd do it.

LUA:
local boostedMonstersList = {
    ["rat"] = {
        {id = 2160, count = 5, chance = 100000}, -- 100% chance
        {id = 2152, count = 50, chance = 50000}  -- 50% chance
    },
    ["cave rat"] = {
        {id = 2160, count = 5, chance = 100000}, -- 100% chance
        {id = 2152, count = 50, chance = 50000}  -- 50% chance
    }
}

local event = Event()

event.onDropLoot = function(self, corpse)
    if configManager.getNumber(configKeys.RATE_LOOT) == 0 then
        return
    end
    
    local player = Player(corpse:getCorpseOwner())
    local mType = self:getType()
    local doCreateLoot = false
    
    if not player or player:getStamina() > 840 then
        doCreateLoot = true
    end
    
    local boosted = false
    
    if doCreateLoot 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
        
        local boostedMonster = boostedMonstersList[self:getName():lower()]
        if boostedMonster then
            local lootCount = #corpse:getItems()            
            for _, lootItem in pairs(boostedMonster) do
                local item = corpse:createLootItem(lootItem)
                if not item then
                    print("[Warning] DropLoot: Could not add boosted loot item to corpse.")
                end
            end
            if lootCount < #corpse:getItems() then
                boosted = true
            end
        end
    end
    
    if player then
        local text
        if doCreateLoot then
            text = ("Loot of %s: %s.%s"):format(mType:getNameDescription(), corpse:getContentDescription(), (boosted and " (boosted)" or ""))
        else
            text = ("Loot of %s: nothing (due to low stamina)."):format(mType:getNameDescription())
        end
        local party = player:getParty()
        if party then
            party:broadcastPartyLoot(text)
        else
            player:sendTextMessage(MESSAGE_LOOT, text)
        end
    end
end

event:register()
 
Last edited by a moderator:
ffs. lmao
This is why you need to post your server in the main post.

I think in config.lua is a monsterLootMessage, set that to 0 to disable the normal loot message.

Then you'll need to find the corpse, and loop through it's contents to manually figure out what's inside the body, and create the loot message yourself.
 
Then remove in source that message, create one function to loot display
corpse:content() + boosted content as single message,

hint: this must be an addEvent with 5ms delay, somehow corpse items/description return nill without that small delay.

so:
  • Remove that message from c++ probably monster.cpp onDeath function
  • Move description corpse function from c++ to lua
  • Write in onDeath event in lua part boosted + monster corpse text message

btw @Xikini gave you solution that is perfect example why tfs lower than 1.2 its absolute bullshit and noone should use it as base for server.

Tfs 0.x be like:
  • bad performance
  • a lot of bugs
  • absolute 0 newbie friendly
 
ffs. kkkk
É por isso que você precisa postar seu servidor no post principal.

Acho que config.luaexiste um monsterLootMessage, defina isso para 0desabilitar a mensagem de saque normal.

Depois, você precisará encontrar o cadáver e percorrer seu conteúdo para descobrir manualmente o que há dentro dele e criar você mesmo a mensagem de saque.
The Forgotten Server - Editado por Cyko V8, versão 0.3.6 - Editado por Cyko V8 (Crying Damson - Editado por Cyko V8) Compiled with GNU C++ version 3.4.5
 
Back
Top