|
| 28 May 2014 04:28 PM |
| Nothing too complicated, just a example that I can edit. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 May 2014 04:29 PM |
local allPlayers = Game.Players:GetPlayers(); local player1, player2;
if #allPlayers >= 2 then player1 = table.remove(allPlayers, math.random(#allPlayers)); player2 = allPlayers[math.random(#allPlayers)]; end |
|
|
| Report Abuse |
|
|
|
| 28 May 2014 04:34 PM |
P = Game.Players:GetPlayers() local r1 = P[math.random(1,#P)] table.remove(P,r1) if #P > 0 then local r2 = P[math.random(1,#P)] else end
Not tested |
|
|
| Report Abuse |
|
|
|
| 28 May 2014 04:35 PM |
| ninja'd(or whatever you call it) |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 May 2014 04:36 PM |
| You still have a chance for a interval is empty error and putting the r2 local variable in the if scope is kinda useless if they don't plan on putting their code in the if scope--since they won't be able to access r2. |
|
|
| Report Abuse |
|
|
Argelius
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 4047 |
|
|
| 28 May 2014 04:36 PM |
This should be in the "Scripting Requests" forum
Oh wait we don't have one
so this shouldn't exist |
|
|
| Report Abuse |
|
|
|
| 28 May 2014 04:43 PM |
| @cnt, just a quick question, was does the symbol ; do? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 May 2014 04:43 PM |
| In Lua? Not much, it's not required but it's just a habit. |
|
|
| Report Abuse |
|
|
Argelius
|
  |
| Joined: 19 Jul 2010 |
| Total Posts: 4047 |
|
|
| 28 May 2014 04:44 PM |
| It is a required symbol in other programming languages but not Lua, I believe. |
|
|
| Report Abuse |
|
|
|
| 28 May 2014 05:07 PM |
So I would edit the random chosen players using the variables Player1 and 2? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 May 2014 05:09 PM |
Assuming 2 or more people are in the game and you run that, then yes, player1 and player2 will be the actual player object.
player1.Character.Humanoid.WalkSpeed = 100 or whatever |
|
|
| Report Abuse |
|
|
|
| 28 May 2014 05:18 PM |
So this would print The "first pair is randomname1, randomname2"
local allPlayers = Game.Players:GetPlayers(); local player1, player2; local chosen = {player1, player2} if #allPlayers >= 2 then player1 = table.remove(allPlayers, math.random(#allPlayers)); player2 = allPlayers[math.random(#allPlayers)]; print( "The fisrt pair is", unpack(squares)) end
|
|
|
| Report Abuse |
|
|
|
| 28 May 2014 05:19 PM |
So this would print The "first pair is randomname1, randomname2"
local allPlayers = Game.Players:GetPlayers(); local player1, player2; local chosen = {player1, player2} if #allPlayers >= 2 then player1 = table.remove(allPlayers, math.random(#allPlayers)); player2 = allPlayers[math.random(#allPlayers)]; print( "The fisrt pair is", unpack(chosen)) end
Sorry, learning this also off the Wiki. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 May 2014 05:20 PM |
No.
local allPlayers = Game.Players:GetPlayers(); local player1, player2; if #allPlayers >= 2 then player1 = table.remove(allPlayers, math.random(#allPlayers)); player2 = allPlayers[math.random(#allPlayers)];
local chosen = {player1, player2} print( "The fisrt pair is", unpack(chosen)) --squares? end |
|
|
| Report Abuse |
|
|
| |
|
Krauzz
|
  |
| Joined: 24 Sep 2012 |
| Total Posts: 104 |
|
|
| 28 May 2014 05:27 PM |
Um, also you should use a loop to make sure the random players aren't the same player
local player1 local player2 repeat player1 = game:service'Players':GetPlayers()[(math.random(#game:service'Players':GetPlayers())] player2 = game:service'Players':GetPlayers()[(math.random(#game:service'Players':GetPlayers())] until player1 ~= player2 |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 May 2014 05:29 PM |
| No, that's terribly inefficient and my way already deals with that. |
|
|
| Report Abuse |
|
|
Krauzz
|
  |
| Joined: 24 Sep 2012 |
| Total Posts: 104 |
|
|
| 28 May 2014 05:34 PM |
I didn't see your latter post, sry
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 May 2014 05:38 PM |
| My first post even did that, so yeah. |
|
|
| Report Abuse |
|
|
|
| 28 May 2014 07:44 PM |
| @cnt, is their a Lua index? For stuff such as #s and other Lua symbols? |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 May 2014 07:46 PM |
| "#" is just an operator to get the length-of. |
|
|
| Report Abuse |
|
|
|
| 28 May 2014 07:49 PM |
Lol, so you could do: namelenth = game.Players:FindFirstChild("Seizurezxzz") print (#namelenth) prints: 11 Thats just what I think of when you say that. |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 28 May 2014 07:50 PM |
No, because if namelenth isn't nil, it would be a userdata.
print(#namelenth.Name) |
|
|
| Report Abuse |
|
|
|
| 28 May 2014 07:51 PM |
| Well strings aren't considered tables in lua, but that does still work so yes. |
|
|
| Report Abuse |
|
|
| |
|