• 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!

RevScripts More exp onKill

Lua:
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()
    
    local PercentLoot = 0

    if player and player:getStorageValue(20500) > 0 and mType:getNameDescription():lower() == "rotworm" then
        PercentLoot = 0.20 -- 20% more loot
    end

    local monsterLoot = mType:getLoot()
    for i = 1, #monsterLoot do
        monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * PercentLoot)
        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_LOOT, text)
        end
    end
end

ec.onKill = function(self, target, killer)
    local player = Player(killer)
    if player and target:isMonster() then
        local mtype = MonsterType(target:getName())
        if mtype then
            local xp = mtype:getExperience()
            
            if target:getName():lower() == "rotworm" and player:getStorageValue(20500) > 0 then
                xp = xp * 1.20 -- Apply 20% bonus to experience
            end
            
            player:addExperience(xp)
        end
    end
end

ec:register()
 
Last edited:
Lua:
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()
  
    local PercentLoot = 0

    if player and player:getStorageValue(20500) > 0 and mType:getNameDescription():lower() == "rotworm" then
        PercentLoot = 0.20 -- 20% more loot
    end

    local monsterLoot = mType:getLoot()
    for i = 1, #monsterLoot do
        monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * PercentLoot)
        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_LOOT, text)
        end
    end
end

ec.onKill = function(self, target, killer)
    local player = Player(killer)
    if player and target:isMonster() then
        local mtype = MonsterType(target:getName())
        if mtype then
            local xp = mtype:getExperience()
          
            if target:getName():lower() == "rotworm" and player:getStorageValue(20500) > 0 then
                xp = xp * 1.20 -- Apply 20% bonus to experience
            end
          
            player:addExperience(xp)
        end
    end
end

ec:register()
Thanks for your help. But now I have another problem, I'm a layman, and it ended up giving the following error, and I don't know how to solve it, could you help me one more time?

The Error:

[2023-23-08 17:57:21.783] [error] Lua script error:
scriptInterface: [Scripts Interface]
scriptId: [C:OTserver 13.11\data-otservbr-global\scripts\rotworm_boost_xp.lua]
timerEvent: []
callbackId:[]
function: []
error [... 13.11\data-otservbr-global\scripts\rotworm_boost_xp.lua:35: attempt to index local 'ec' (a nil value)
stack traceback:
[C]: in function '__newindex'
... 13.11\data-otservbr-global\scripts\rotworm_boost_xp.lua:35: in main chunk]
[2023-23-08 17:57:21.783] [error] rotworm_boost_xp.lua
 
Every time you post here on Otland, you must inform about your server version... I saw that it was Canary. If it was the title, I wouldn't touch it, because I have no knowledge. If the title was 'TFS 1x upwards', which I am aware of, I would do it. Sorry


If it's an error and it doesn't work, it's because I've never touched this Canary/OTServBR-Global.
Lua:
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()
    
    local PercentLoot = 0

    if player and player:getStorageValue(20500) > 0 and mType:getNameDescription():lower() == "rotworm" then
        PercentLoot = 0.20 -- 20% more loot
    end

    local monsterLoot = mType:getLoot()
    for i = 1, #monsterLoot do
        monsterLoot[i].chance = monsterLoot[i].chance + (monsterLoot[i].chance * PercentLoot)
        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_LOOT, text)
        end
    end
end

ec.onKill = function(self, target, killer)
    local player = Player(killer)
    if player and target:isMonster() then
        local mtype = MonsterType(target:getName())
        if mtype then
            local xp = mtype:getExperience()
            
            if target:getName():lower() == "rotworm" and player:getStorageValue(20500) > 0 then
                xp = xp * 1.20 -- Apply 20% bonus to experience
            end
            
            player:addExperience(xp)
        end
    end
end

ec:register()
 
Thanks for your help. But now I have another problem, I'm a layman, and it ended up giving the following error, and I don't know how to solve it, could you help me one more time?

The Error:

[2023-23-08 17:57:21.783] [error] Lua script error:
scriptInterface: [Scripts Interface]
scriptId: [C:OTserver 13.11\data-otservbr-global\scripts\rotworm_boost_xp.lua]
timerEvent: []
callbackId:[]
function: []
error [... 13.11\data-otservbr-global\scripts\rotworm_boost_xp.lua:35: attempt to index local 'ec' (a nil value)
stack traceback:
[C]: in function '__newindex'
... 13.11\data-otservbr-global\scripts\rotworm_boost_xp.lua:35: in main chunk]
[2023-23-08 17:57:21.783] [error] rotworm_boost_xp.lua
Ec ,
Means that otbr doesn’t have eventcallback , so the part to register on eventcallback I think is the loot about monster (ondroop ) this part it’s needed to add it manually to monster.Lua on the loot part. Then the ec.onKill is a CreatureEvent onKill, register it as normal revscript will work, maybe local ec = CreatureEvent(“rootwormLoot”) then rootwormLoot add it on login_events.lua
 
Ec ,
Means that otbr doesn’t have eventcallback , so the part to register on eventcallback I think is the loot about monster (ondroop ) this part it’s needed to add it manually to monster.Lua on the loot part. Then the ec.onKill is a CreatureEvent onKill, register it as normal revscript will work, maybe local ec = CreatureEvent(“rootwormLoot”) then rootwormLoot add it on login_events.lua
Could you show me an example script of how i do this?
 
Not sure if it will work... Just add in CreatureScript

creaturescript onKill

Lua:
local storageRequirement = 20500
local experienceMultiplier = 1.2 -- +20% bonus experience
local lootMultiplier = 1.2 -- +20% loot bonus

if target:isMonster() then
    local mtype = MonsterType(target:getName())
 
    if mtype and mtype:getName() == "Rotworm" then
        local xp = mtype:getExperience()
   
        -- Check if the player's storage is greater than the requirement
        if player:getStorageValue(storageRequirement) then
            xp = xp * experienceMultiplier
        end
   
        player:addExperience(xp)
   
   
        if player:getStorageValue(storageRequirement) then
        
        end
    end
end
Afterwards, you will need to add it to the XML and also register it in login.lua, okay? And then test to see if it works. Check the code to see what needs to be changed. For example, the function was not compatible with your CANARY/OTServBR-Global. Take a look at your source or libs/compaty to see which functions are right to replace and test.
Post automatically merged:

As @emerson1495 mentioned it was a role specific to your server. So I made some changes here. Hope it works


Lua:
local rootwormLoot = CreatureEvent("rootwormLoot")

function rootwormLoot.onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    if killer:isPlayer() then
        local player = Player(killer)
        local mType = creature:getType()
       
        if mType:getName() == "Rotworm" then
            local monsterLoot = mType:getLoot()
            for i = 1, #monsterLoot do
                local item = corpse:createLootItem(monsterLoot[i])
               
               -- Apply 20% bonus to withdrawal chance
                local default = monsterLoot[i].chance
            
                if default < 100000 then
                    monsterLoot[i].chance = default + ((20 * (default / 1000) / 100) * 1000)
                end
               
                if not item then
                    print('[Warning] DropLoot:', 'Could not add loot item to corpse.')
                end
            end

            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_LOOT, text)
            end
        end
    end
    return true
end

-- Set CreatureEvent onKill to add experience bonus
local rootwormKill = CreatureEvent("rootwormKill")

function rootwormKill.onKill(player, target)
    if target:isMonster() then
        local mtype = MonsterType(target:getName())
        if mtype and mtype:getName() == "Rotworm" then
            local xp = mtype:getExperience()

           -- Apply 20% bonus to experience
            xp = xp * 1.2

            player:addExperience(xp)
        end
    end
    return true
end

rootwormLoot:register()
rootwormKill:register()
 
Last edited:
Thanks again for your availability and attention.
I tried using your code, but unfortunately no action happened, no log error or anything.
But anyway, thank you very much.
 
Back
Top