FlyingSpoon Posted August 20, 2015 Posted August 20, 2015 How can I set the player on a random team? I have 2 teams. GitHub: https://github.com/flyingspoon YouTube: https://www.youtube.com/channel/UClsnd4SEid3gob33DSk1-GQ
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 Do not yield your back to your enemy, might feel something strange in your ass. Two things are infinite the universe and human stupidity and i'm not sure about the universe. UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators
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 Hahaha Are You Gang ? This is Spartan
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 ) ? GitHub: https://github.com/flyingspoon YouTube: https://www.youtube.com/channel/UClsnd4SEid3gob33DSk1-GQ
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)] Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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) GitHub: https://github.com/flyingspoon YouTube: https://www.youtube.com/channel/UClsnd4SEid3gob33DSk1-GQ
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) '^ Just a beginner scripter.'
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. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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 '^ Just a beginner scripter.'
FlyingSpoon Posted August 29, 2015 Author Posted August 29, 2015 Ty GitHub: https://github.com/flyingspoon YouTube: https://www.youtube.com/channel/UClsnd4SEid3gob33DSk1-GQ
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