[help] Math.random items and amount

I am so clueless when it comes to this stuff if you can help me out that would be great!
here’s what I made that I thought was the way to go but its not :frowning:

RegisterServerEvent('bankrob:loot')
AddEventHandler('bankrob:loot', function()
    local xPlayer = ESX.GetPlayerFromId(source)
    local a = 'cokep'
    local b = 'hpipe'
    local c = 'lighter'
    local d = 'nitro'

    xPlayer.addInventoryItem(Math.Random(a,d), Math.Random(2,6))
end)

If anyone can point me in the right direction that would be greatly appreciated.
Cheers!

6 Likes

Try this

Items = {
  "cokep",
  "hpipe",
  "lighter",
  "nitro"
}

function RandomItem()
  return Items[math.random(#Items)]
end

function RandomNumber()
	return math.random(2,6)
end

RegisterServerEvent('bankrob:loot')
AddEventHandler('bankrob:loot', function()
  local xPlayer = ESX.GetPlayerFromId(source)
  math.randomseed(GetGameTimer())
  xPlayer.addInventoryItem(RandomItem(), RandomNumber())
end)

1 Like

Thank you so much! :smiley:

@ixHal btw… you need to use math.randomseed before the random.math
source: http://lua-users.org/wiki/MathLibraryTutorial

1 Like

Done it cheers for the help man really appreciate it.

1 Like

And how to do it whit giving weapons to someone?