Item Probability
How to make a probability item system
RegisterNetEvent('gusti-lootcrate:openCrate')
AddEventHandler('gusti-lootcrate:openCrate', function()
ESX.TriggerServerCallback('gusti-lootcrate:openCrate', function(success)
if success then
ESX.ShowNotification('You received an item!')
else
ESX.ShowNotification('You cannot carry more items.')
end
end)
end)
ESX.RegisterServerCallback('gusti-lootcrate:openCrate', function(source, cb)
local xPlayer = ESX.GetPlayerFromId(source)
local item
local chance = math.random(100)
if chance <= 50 then
item = 'legendary_item'
elseif chance <= 80 then
item = 'special_item'
else
item = 'epic_item'
end
if xPlayer.canCarryItem(item, 1) then
xPlayer.addInventoryItem(item, 1)
cb(true)
else
cb(false)
end
end)
Last updated