mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-17 05:56:02 +01:00
getRandomReward added for reward item support
This commit is contained in:
36
crafting.lua
36
crafting.lua
@@ -518,4 +518,40 @@ function canCarry(itemTable, src)
|
||||
end
|
||||
end
|
||||
return resultTable
|
||||
end
|
||||
|
||||
function getRandomReward(itemName) -- intended for job scripts
|
||||
if Config.Rewards.RewardPool then
|
||||
local reward = false
|
||||
if type(Config.Rewards.RewardItem) == "string" then Config.Rewards.RewardItem = { Config.Rewards.RewardItem } end
|
||||
for k, v in pairs(Config.Rewards.RewardItem) do
|
||||
if v == itemName then reward = true break end
|
||||
end
|
||||
if reward then
|
||||
removeItem(itemName, 1)
|
||||
local totalRarity = 0
|
||||
for i=1, #Config.Rewards.RewardPool do
|
||||
totalRarity += Config.Rewards.RewardPool[i].rarity
|
||||
end
|
||||
if Config.System.Debug then
|
||||
print("^6Bridge^7: ^3getRandomReward^7: ^2Total Rarity ^7'^6"..totalRarity.."^7'")
|
||||
end
|
||||
|
||||
local randomNum = math.random(1, totalRarity)
|
||||
if Config.System.Debug then
|
||||
print("^6Bridge^7: ^3getRandomReward^7: ^2Random Number ^7'^6"..randomNum.."^7'")
|
||||
end
|
||||
local currentRarity = 0
|
||||
for i=1, #Config.Rewards.RewardPool do
|
||||
currentRarity += Config.Rewards.RewardPool[i].rarity
|
||||
if randomNum <= currentRarity then
|
||||
if Config.System.Debug then
|
||||
print("^6Bridge^7: ^3getRandomReward^7: ^2Selected toy ^7'^6"..Config.Rewards.RewardPool[i].item.."^7'")
|
||||
end
|
||||
addItem(Config.Rewards.RewardPool[i].item, 1)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,7 +8,7 @@ function jobCheck(job)
|
||||
return canDo
|
||||
end
|
||||
|
||||
local time = 100
|
||||
local time = 1000
|
||||
function loadModel(model)
|
||||
if not IsModelValid(model) then print("^6Bridge^7: ^1ERROR^7: ^2Model^7 - '^6"..model.."^7' ^2does not exist in server") return
|
||||
else
|
||||
@@ -588,7 +588,7 @@ function ConsumeSuccess(itemName, type)
|
||||
AlienEffect()
|
||||
end
|
||||
end
|
||||
if Config.RewardItem == itemName then addItem(Config.RewardPool[math.random(1, #Config.RewardPool)], 1) end
|
||||
getRandomReward(itemName) -- check if a reward item should be given
|
||||
end
|
||||
|
||||
function addItem(item, amount, info)
|
||||
|
||||
Reference in New Issue
Block a user