• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua [globalevent] Saving 5 randoms players

ligus

New Member
Joined
Apr 26, 2010
Messages
253
Reaction score
0
Hey, does anyone know how to get 5 random players?

I want to make script which saves 5 random players but do not know how to get them :p
Code:
function onThink(interval)
     for _, pid in ipairs(getPlayersOnline()) do
     -- get 5 random players
     doPlayerSave(randoms)
     end
end

Does anyone have an idea?
 
Well, I have something like that:

Code:
    local list = getPlayersOnline()
 
    local player1 = list[math.random(#list)]
    local player2 = list[math.random(#list)]
    local player3 = list[math.random(#list)]
    local player4 = list[math.random(#list)]
    local player5 = list[math.random(#list)]

But it can draw one player 5 times during one "lottery", does anyone have an idea how it can be done without any repeat?
 
maybe
Code:
function onThink(interval)
local players = getPlayersOnline()
     for i = 1,5 do
     doPlayerSave(players[math.random(1,table.maxn(players))])
  end
end
 
Code:
local amount = 5

function onThink(interval)
  local players = getPlayersOnline()
  for i = 1, amount do
    local id = math.random(#players)
    doPlayerSave(players[id])
    table.remove(players, id)
  end
end
 
Back
Top