Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
|
| 15 Feb 2015 08:43 AM |
I want to get 5 random players (already checked NumPlayers) and leave the rest
but each of the five is unique, how to I make sure that one of the five is not the same as the other, and at the same time distinguish them from the remaining players?
Here's what I have, don't think it's good:
local players = game:GetService("Players") local table = players:GetPlayers() local s1 = table[math.random(1, #table)] local s2 = table[math.random(1, #table)] if s1 ~= s2 then
Is there not a better method? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 15 Feb 2015 08:49 AM |
function getPlayers(amt) local p,r = game.Players:GetPlayers(),{} if amt < #p then for 1,amt do table.insert(r,table.remove(p,math.random(#p))) end return r,p else return p,r end
May be missing ends or parentheses
|
|
|
| Report Abuse |
|
|
|
| 15 Feb 2015 08:50 AM |
| if ur making a game u need to learn tables and for loops first. I remember making a 3k line script game cause I didn't know tables and loops, a while back I went and remade it, the script is around 250 lines now |
|
|
| Report Abuse |
|
|
Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
|
| 15 Feb 2015 08:58 AM |
@verbal
who said I didn't know how to use them? I'm just looking for a quick method lol |
|
|
| Report Abuse |
|
|
Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
|
| 15 Feb 2015 09:02 AM |
@eLunate
How would I get the chosen players? I want to have them as a variable for later usage |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 15 Feb 2015 09:07 AM |
| It returns a tuple of 2 tables containing the chosen players and the ones not chosen respectively. |
|
|
| Report Abuse |
|
|
Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
|
| 15 Feb 2015 09:10 AM |
| okay, that's implying that amt is the number of players I need |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 15 Feb 2015 09:15 AM |
function getPlayers(amt) local p,r = game.Players:GetPlayers(),{} if amt < #p then for _=1,amt do table.insert(r,table.remove(p,math.random(#p))) end return r,p else return p,r end
Lua is silly and may want it to use the garbage var instead |
|
|
| Report Abuse |
|
|
Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
|
| 15 Feb 2015 09:17 AM |
so to save the players as variables, could I do something like
local p1 = r[1] local p2 = r[2] |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 15 Feb 2015 09:38 AM |
Or just
p1,p2,p3,p4,p5 (etc) = unpack(getPlayers(5)) |
|
|
| Report Abuse |
|
|
Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
|
| 15 Feb 2015 03:10 PM |
your thing works, but after it pulls the five players from Players and leaves ONE to be left out for a separate thing, the rest are not assigned to said separate things
like
>5 assignments given
>1 Player correctly left of assignments
>rest of players in server are not left out nor given assignments (so pretty much, left out of being left out) |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
| |
|
|
| 15 Feb 2015 05:12 PM |
I'm not sure if I quite understand you correctly, but here:
t1 = {} t2 = {}
d = math.random(1,2) local n1 local n2
if d == 1 then n1 = math.ceil(#game.Players:GetPlayers()/2) n2 = #game.Players:GetPlayers()-n1 elseif d == 2 then n2 = math.ceil(#game.Players:GetPlayers()/2) n1 = #game.Players:GetPlayers()-n2 end
for i,v in pairs(game.Players:GetPlayers()) do if #t1 < n1 then table.insert(t1,v)
elseif #t2< n2 then table.insert(t2,v) end end |
|
|
| Report Abuse |
|
|
iiTrxth05
|
  |
| Joined: 12 Dec 2012 |
| Total Posts: 589 |
|
| |
|
|
| 15 Feb 2015 05:25 PM |
I see what you're asking for. Here: ---- function get5() local t = {} for i = 1,5 do local p repeat p = game.Players:GetPlayers()[math.random(1,#game.Players:GetPlayers())] wait() until not t[p] table.insert(t,p) end return t end ---- 'get5' returns a table containing 5 different players. |
|
|
| Report Abuse |
|
|
Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
|
| 15 Feb 2015 05:54 PM |
Like I said, it's like it picks the five players, leaves one out for a separate assignment (Even though it should leave the REST out), and the others who should have been left out like the first one aren't given an assignment at all like they should have, just separate from the five players.
>5 assignments given.
>1 player correctly left out of assignments for a different job, even though it should be every single player in the server who wasn't picked.
>Rest of players in server are not left out for the different assignment nor given assignments at all. |
|
|
| Report Abuse |
|
|
Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
| |
|
Tripane
|
  |
| Joined: 03 Jun 2011 |
| Total Posts: 11432 |
|
| |
|