beenii
Well-Known Member
- Joined
- Jul 26, 2010
- Messages
- 580
- Solutions
- 1
- Reaction score
- 57
Hello I was wondering if anyone has this code available
my onDropLoot:
my function Container.createLootItem(self, item):
try this one, but it gave me null item errors:
and with the fix in same thread, also downgrades the function to tfs 1.3.
loop print in console:
[Warning] DropLoot: Could not add loot item to corpse.
my onDropLoot:
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 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()
my function Container.createLootItem(self, item):
Lua:
function Container.createLootItem(self, item)
if self:getEmptySlots() == 0 then
return true
end
local itemCount = 0
local randvalue = getLootRandom()
local itemType = ItemType(item.itemId)
if randvalue < item.chance then
if itemType:isStackable() then
itemCount = randvalue % item.maxCount + 1
else
itemCount = 1
end
end
while itemCount > 0 do
local count = math.min(100, itemCount)
local subType = count
if itemType:isFluidContainer() then
subType = math.max(0, item.subType)
end
local tmpItem = Game.createItem(item.itemId, subType)
if not tmpItem then
return false
end
if tmpItem:isContainer() then
for i = 1, #item.childLoot do
if not tmpItem:createLootItem(item.childLoot[i]) then
tmpItem:remove()
return false
end
end
if #item.childLoot > 0 and tmpItem:getSize() == 0 then
tmpItem:remove()
return true
end
end
if item.subType ~= -1 then
tmpItem:setAttribute(ITEM_ATTRIBUTE_CHARGES, item.subType)
end
if item.actionId ~= -1 then
tmpItem:setActionId(item.actionId)
end
if item.text and item.text ~= "" then
tmpItem:setText(item.text)
end
local ret = self:addItemEx(tmpItem)
if ret ~= RETURNVALUE_NOERROR then
tmpItem:remove()
end
itemCount = itemCount - count
end
return true
end
try this one, but it gave me null item errors:
Lua - Gold coin rate and gold coin to bank
Hey everyone, I was wondering on how to add a gold coin rate to my server (TFS 1.3), for example monsters would drop 2x gold coins etc, I found a way to do it but since it is done AFTER the loot is created, the loot message is ugly (not accurate), so I would like to know how to do it BEFORE the...
otland.net
and with the fix in same thread, also downgrades the function to tfs 1.3.
loop print in console:
[Warning] DropLoot: Could not add loot item to corpse.