xLink123
|
  |
| Joined: 07 Aug 2014 |
| Total Posts: 11158 |
|
|
| 24 Jan 2015 03:59 PM |
Say if I had 12 people in the entire server
one person gets assigned "2"
4 get assigned "1"
and 7 get assigned "0" |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:02 PM |
local function assign() for x, player in next, game.Players:GetPlayers() do if (x == 1) then --[[This player is a 2]] elseif (x =< 3) --[[This player is a 1]] else --[[This player is a 0]] end end end
assign() |
|
|
| Report Abuse |
|
|
xLink123
|
  |
| Joined: 07 Aug 2014 |
| Total Posts: 11158 |
|
|
| 24 Jan 2015 04:08 PM |
I knew how to do this, but will that not just give random players numbers?
there can only be 4 1s, and 1 2, and 7 0s |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:15 PM |
for Index, Value in pairs(table.sort(game.Players:GetPlayers(), function() return math.random() < 0.5 end)) do if Index < 2 then --Assign 2 elseif Index < 6 then --Assign 1 else --Assign 0 end end |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:16 PM |
if (x == 1) then --[[This player is a 2]] elseif (x =< 3) --[[This player is a 1]] else --[[This player is a 0]] end
x will only be 1 once x will only be less than or the same as 3 3 times, but the first time it was one, so 2 times
every other time it will be 4+, so it will do the else make 0
You might wanna shuffle the players table though so the same people are not picked every time |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:17 PM |
| That's not quite how he said it. He wanted FOUR people to get a 1. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:18 PM |
@Jarod table.sort does not return anything, and if it did that script will sometimes give you the error invalid order function for sorting
Also I just noticed you said 4 people should have the value 1 change elseif (x =< 3)
to elseif (x =< 5)
|
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:22 PM |
local Players = game.Players:GetPlayers() table.sort(Players, function(...) return math.random() < 0.5 end) for Index, Value in pairs(Players) do if Index < 2 then --Assign 2 elseif Index < 6 then --Assign 1 else --Assign 0 end end |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:26 PM |
Oh, and here.
local _table = table getfenv(1).table = setmetatable({sort = function(Table, Comp) _table.sort(Table, Comp) return Table end}, {__index = _table}) |
|
|
| Report Abuse |
|
|
xLink123
|
  |
| Joined: 07 Aug 2014 |
| Total Posts: 11158 |
|
|
| 24 Jan 2015 04:26 PM |
| yea I wish I knew what that meant |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:27 PM |
I gave you the code :(
Just put it in a function to run when you want to get the players, and yeah. Also add the part to assign the values, as marked by comments. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:32 PM |
You still didn't fix this problem Jarod invalid order function for sorting
|
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:34 PM |
| How so? Tell me exactly what I am doing wrong. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:40 PM |
table.sort(Players, function(...) return math.random() < 0.5 end)
That can error because it gives an impossible combination of how to sort it
It could say
Player1 goes before Player2 Player2 goes before Player3 Player3 goes before Player1
How can x be more than y, y be more than z, and z be more than x? |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:41 PM |
Okay, you're wrong. It is supposed to return true or false. My code does exactly that. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:50 PM |
I'm not wrong
local players = {} for x = 1, 12, 1 do local fakePlayer = Instance.new("Model", workspace) fakePlayer.Name = ("Player" .. x) table.insert(players, fakePlayer) end --[[It doesn't matter if we use real players, this is about how you sorted your table.]]
table.sort(players, function(...) return (math.random() > 0.5) end)
--[[Run this more than once because its possible that you just so happen to not get the combination that errors.]]
X can be more than Y Y can be more than Z But if the above 2 are true, Z can not be more than X |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:55 PM |
| It returns true or false to tell it if value x is more than value y |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 04:58 PM |
Oh, I see.
Although your example did nothing for me, especially the needless part with the fake players.
Whatever, it is a really easy fix. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 05:08 PM |
| https://www.youtube.com/watch?v=gfii9uV_Q64 |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 05:10 PM |
| I already know what the problem is. I just didn't need the five lines of unnecessary code to confuse me. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 05:12 PM |
| Okay sorry I just needed a table to sort and I wanted to put objects in it to represent players. |
|
|
| Report Abuse |
|
|
|
| 24 Jan 2015 05:14 PM |
| Yeah, that's fine. When I was reading your explanations before that, I wasn't paying too much attention and I thought you were unaware that I can compare userdatas or something, when you said "How can Blah be less than OtherBlah" |
|
|
| Report Abuse |
|
|