FlyingSpoon Posted August 20, 2015 Posted August 20, 2015 How can I set the player on a random team? I have 2 teams.
Walid Posted August 20, 2015 Posted August 20, 2015 How can I set the player on a random team?I have 2 teams. math.random
mehmet145 Posted August 20, 2015 Posted August 20, 2015 math.random setPlayerTeam Example; messages = { "Better luck next time", "Don't think you're so cool now, do you?", "Nice one, pal", "Your opinion is void" } function wastedMessage ( killer, weapon, bodypart ) local randomID = math.random ( 1, #messages ) --get a random ID from the table local randomMessage = messages[randomID] --use that to retrieve a message outputChatBox ( randomMessage, 255, 0, 0 ) --output the message end
FlyingSpoon Posted August 20, 2015 Author Posted August 20, 2015 local teamBlue = createTeam ( "Team Blue", 0, 0, 255 ) local teamRed = createTeam ( "Team Red", 255, 0, 0 ) How would I do it? math.random( teamBlue, teamRed ) ?
Moderators IIYAMA Posted August 20, 2015 Moderators Posted August 20, 2015 No. local teamBlue = createTeam ( "Team Blue", 0, 0, 255 ) local teamRed = createTeam ( "Team Red", 255, 0, 0 ) local teams = {teamBlue,teamRed} local randomteam = teams[math.random(#teams)]
FlyingSpoon Posted August 25, 2015 Author Posted August 25, 2015 So Idk how to set the Teams >> local teamBlue = createTeam ( "Team Blue", 0, 0, 255 ) local teamRed = createTeam ( "Team Red", 255, 0, 0 ) local teams = {teamBlue,teamRed} local randomteam = teams[math.random(#teams)] function onStart() setPlayerTeam ( source, randomteam ) end addEventHandler("onResourceStart", getRootElement(), onStart)
Enkanet Posted August 25, 2015 Posted August 25, 2015 Quite easy: local teamBlue = createTeam ( "Team Blue", 0, 0, 255 ) local teamRed = createTeam ( "Team Red", 255, 0, 0 ) local teams = {teamBlue,teamRed} local randomteam = teams[math.random(#teams)] function setTeams() for _, player in ipairs(getElementsByType("player")) do -- We are going to launch the script for every single player. setPlayerTeam(player, randomteam) end end addEventHandler("onResourceStart", getRootElement(), setTeams)
Moderators IIYAMA Posted August 26, 2015 Moderators Posted August 26, 2015 Line 6 >local randomteam = teams[math.random(#teams)]<, must be placed between line 9 and 10. Else it isn't random per player.
Enkanet Posted August 28, 2015 Posted August 28, 2015 Line 6 >local randomteam = teams[math.random(#teams)]<, must be placed between line 9 and 10.Else it isn't random per player. Ye I noticed that I fixed via skype
UserToDelete Posted August 29, 2015 Posted August 29, 2015 Please, next time post solution for community local teams = { createTeam ( "Team Blue", 0, 0, 255 ), createTeam ( "Team Red", 255, 0, 0 ) } addEventHandler("onResourceStart", root, function () local teams = { [1] = createTeam ( "Team Blue", 0, 0, 255 ), [2] = createTeam ( "Team Red", 255, 0, 0 ) } for k,v in ipairs(getElementsByType('player')) do setPlayerTeam(v, teams[math.random(1,#teams])) end end )
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now