Jump to content

How can I set the player on a random team?


FlyingSpoon

Recommended Posts

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 

Link to comment

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) 

Link to comment

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) 
  

Link to comment

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 
) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...