Svira
Active Member
- Joined
- Jan 27, 2008
- Messages
- 263
- Solutions
- 11
- Reaction score
- 35
Hello, for some time I have been trying to specify loot for the selected monster "loot chance"
The assumption is that all items from BOSS will have slots not less than 28%
other monsters according to standard calculation.
However, the script does not work as expected without any errors.
The assumption is that all items from BOSS will have slots not less than 28%
other monsters according to standard calculation.
However, the script does not work as expected without any errors.
Lua:
function getper()
local n = 1
for i=1,10 do
n = n+math.random(0,10)
if n < 8*i then
break
end
end
return n
end
function getperchance()
local n = 1
for i=1,10 do
n = n+math.random(1,10)
if n < 28*i then
break
end
end
return n
end
local lootable_slots = {'hp','mp','ml','melee','shield','dist'}
function assign_loot_Slot(pos)
local c = Tile(pos):getTopDownItem()
if c ~= nil then
if c:isContainer() then
local h = c:getItemHoldingCount()
if h > 0 then
for i = 1, h do
local i_Ex = c:getItem(i - 1)
if i_Ex == nil then
break
end
local itemEx = {
itemid = i_Ex:getId(),
uid = i_Ex:getUniqueId()
}
if (isArmor(itemEx.uid) or isWeapon(itemEx.uid) or isShield(itemEx.uid)) and not isItemStackable(itemEx.uid) then
if math.random(1,5) == 5 then
if math.random(1, 100) <= 75 then
nam = Item(itemEx.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getper()..'%]'
doSetItemSpecialDescription(itemEx.uid, nam)
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYAREA)
if math.random(1, 100) <= 50 then
nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getper()..'%]'
doSetItemSpecialDescription(itemEx.uid, nam)
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_ICETORNADO)
end
if math.random(1, 100) <= 1 then
nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getper()..'%]'
doSetItemSpecialDescription(itemEx.uid, nam)
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_PURPLEENERGY)
end
end
end
end
end
end
end
return true
end
end
function assign_loot_chance(pos)
local c = Tile(pos):getTopDownItem()
if c ~= nil then
if c:isContainer() then
local h = c:getItemHoldingCount()
if h > 0 then
for i = 1, h do
local i_Ex = c:getItem(i - 1)
if i_Ex == nil then
break
end
local itemEx = {
itemid = i_Ex:getId(),
uid = i_Ex:getUniqueId()
}
if (isArmor(itemEx.uid) or isWeapon(itemEx.uid) or isShield(itemEx.uid)) and not isItemStackable(itemEx.uid) then
if math.random(1, 100) <= 1 then
nam = Item(itemEx.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getperchance()..'%]'
doSetItemSpecialDescription(itemEx.uid, nam)
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_HOLYAREA)
if math.random(1, 100) <= 1 then
nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getperchance()..'%]'
doSetItemSpecialDescription(itemEx.uid, nam)
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_ICETORNADO)
end
if math.random(1, 100) <= 1 then
nam = nam..' ['..lootable_slots[math.random(1, #lootable_slots)]..'.+'..getperchance()..'%]'
doSetItemSpecialDescription(itemEx.uid, nam)
doSendMagicEffect(getThingPos(itemEx.uid), CONST_ME_PURPLEENERGY)
end
end
end
end
end
end
return true
end
end
function onKill(cid, target, lastHit)
if (not isSummon(target)) then
addEvent(assign_loot_Slot, 2, getThingPos(target))
end
local creaturenames = {"Loot Chance"}
local name = string.lower(getCreatureName(cid))
if(isInArray(creaturenames, name)) then
addEvent(assign_loot_chance, 2, getThingPos(target))
end
return true
end