Jump to content

some Help in Teams :(


^Dev-PoinT^

Recommended Posts

Hey i make This how To Make 2 thing

1- outputChatBox To The Player Your are Now in team ..

2- RedTeam Kill Blue Team Onley

and Blue Team dont kill Red Team Only :D

function team () 
    teamRed = createTeam ("Red", 255, 0, 0 ) 
    teamBlue = createTeam ("Blue", 0, 0, 255) 
end 
addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), team ) 
  
function count (thePlayer) 
local teamRed = getTeamFromName ( "Red" ) 
local teamBlue = getTeamFromName( "Blue" ) 
local RedCount = countPlayersInTeam ( teamRed ) 
local BlueCount = countPlayersInTeam( teamBlue ) 
if Redcount == Bluecount then 
    setPlayerTeam (thePlayer, teamRed ) 
    elseif Redcount < Bluecount then 
    setPlayerTeam (thePlayer, teamBlue ) 
    else if Redcount < Bluecount then 
    setPlayerTeam (thePlayer,teamRed ) 
    end 
end 
addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), count ) 

just This :)

Link to comment

mybe this Work: For #2

    function team () 
        teamRed = createTeam ("Red", 255, 0, 0 ) 
        teamBlue = createTeam ("Blue", 0, 0, 255) 
    end 
    addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), team ) 
      
    function count (thePlayer) 
    local teamRed = getTeamFromName ( "Red" ) 
    local teamBlue = getTeamFromName( "Blue" ) 
    local RedCount = countPlayersInTeam ( teamRed ) 
    local BlueCount = countPlayersInTeam( teamBlue ) 
    if Redcount == Bluecount then 
        setPlayerTeam (thePlayer, teamRed ) 
        elseif Redcount < Bluecount then 
        setPlayerTeam (thePlayer, teamBlue ) 
        else if Redcount > Bluecount then 
        setPlayerTeam (thePlayer,teamRed ) 
  
        setTeamFriendlyFire ( teamBlue, false ) 
        setTeamFriendlyFire ( teamRed, false ) 
        end 
    end 
    addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), count ) 

Link to comment

its say teams.lua 'end' expected (to close 'if' at line 16 near ''

function x () 
    teamRed = createTeam ( "Red", 255, 0, 0 ) 
    teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), x  ) 
     
function count (thePlayer) 
    local teamRed = getTeamFromName ( "Red" ) 
    local teamBlue = getTeamFromName( "Blue" ) 
    local RedCount = countPlayersInTeam ( teamRed ) 
    local BlueCount = countPlayersInTeam( teamBlue ) 
    if Redcount == Bluecount then 
    setPlayerTeam (thePlayer, teamRed ) 
    elseif Redcount < Bluecount then 
    setPlayerTeam (thePlayer, teamBlue ) 
    else if Redcount > Bluecount then 
    setPlayerTeam (thePlayer,teamRed ) 
    setTeamFriendlyFire ( teamBlue, false ) 
    setTeamFriendlyFire ( teamRed, false ) 

Link to comment
    function x () 
        teamRed = createTeam ( "Red", 255, 0, 0 ) 
        teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
    end 
    addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), x  ) 
        
    function count (thePlayer) 
        local teamRed = getTeamFromName ( "Red" ) 
        local teamBlue = getTeamFromName( "Blue" ) 
        local RedCount = countPlayersInTeam ( teamRed ) 
        local BlueCount = countPlayersInTeam( teamBlue ) 
        if Redcount == Bluecount then 
        setPlayerTeam (thePlayer, teamRed ) 
        elseif Redcount < Bluecount then 
        setPlayerTeam (thePlayer, teamBlue ) 
        elseif Redcount > Bluecount then 
        setPlayerTeam (thePlayer,teamRed ) 
        setTeamFriendlyFire ( teamBlue, false ) 
        setTeamFriendlyFire ( teamRed, false ) 

Link to comment

@ ^Dev-PoinT^

I could give you the answer.. But I wont..

But I am gonna tell you this, as a hint:

Remember that you should always close, function, if, for.

Example:

  
function something() 
if(something == something)then 
for i,k in ipairs(something)do 
--something 
end 
elseif(something == somethingElse)then 
--something else 
end 
end 
  

If that doesn't help you, then you should really start reading the Wiki from the beginning again.

I know that scripting can be hard when you are learning.. ( I started 6 months ago, so I know )

But you also need to learn how to solve problems on your own.

Good luck :)

EDIT: Also, as -=I Blaawee I=- said:

It should be "elseif" not "else if".

I would really recommend that you start reading everything you can on the wiki and the Lua documentation.

You have some basic understanding of how scripting for Mta works, but it seems that you have no idea how Lua works. Do some reading and you will get better over time :)

Edited by Guest
Link to comment

i fix it :D but its dont set me in any team :(

function createTeamsOnStart () 
    teamRed = createTeam ( "Red", 255, 0, 0 ) 
    teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function balanceTeams ( thePlayer ) 
    local RedTeam = getTeamFromName ( "Red" ) 
    local BlueTeam = getTeamFromName ( "Blue" ) 
    local RedCount = countPlayersInTeam ( RedTeam ) 
    local BlueCount = countPlayersInTeam ( BlueTeam ) 
    if RedCount == BlueCount then 
        setPlayerTeam ( thePlayer , RedTeam ) 
    elseif RedCount > BlueCount then 
        setPlayerTeam ( thePlayer , BlueTeam ) 
    elseif RedCount < BlueCount then 
        setPlayerTeam ( thePlayer , RedTeam ) 
    end 
end 

Link to comment

i see this on mta wiki Teams functions its say (thePlayer)

i made this and did not work :x

function createTeamsOnStart () 
    teamRed = createTeam ( "Red", 255, 0, 0 ) 
    teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function balanceTeams ( source ) 
    local RedTeam = getTeamFromName ( "Red" ) 
    local BlueTeam = getTeamFromName ( "Blue" ) 
    local RedCount = countPlayersInTeam ( RedTeam ) 
    local BlueCount = countPlayersInTeam ( BlueTeam ) 
    local source = getLocalPlayer() 
    if RedCount == BlueCount then 
        setPlayerTeam ( source , RedTeam ) 
    elseif RedCount > BlueCount then 
        setPlayerTeam ( source , BlueTeam ) 
    elseif RedCount < BlueCount then 
        setPlayerTeam ( source , RedTeam ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), balanceTeams ) 

Link to comment
function createTeamsOnStart () 
    teamRed = createTeam ( "Red", 255, 0, 0 ) 
    teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function balanceTeams ( thePlayer, source ) 
    local RedTeam = getTeamFromName ( "Red" ) 
    local BlueTeam = getTeamFromName ( "Blue" ) 
    local RedCount = countPlayersInTeam ( RedTeam ) 
    local BlueCount = countPlayersInTeam ( BlueTeam ) 
    if not RedCount == BlueCount then 
        if RedCount > BlueCount then 
            setPlayerTeam ( source , teamBlue ) 
            outputChatBox("You've been moved to the blue team!", thePlayer) 
         elseif RedCount < BlueCount then 
            setPlayerTeam ( source , teamRed ) 
            outputChatBox("You've been moved to the red team!", thePlayer) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), balanceTeams ) 

This should work. Learn from this. Study what I've changed. You have potential, but your lazy, honestly. Good luck!

Link to comment

thx its say

'end' expected(to close 'function' at line 7 near ''

function createTeamsOnStart () 
    teamRed = createTeam ( "Red", 255, 0, 0 ) 
    teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function balanceTeams ( thePlayer, source ) 
    local RedTeam = getTeamFromName ( "Red" ) 
    local BlueTeam = getTeamFromName ( "Blue" ) 
    local RedCount = countPlayersInTeam ( RedTeam ) 
    local BlueCount = countPlayersInTeam ( BlueTeam ) 
    if not RedCount == BlueCount then 
        if RedCount > BlueCount then 
            setPlayerTeam ( source , teamBlue ) 
            outputChatBox("You've been moved to the blue team!", thePlayer) 
         elseif RedCount < BlueCount then 
            setPlayerTeam ( source , teamRed ) 
            outputChatBox("You've been moved to the red team!", thePlayer) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), balanceTeams ) 
  

Link to comment
function createTeamsOnStart () 
    teamRed = createTeam ( "Red", 255, 0, 0 ) 
    teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function balanceTeams ( thePlayer, source ) 
    local RedTeam = getTeamFromName ( "Red" ) 
    local BlueTeam = getTeamFromName ( "Blue" ) 
    local RedCount = countPlayersInTeam ( RedTeam ) 
    local BlueCount = countPlayersInTeam ( BlueTeam ) 
    if not RedCount == BlueCount then 
        if RedCount > BlueCount then 
            setPlayerTeam ( source , teamBlue ) 
            outputChatBox("You've been moved to the blue team!", thePlayer) 
         elseif RedCount < BlueCount then 
            setPlayerTeam ( source , teamRed ) 
            outputChatBox("You've been moved to the red team!", thePlayer) 
         end 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), balanceTeams ) 
  

Forgot to add an end. :P

Link to comment

you mean like this ?

function createTeamsOnStart () 
    teamRed = createTeam ( "Red", 255, 0, 0 ) 
    teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), createTeamsOnStart  ) 
  
function balanceTeams () 
    local RedTeam = getTeamFromName ( "Red" ) 
    local BlueTeam = getTeamFromName ( "Blue" ) 
    local RedCount = countPlayersInTeam ( RedTeam ) 
    local BlueCount = countPlayersInTeam ( BlueTeam ) 
    if not RedCount == BlueCount then 
        if RedCount > BlueCount then 
            setPlayerTeam ( source , teamBlue ) 
            outputChatBox("You've been moved to the blue team!", source) 
         elseif RedCount < BlueCount then 
            setPlayerTeam ( source , teamRed ) 
            outputChatBox("You've been moved to the red team!", source) 
         end 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), balanceTeams ) 
  

Link to comment

Improved code:

teamRed = createTeam ( "Red", 255, 0, 0 ) 
teamBlue = createTeam ( "Blue", 0, 0, 255 ) 
  
function balanceTeams ( ) 
    local RedCount = countPlayersInTeam ( teamBlue ) 
    local BlueCount = countPlayersInTeam ( teamRed ) 
    if RedCount ~= BlueCount then 
        if RedCount > BlueCount then 
            setPlayerTeam ( source , teamBlue ) 
         elseif RedCount < BlueCount then 
            setPlayerTeam ( source , teamRed ) 
         end 
         outputChatBox ( "You've been moved to the "..getTeamName ( getPlayerTeam ( source ) ):lower ( ).." team!", source ) 
    end 
end 
addEventHandler ( "onPlayerJoin", getRootElement ( ), balanceTeams ) 

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...