Jump to content

[REL] Autoteams on 1.1


Cadu12

Recommended Posts

I did created myself it toady and works

https://community.multitheftauto.com/index.php?p= ... ls&id=2855

Server-side:

Tags = { {"YCN%|", "Your clan name", "#00bb9b", nil} } 
  
ATCarcolor = true 
ATNormalColor = {255, 255, 255} 
ATFixspam = {} 
  
function onResourceStartAutoteams() 
    for name, data in ipairs(Tags) do 
        for id, player in ipairs(getElementsByType("player")) do 
            table.insert(ATFixspam, {source, false}) 
            if string.find(getPlayerName(player), data[1]) then 
                if not isElement(data[2]) or getElementType(data[2]) ~= "team" then 
                    creatingTeam = createTeam(data[2], getColorFromString (data[3])) 
                    if creatingTeam then 
                        outputDebugString("Autoteams: Added team '" .. data[2] .. "'.") 
                        data[4] = creatingTeam 
                    end 
                end 
                setTimer(function() 
                            local int = {} 
                            for name, data in ipairs(Tags) do 
                                for id, player in ipairs(getElementsByType("player")) do 
                                    if string.find(getPlayerName(player), data[1]) then 
                                        movedteam = setPlayerTeam(player, data[4]) 
                                        if not movedteam then 
                                            MoveToTeam = getTeamFromName(data[2]) 
                                            if getPlayerTeam(player) and getFixspam(player) == false then 
                                                outputDebugString("Autoteams: Set '" .. getPlayerName(player) .. "' to team as '" .. data[2] .. "'.") 
                                                setFixspam(player, true) 
                                            end 
                                            setPlayerTeam(player, MoveToTeam) 
                                        elseif getPlayerTeam(player) and getFixspam(player) == false then 
                                            outputDebugString("Autoteams: Set '" .. getPlayerName(player) .. "' to team as '" .. data[2] .. "'.") 
                                            setFixspam(player, true) 
                                        end 
                                    end 
                                end 
                            end 
                         end, 2000, 1) 
            end 
        end 
    end 
end 
addEventHandler( "onResourceStart", getResourceRootElement(getThisResource()), onResourceStartAutoteams ) 
  
function onPlayerChangeNickAutoteams() 
    setTimer(checkPlayerTeam, 1000, 1, source) 
end 
addEventHandler("onPlayerChangeNick", getRootElement(), onPlayerChangeNickAutoteams) 
  
function onPlayerJoinAutoteams() 
    setTimer(checkPlayerTeam, 1000, 1, source) 
    table.insert(ATFixspam, {source, false}) 
end 
addEventHandler("onPlayerJoin", getRootElement(), onPlayerJoinAutoteams) 
  
function onPlayerQuitAutoteams() 
    -- Remove teams if players are not team 
    for i, v in ipairs(ATFixspam) do 
        if v[1] == source then 
            table.remove(ATFixspam, i) 
        end 
    end 
    returnPlayerTeam = getPlayerTeam(source) 
    if returnPlayerTeam then 
        outputDebugString("Autoteams: Removed '" .. getPlayerName(source) .. "' from team as '" .. getTeamName(returnPlayerTeam) .. "'.") 
        if countPlayersInTeam(returnPlayerTeam) == 0 then 
            outputDebugString("Autoteams: Removed team '" .. returnPlayerTeam .. "'.") 
            destroyElement(returnPlayerTeam) 
        end 
    end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuitAutoteams) 
  
function checkPlayerTeam(player) 
    local publicplayer = player 
    for name, data in ipairs(Tags) do 
        if string.find(getPlayerName(player), data[1]) then 
            if not isElement(data[4]) or getElementType(data[4]) ~= "team" then 
                creatingTeam = createTeam(data[2], getColorFromString(data[3])) 
                if creatingTeam then 
                    outputDebugString("Autoteams: Added team '" .. data[2] .. "'.") 
                    data[4] = creatingTeam 
                end 
            end 
            setTimer(function() 
                        for name, data in ipairs(Tags) do 
                            if string.find(getPlayerName(publicplayer), data[1]) then 
                                movedteam = setPlayerTeam(publicplayer, data[4]) 
                                if not movedteam then 
                                    MoveToTeam = getTeamFromName(data[2]) 
                                    setPlayerTeam(player, MoveToTeam) 
                                    if getPlayerTeam(player) and getFixspam(player) == false then 
                                        outputDebugString("Autoteams: Set '" .. getPlayerName(player) .. "' to team as '" .. data[2] .. "'.") 
                                        setFixspam(player, true) 
                                    end 
                                elseif getPlayerTeam(player) and getFixspam(player) == false then 
                                    outputDebugString("Autoteams: Set '" .. getPlayerName(player) .. "' to team as '" .. data[2] .. "'.") 
                                    setFixspam(player, true) 
                                end 
                            end 
                        end 
                     end, 2000, 1) 
        else 
            -- Remove teams if players are not team 
            returnPlayerTeam = getPlayerTeam(player) 
            if returnPlayerTeam then 
                outputDebugString("Autoteams: Removed '" .. getPlayerName(player) .. "' from team as '" .. getTeamName(returnPlayerTeam) .. "'.") 
                setPlayerTeam(player, nil) 
                setFixspam(player, false) 
                if countPlayersInTeam(returnPlayerTeam) == 0 then 
                    outputDebugString("Autoteams: Removed team '" .. getTeamName(returnPlayerTeam) .. "'.") 
                    destroyElement(returnPlayerTeam) 
                end 
            end 
        end 
    end 
end 
  
function setFixspam(player, boolean) 
    for i, v in ipairs(ATFixspam) do 
        if v[1] == player then 
            v[2] = boolean 
        end 
    end 
end 
  
function getFixspam(player) 
    if not ATFixspam then return end 
    for i, v in ipairs(ATFixspam) do 
        if v[1] == player then 
            return v[2] 
        end 
    end 
end 

For whos wants blips for race, add line:

function onRaceEveryTime() 
    for _,player in ipairs(getElementsByType("player")) do 
        if not getPlayerTeam(player) then 
            checkPlayerTeam(player) 
        end 
        if ATCarcolor == true then 
            local r,g,b = ATNormalColor[1], ATNormalColor[2], ATNormalColor[3] 
            local team = getPlayerTeam(player) 
            if team then 
                r,g,b = getTeamColor(team) 
            end  
            local PedIsInVehicle = getPedOccupiedVehicle(player) 
            if PedIsInVehicle then 
                setVehicleHeadLightColor(PedIsInVehicle, tonumber(r), tonumber(g), tonumber(b)) 
                setVehicleColor(PedIsInVehicle, tonumber(r), tonumber(g), tonumber(b)) 
            end 
            local attachElement = getAttachedElements(player) 
            if attachElement and #attachElement > 0 then 
                for k, v in ipairs(attachElement) do 
                    if getElementType(v) and getElementType(v) == "blip" then 
                        setBlipColor(v, tonumber(r), tonumber(g), tonumber(b), 255) 
                    end 
                end 
            end 
        end 
    end 
end 
setTimer(onRaceEveryTime, 250, 0) 

Changelogs:

1.0: First public release

1.1: Fixed bugged

1.2: Fixed bugged. Added team color for blips

1.3: Fixed bugged for blips

1.4: Added event for race

1.5:

• Fixed bugs

1.6

• Fixed bugs

2.0

• Fixed bugs

• Fixed spammer on debugscript

Add credis if you used

Edited by Guest
Link to comment

nope only your script is full buged ( i tested my self only debugscript created team player added to team and done no team on scoreboard and so on .. and an autoeam don't need admin right's) and you don't change anything and i am just helping @Hunterix for the fastest solution for his problem

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