darkmubr
Member
- Joined
- Mar 8, 2019
- Messages
- 47
- Solutions
- 1
- Reaction score
- 13
How do I change in the local code the chance = 1 for a variable of type:
local rare_items = {2152, 2333, 2542}?
Sorry for the doubt, I'm a beginner.
local rare_items = {2152, 2333, 2542}?
Sorry for the doubt, I'm a beginner.
Lua:
local effect = CONST_ME_TUTORIALARROW -- magic effect
local chance = 1 -- magic effect for item that drops less than 5% of the time
function onLogin(player)
player:registerEvent('rarelootkill')
return true
end
function onKill(player, target)
if target:isMonster() then target:registerEvent('rarelootdeath') end
return true
end
function getContainerItemIds(container)
t = {}
if not container then return t end
if not container:getSize() then return t end
for i = container:getSize()-1, 1, -1 do
table.insert(t,container:getItem(i):getId())
end
return t
end
function hasItemById(container,itemid)
if not itemid or not container then return false end
if isInArray(getContainerItemIds(container),itemid) then return true end
return false
end
function onDeath(creature, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
if not creature then return true end
local loot = creature:getType():getLoot()
if not loot then return true end
local totalchance = 0
for i, k in pairs(loot) do
totalchance = totalchance + k.chance
end
addEvent(function()
for i, k in pairs(loot) do
if not corpse or not killer then
return
end
if hasItemById(corpse,k.itemId) and k.chance/totalchance < chance/100 then
corpse:getPosition():sendMagicEffect(effect)
killer:sendTextMessage(MESSAGE_STATUS_DEFAULT, "You looted a "..ItemType(k.itemId):getName().."!")
end
end
end,1)
return true
end