Evess
|
  |
| Joined: 27 May 2012 |
| Total Posts: 25583 |
|
|
| 24 Dec 2012 09:38 AM |
I tried to make a script that would randomize two teams when an admin would say "scramble teams".
It doesn't seem to work and I can't see the output because it's a chat command.
This is what I got;
function command(msg,speaker) if string.lower(msg) == "scramble teams" then if speaker.Name == "Evess" then _G.Teams = {} _G.Teams["Red team"] = {} _G.Teams["Blue team"] = {} local plrs=randomizetable(game.Players:GetChildren()) for i,v in ipairs(plrs) do if v~=nil and v.Parent~=nil then local t = (i%(#teams))+1 v.TeamColor=teams[t].color _G.Teams[teams[t].name][v.Name] = v end end end end end |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2012 09:57 AM |
local function shuffle(t) local n = #t while n >= 2 do local k = math.random(n) t[n], t[k] = t[k], t[n] n = n - 1 end return t end
function command(msg, speaker) if msg:lower() == "scramble teams" then if speaker.Name == "Evess" then _G.Teams = {["Red team"] = {}, ["Blue team"] = {}} local players = shuffle(game.Players:GetChildren()) for _,p in ipairs(players) do p.TeamColor = _G.Teams["Blue team"] end for x = 1, math.floor(#players/2) do players[x].TeamColor = _G.Teams["Red team"] end end end end
|
|
|
| Report Abuse |
|
|
Evess
|
  |
| Joined: 27 May 2012 |
| Total Posts: 25583 |
|
|
| 24 Dec 2012 01:11 PM |
It didn't work so I put it in a while true do loop instead.
This is the error I got;
Workspace.Team Scrambler:15: bad argument #3 to 'TeamColor' (BrickColor expected, got table)
Line 15 is "p.TeamColor = _G.Teams["Blue team"] " |
|
|
| Report Abuse |
|
|
Evess
|
  |
| Joined: 27 May 2012 |
| Total Posts: 25583 |
|
| |
|
Moolah60
|
  |
| Joined: 26 Sep 2009 |
| Total Posts: 654 |
|
|
| 24 Dec 2012 02:20 PM |
You needed to have it so it set the players team color to an actual BrickColor value, before it was setting _G.Teams["Red team"] to a table rather than to a brick color and then trying to set the players teamcolor as a table. This should work.
local function shuffle(t) local n = #t while true do if n >1 do local k = math.random(n) t[n], t[k] = t[k], t[n] n = n - 1 end wait() end return t end
function command(msg, speaker) if msg:lower() == "scramble teams" then if speaker.Name == "Evess" then _G.Teams = {["Red team"] = BrickColor.new("Bright red"), ["Blue team"] = BrickColor.new("Bright blue")} local players = shuffle(game.Players:GetChildren()) for _,p in ipairs(players) do p.TeamColor = _G.Teams["Blue team"] end for x = 1, math.floor(#players/2) do players[x].TeamColor = _G.Teams["Red team"] end end end end |
|
|
| Report Abuse |
|
|
Moolah60
|
  |
| Joined: 26 Sep 2009 |
| Total Posts: 654 |
|
|
| 24 Dec 2012 02:21 PM |
I always mess up on the forums.. now it should work.
local function shuffle(t) local n = #t while true do if n >1 then local k = math.random(n) t[n], t[k] = t[k], t[n] n = n - 1 end wait() end return t end
function command(msg, speaker) if msg:lower() == "scramble teams" then if speaker.Name == "Evess" then _G.Teams = {["Red team"] = BrickColor.new("Bright red"), ["Blue team"] = BrickColor.new("Bright blue")} local players = shuffle(game.Players:GetChildren()) for _,p in ipairs(players) do p.TeamColor = _G.Teams["Blue team"] end for x = 1, math.floor(#players/2) do players[x].TeamColor = _G.Teams["Red team"] end end end end |
|
|
| Report Abuse |
|
|
Evess
|
  |
| Joined: 27 May 2012 |
| Total Posts: 25583 |
|
|
| 25 Dec 2012 01:38 PM |
It doesn't work for me. I put it in a while wait(1) do form instead of admin chat, and there's no output at all. |
|
|
| Report Abuse |
|
|
gerit99
|
  |
| Joined: 21 Jul 2010 |
| Total Posts: 521 |
|
|
| 25 Dec 2012 01:48 PM |
Is it me or should p.TeamColor = _G.Teams["Blue team"] be p.TeamColor = _G.Teams["Blue team"].TeamColor
|
|
|
| Report Abuse |
|
|
Evess
|
  |
| Joined: 27 May 2012 |
| Total Posts: 25583 |
|
|
| 25 Dec 2012 08:28 PM |
Maybe, I don't know. I think the output would have made an error if that was the case. |
|
|
| Report Abuse |
|
|
|
| 25 Dec 2012 08:31 PM |
@Evess, I've learned that even though there's no output, that doesn't mean there's no errors. I've made scripts before where I purposely added errors, and the output never found them.
~SamuelKingx~LuaLearners Teacher(+2) |
|
|
| Report Abuse |
|
|
Evess
|
  |
| Joined: 27 May 2012 |
| Total Posts: 25583 |
|
|
| 26 Dec 2012 08:03 AM |
| I thought only logical mistakes didn't make any output. |
|
|
| Report Abuse |
|
|