Mr Noxi
Noxus Otserver
Hey
So i got this scrip that req a key to get a random reward but its messing up with the chancec of what item to give the player.
As can be seen below, i made it from top to bottom but the item at bottom has chance = 1000 witch should be 100% but i never get that item, am more likely to get other stuff.
Why is that ?
So i got this scrip that req a key to get a random reward but its messing up with the chancec of what item to give the player.
As can be seen below, i made it from top to bottom but the item at bottom has chance = 1000 witch should be 100% but i never get that item, am more likely to get other stuff.
Why is that ?
Lua:
local config = {
actionId = 45055, -- ID on chest
cooldown = {
key = 13292,
},
rewards = {
{itemId = 2160, minCount = 10, maxCount = 30, chance = 100}, -- CC
{itemId = 26412, minCount = 1, maxCount = 5, chance = 200}, -- token
{itemId = 26413, minCount = 1, maxCount = 3, chance = 300}, -- token 2
{itemId = 20138, minCount = 1, maxCount = 1, chance = 400}, -- Endengered leech
{itemId = 2500, minCount = 1, maxCount = 1, chance = 500}, -- Amazon Armor
{itemId = 8865, minCount = 1, maxCount = 1, chance = 600}, -- Dark lord's cape
{itemId = 8189, minCount = 1, maxCount = 1, chance = 700}, -- Exp scroll
{itemId = 2345, minCount = 1, maxCount = 1, chance = 1000} -- Global Exp scroll
}
}
local rewardChest = Action()
function rewardChest.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local rewardList = {} -- this section is forcing a single item to be chosen from the rewards section
while #rewardList < 1 do
for i = 1, #config.rewards do
rand = math.random(1000)
if rand <= config.rewards[i].chance then
rewardList[#rewardList + 1] = i
end
end
end
if player:getItemCount(13292) > 0 then
rand = math.random(#rewardList)
player:removeItem(13292,1)
player:addItem(config.rewards[rand].itemId, math.random(config.rewards[rand].minCount, config.rewards[rand].maxCount), true)
player:say("Received " .. ItemType(config.rewards[rand].itemId):getName():lower() .. " as reward.", TALKTYPE_MONSTER_SAY)
doSendMagicEffect(player:getPosition(), CONST_ME_HOLYAREA)
else
player:say("You need a magical delux key!", TALKTYPE_MONSTER_SAY)
return true
end
end
rewardChest:aid(config.actionId)
rewardChest:register()