beenii
Well-Known Member
- Joined
- Jul 26, 2010
- Messages
- 580
- Solutions
- 1
- Reaction score
- 57
Hello, I have an enchantment system, which gives extra gold on monsters.
the problem is add the gold inside the body, with the onDeath function.
I want to do it from the onDropLoot function.
since I have a system to auto deposit the gold, in the function onDropLoot, so it cleans up the gold, before the onDeath function can read how much gold was in the corpse, and doesn't add any extra gold.
enchantment system function:
system by: oen432
the problem is add the gold inside the body, with the onDeath function.
I want to do it from the onDropLoot function.
since I have a system to auto deposit the gold, in the function onDropLoot, so it cleans up the gold, before the onDeath function can read how much gold was in the corpse, and doesn't add any extra gold.
enchantment system function:
system by: oen432
[TFS 1.3 / 1.4] Upgrade System
Lua:
function us_CheckCorpse(monsterType, corpsePosition, killerId)[/SIZE][/HEADING]
local killer = Player(killerId)
local corpse = Tile(corpsePosition):getTopDownItem()
if killer and killer:isPlayer() and corpse and corpse:isContainer() then
for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
local item = killer:getSlotItem(slot)
if item then
local values = item:getBonusAttributes()
if values then
for key, value in pairs(values) do
local attr = US_ENCHANTMENTS[value[1]]
if attr then
if attr.name == "Additonal Gold" then
local cc, plat, gold = 0, 0, 0
for i = 0, corpse:getSize() do
local item = corpse:getItem(i)
if item then
if item.itemid == 2160 then
gold = gold + (item:getCount() * 10000)
elseif item.itemid == 2152 then
gold = gold + (item:getCount() * 100)
elseif item.itemid == 2148 then
gold = gold + item:getCount()
end
end
end
gold = math.floor(gold * value[2] / 100)
while gold >= 10000 do
gold = gold / 10000
cc = cc + 1
end
if cc > 0 then
local crystalCoin = Game.createItem(2160, cc)
corpse:addItemEx(crystalCoin)
end
while gold >= 100 do
gold = gold / 100
plat = plat + 1
end
if plat > 0 then
local platinumCoin = Game.createItem(2152, plat)
corpse:addItemEx(platinumCoin)
end
if gold > 0 then
local goldCoin = Game.createItem(2148, gold)
corpse:addItemEx(goldCoin)
end
end
end
end
end
end
end
my onDroopLoot function:
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()
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 gold = corpse:removeCoins()
local text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
if (gold > 0) then
player:setBankBalance(player:getBankBalance() + gold)
text = ("%s, x%d gold coins were sent to your bank balance."):format(text, gold)
end
local party = player:getParty()
if party then
--party:broadcastPartyLoot(text)
party:broadcastPartyLoot(text:gsub("your (bank)", player:getName():lower().."'s %1"))
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()
Lua:
function us_CheckCorpse(monsterType, corpsePosition, killerId)[/SIZE][/HEADING]
local killer = Player(killerId)
local corpse = Tile(corpsePosition):getTopDownItem()
if killer and killer:isPlayer() and corpse and corpse:isContainer() then
for slot = CONST_SLOT_HEAD, CONST_SLOT_AMMO do
local item = killer:getSlotItem(slot)
if item then
local values = item:getBonusAttributes()
if values then
for key, value in pairs(values) do
local attr = US_ENCHANTMENTS[value[1]]
if attr then
if attr.name == "Additonal Gold" then
local cc, plat, gold = 0, 0, 0
for i = 0, corpse:getSize() do
local item = corpse:getItem(i)
if item then
if item.itemid == 2160 then
gold = gold + (item:getCount() * 10000)
elseif item.itemid == 2152 then
gold = gold + (item:getCount() * 100)
elseif item.itemid == 2148 then
gold = gold + item:getCount()
end
end
end
gold = math.floor(gold * value[2] / 100)
while gold >= 10000 do
gold = gold / 10000
cc = cc + 1
end
if cc > 0 then
local crystalCoin = Game.createItem(2160, cc)
corpse:addItemEx(crystalCoin)
end
while gold >= 100 do
gold = gold / 100
plat = plat + 1
end
if plat > 0 then
local platinumCoin = Game.createItem(2152, plat)
corpse:addItemEx(platinumCoin)
end
if gold > 0 then
local goldCoin = Game.createItem(2148, gold)
corpse:addItemEx(goldCoin)
end
end
end
end
end
end
end
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()
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 gold = corpse:removeCoins()
local text = ("Loot of %s: %s"):format(mType:getNameDescription(), corpse:getContentDescription())
if (gold > 0) then
player:setBankBalance(player:getBankBalance() + gold)
text = ("%s, x%d gold coins were sent to your bank balance."):format(text, gold)
end
local party = player:getParty()
if party then
--party:broadcastPartyLoot(text)
party:broadcastPartyLoot(text:gsub("your (bank)", player:getName():lower().."'s %1"))
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()