• choose random player to join team 2 on gamemode start
    5 replies, posted
[lua] function GM:Initialize( ply ) local Players = player.GetAll() for i = 1, table.Count(Players) do local ply = Players[i] ply:SetTeam( 2 ) end end [/lua] Apparently that code chooses everyone in the game according to the wiki, How would I make it choose one?
table.Random(Players) maybe
[ERROR] gamemodes/tele/gamemode/init.lua:41: 'for' limit must be a number 1. unknown - gamemodes/tele/gamemode/init.lua:41 2. unknown - lua/includes/modules/concommand.lua:69 [lua] for i = 1, table.Random(Players) do [/lua] I don't understand the error?
[LUA] local randomplayer = table.Random( player.GetAll() ) randomplayer:SetTeam( 2 ) [/LUA]
table.Random(Players) returns a random item from your table, in case of Players, it obviously isn't a number, but a player.
[QUOTE=Robotboy655;42377454]table.Random(Players) returns a random item from your table, in case of Players, it obviously isn't a number, but a player.[/QUOTE] ohhhh okay that makes more sense [editline]2nd October 2013[/editline] [QUOTE=rejax;42377443][LUA] local randomplayer = table.Random( player.GetAll() ) randomplayer:SetTeam( 2 ) [/LUA][/QUOTE] Thank you :)
Sorry, you need to Log In to post a reply to this thread.