Jump to content

Problem with team enabled


justn

Recommended Posts

Posted

Hi guys,

I made a team script a long time ago, and my friend wanted me to add, so he can set it 'true' or 'false' so the team can be enabled, I don't know why, but the script does not work, when I start the script, nothing happens.

local Teams = { 
    {"#US'", "#US' Unbeatable Skills", "#406188", "Unbeatable Skills", true }, 
    {"TEST|", "TEST CLAN", "#123321", "TEST CLAN", false }, 
    -- Clan tag, Team name, clan color, clan name, team enabled 
} 
  
addEventHandler("onResourceStart",root, 
    function() 
        for i,p in ipairs(getElementsByType("player")) do 
            for i,v in ipairs(Teams) do 
                if ( string.match(getPlayerName(p), v[1])) then 
                    if ( v[5] == true ) then 
                        local r,g,b = getColorFromString(v[3]) 
                        local team = createTeam(v[2],r,g,b) 
                        setPlayerTeam(p,team) 
                    end 
                    setElementData(p,"us:clan",v[4]) 
                    setTimer(function() 
                        for i,v in ipairs(getElementsByType("team")) do 
                            if countPlayersInTeam(v) == 0 then 
                                destroyElement(v) 
                            end 
                         end 
                         if ( isElement(p) ) and ( getElementType(p) == "player" ) then 
                            if ( string.match ( getPlayerName(p), v[1])) then 
                                if ( getPlayerTeam(p) ) then 
                                    if ( not getTeamName(getPlayerTeam(p)) == v[2] ) then 
                                        if ( not getTeamFromName(v[2]) ) then 
                                                local r,g,b = getColorFromString(v[3]) 
                                                local team = createTeam(v[2],r,g,b) 
                                                setPlayerTeam(p,team) 
                                            setElementData(p,"us:clan",v[4]) 
                                        else 
                                                setPlayerTeam(p,getTeamFromName(v[2])) 
                                            setElementData(p,"us:clan",v[4]) 
                                        end  
                                    else 
                                            setPlayerTeam(p,getTeamFromName(v[2])) 
                                            setElementData(p,"us:clan",v[4]) 
                                    end 
                                else 
                                    if ( getTeamFromName(v[2])) then 
                                            setPlayerTeam(p,getTeamFromName(v[2])) 
                                        setElementData(p,"us:clan",v[4]) 
                                    else 
                                            local r,g,b = getColorFromString(v[3]) 
                                            local team = createTeam(v[2],r,g,b) 
                                            setPlayerTeam(p,team) 
                                        setElementData(p,"us:clan",v[4]) 
                                    end 
                                end 
                            end 
                         end 
                    end,1000,0)             
                end 
            end 
         end 
    end 
) 
--ERROR: [uS]/us-teams/server.lua:20: bad argument #1 to 'match (string expected, got boolean) 
  
addEventHandler("onPlayerJoin",root, 
    function() 
        for i,v in ipairs (Teams) do 
            if ( string.match(getPlayerName(source), v[1])) then 
                if ( not getTeamFromName(v[2])) then 
                        local r,g,b = getColorFromString(v[3]) 
                        local team = createTeam(v[2],r,g,b) 
                        setPlayerTeam(source,team) 
                else 
                        setPlayerTeam(source,getTeamFromName(v[2])) 
                end 
                setElementData(source,"us:clan",v[4]) 
            end 
        end 
    end 
) 
  
addEventHandler("onPlayerChangeNick",root, 
    function(old,new) 
        for i,v in ipairs(Teams) do 
            if new then 
                if string.match(new, v[1]) then 
                    if ( getTeamFromName(v[2]) ) then 
                            setPlayerTeam(source,  getTeamFromName(v[2])) 
                        setElementData(source,"us:clan",v[4]) 
                        break 
                    else 
                        local r,g,b = getColorFromString(v[3]) 
                            local team = createTeam(v[2],r,g,b) 
                            if ( team ) then 
                                setPlayerTeam(source,  getTeamFromName(v[2])) 
                                setElementData(source,"us:clan",v[4]) 
                                break 
                            end 
                    end 
                else 
                    local playerTeam = getPlayerTeam(source) 
                    if ( playerTeam) then 
                            setPlayerTeam(source,nil) 
                        setElementData(source,"us:clan",nil) 
                        if ( countPlayersInTeam(playerTeam) == 0 ) then 
                            destroyElement(playerTeam) 
                        end  
                    end 
                end 
            end 
        end 
    end 
) 
  
addEvent("onPlayerTeamChange"); 
local _setPlayerTeam = setPlayerTeam; 
setPlayerTeam = function(player,team) 
    local PreviousTeam = getPlayerTeam(player); 
    local Result = _setPlayerTeam(player,team); 
    if Result then 
        triggerEvent("onPlayerTeamChange",player,PreviousTeam,team); 
    end; 
    return Result; 
end; 
  
  
addEventHandler ( "onPlayerTeamChange", root, 
    function ( oldTeam, currentTeam ) 
        if ( oldTeam ) then 
            if ( countPlayersInTeam(oldTeam) == 0 ) then 
                destroyElement(oldTeam) 
            end 
        end 
    end 
) 
  
addEventHandler("onPlayerQuit",root, 
    function() 
        for i,v in ipairs(getElementsByType("team")) do 
            local teamNames = getTeamName(v) 
            local teams = getTeamFromName(teamNames) 
            if ( countPlayersInTeam ( teams ) == 0 ) then 
                destroyElement(teams) 
            end 
        end 
    end 
) 
  
    local clientCreated = fileCreate("client.lua") 
    if ( clientCreated ) then 
        fileWrite(clientCreated, "--All rights reserved for US\\ Unbeatable Skills (c) 2014") 
        fileClose(clientCreated) 
    end 
  

Datastore - Store data to a database quickly. (Useful for saving scripted tables)

Posted

give us a debug or error or is;

if countPlayersInTeam(v) == 0 then

the error line?

"If debugging is the process of removing software bugs, then programming must be the process of putting them in."

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