emerson1495
New Member
- Joined
- Sep 10, 2009
- Messages
- 10
- Reaction score
- 0
more XP(+20%) and more loot (20%) for Rotworms if have storage 20500
TFS 1.3+
TFS 1.3+
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?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()
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()
Ec ,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
Could you show me an example script of how i do this?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
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
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()