Jump to content

getTeamcolor and teamtag


h4x7o0r

Recommended Posts

Hello there,

I was trying to modify CW Resource but idk how exactly i can do it.

This resource it's kinda "referee" that keeps the score between 2 teams. by default the admin should open the settings of the resource and set teams names and choice ONLY between 2 colors RED and BLUE.

What i want is to modify this res, to get the team tag and team color directly without needed to set by admin.

To making it work, i'm using autoteams (if a registered team tag is used it's automatically redirect the players and create the proper team. I wanna use that values on this script.

To summarize all, i want this script to find if 2 teams are created already, and then to autocreate the name and color for eachteam for cw.

Here's the server-part:

  
-----------------
-- Variables
-----------------
 
-- Names
homeName  = get('HomeName')
enemyName = get('EnemyName')
 
-- Tags
homeTag  = get('HomeTag')
enemyTag = get('EnemyTag')
 
-- Colors
enemyColor = get('EnemyColor')
homeColor  = get('HomeColor')
 
-- Maps
Maps = get('Maps')
 
-- Table
team = {}
 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),
    function(startedRes)
        if getResourceName(getThisResource()) == getResourceName(startedRes) then
            -- Spectators team
            team[3] = createTeam ( "Spectators", 255, 255, 255 )
            -- Create home team
            if homeColor == "Red" then
                team[1] = createTeam ( homeName, 255, 0, 0 )
            elseif homeColor == "Blue" then
                team[1] = createTeam ( homeName, 0, 0, 255 )
            end
            -- Create enemey team
            if enemyColor == "Red" then
                team[2] = createTeam ( enemyName, 255, 0, 0 )
            elseif enemyColor == "Blue" then
                team[2] = createTeam ( enemyName, 0, 0, 255 )
            end
            -- Save in elementdata
            setElementData(team[1], "points", 0)
            setElementData(team[1], "alive", 0)
            setElementData(team[2], "points", 0)
            setElementData(team[2], "alive", 0)
            setElementData(team[1], "left", Maps)
            setElementData(team[1], "warState", "Waiting")
        end
    end
)
 
addEvent("updateNameServer", true)
addEventHandler("updateNameServer", getRootElement(),
    function(thePlayer)
        triggerClientEvent(thePlayer, "updateName", getRootElement(), homeName, homeTag, enemyName, enemyTag)
    end
)
 
addEventHandler("onNotifyPlayerReady", getRootElement(),
    function()
        local playerTeam = getPlayerTeam (source)
        local PVeh= getPedOccupiedVehicle(source)
        if ( playerTeam ) then
            local teamName = getTeamName(playerTeam)
            -- Home Colors
            if teamName == homeName then
                if homeColor == "Red" then
                    setVehicleColor(PVeh, 3, 3, 3, 3)
                    setVehicleHeadLightColor(PVeh, 255, 0, 0)
                    setElementModel(source, 264)
                elseif homeColor == "Blue" then
                    setVehicleColor(PVeh, 79, 79, 79, 79)
                    setVehicleHeadLightColor(PVeh, 0, 0, 255)
                    setElementModel(source, 84)
                end
            -- Enemy Colors
            elseif teamName == enemyName then
                if enemyColor == "Red" then
                    setVehicleColor(PVeh, 3, 3, 3, 3)
                    setVehicleHeadLightColor(PVeh, 255, 0, 0)
                    setElementModel(source, 264)
                elseif enemyColor == "Blue" then
                    setVehicleColor(PVeh, 79, 79, 79, 79)
                    setVehicleHeadLightColor(PVeh, 0, 0, 255)
                    setElementModel(source, 84)
                end
            end
        end
    end
)
 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),
    function()
        local playerTeam = getPlayerTeam (source)
        local PVeh= getPedOccupiedVehicle(source)
        if ( playerTeam ) then
            local teamName = getTeamName(playerTeam)
            if teamName == homeName then
                if homeColor == "Red" then
                    setVehicleColor(PVeh, 3, 3, 3, 3)
                    setVehicleHeadLightColor(PVeh, 255, 0, 0)
                elseif homeColor == "Blue" then
                    setVehicleColor(PVeh, 79, 79, 79, 79)
                    setVehicleHeadLightColor(PVeh, 0, 0, 255)
                end
            -- Enemy Colors
            elseif teamName == enemyName then
                if enemyColor == "Red" then
                    setVehicleColor(PVeh, 3, 3, 3, 3)
                    setVehicleHeadLightColor(PVeh, 255, 0, 0)
                elseif enemyColor == "Blue" then
                    setVehicleColor(PVeh, 79, 79, 79, 79)
                    setVehicleHeadLightColor(PVeh, 0, 0, 255)
                end
            end
        end
    end
)
 
function getBlipAttachedTo( thePlayer )
    local blips = getElementsByType( "blip" )
    for k, theBlip in ipairs( blips ) do
        if getElementAttachedTo( theBlip ) == thePlayer then
            return theBlip
        end
   end
   return false
end
 
addEvent("onRaceStateChanging")
addEventHandler("onRaceStateChanging",getRootElement(),
    function(old, new)
        if old == "Running" and new == "GridCountdown" then
            setElementData(team[1], "alive", countPlayersInTeam(team[1]))
            setElementData(team[2], "alive", countPlayersInTeam(team[2]))
            local players = getElementsByType("player")
            for k,v in ipairs(players) do
                local thePlayer = v
                local playerTeam = getPlayerTeam (thePlayer)
                if ( playerTeam ) then
                    local teamName = getTeamName(playerTeam)
                    -- Kill spectators
                    if teamName == "Spectators" then
                        setTimer(
                            function()
                                setElementHealth(thePlayer,0)
                            end
                        ,1000, 1)
                    end
                end
            end
        end
    end
)
 
addEvent("onRaceStateChanging")
addEventHandler("onRaceStateChanging",getRootElement(),
    function(old, new)
    local players = getElementsByType("player")
        for k,v in ipairs(players) do
        local thePlayer = v
        local playerTeam = getPlayerTeam (thePlayer)
        local theBlip = getBlipAttachedTo(thePlayer)
        local r,g,b
            if ( playerTeam ) then
                if old == "Running" and new == "GridCountdown" then
                r, g, b = getTeamColor (playerTeam)
                setBlipColor(theBlip, tostring(r), tostring(g), tostring(b), 255)
                end
            end
        end
    end
)
 
function playerDied()
    local playerTeam = getPlayerTeam(source)
    if ( playerTeam ) then
        local teamName = getTeamName(playerTeam)
        if teamName ~= "Spectators" then
            local newAlive = getElementData(playerTeam, "alive") - 1
            if newAlive > -1 then
                setElementData(playerTeam, "alive", newAlive)
            end
        end
    end
end
addEventHandler ( "onPlayerWasted", getRootElement(), playerDied )
addEventHandler ( "onPlayerQuit", getRootElement(), playerDied )
 
function playerDied2()
local alive = getAlivePlayers()
    if (#alive == 1) then
    local player = alive[1]
    local playerTeam = getPlayerTeam(player)
    local teamName = getTeamName(playerTeam)
        if teamName == homeName then
            Newpoints = getElementData(team[1], "points") + 1
            setElementData(team[1], "points", Newpoints)
                        newLeft = getElementData(team[1], "left") - 1
            setElementData(team[1], "left", newLeft)
 
        elseif teamName == enemyName then
            Newpoints = getElementData(team[2], "points") + 1
            setElementData(team[2], "points", Newpoints)
                        newLeft = getElementData(team[1], "left") - 1
            setElementData(team[1], "left", newLeft)
 
        end
    end
end
 
addEventHandler ( "onPlayerWasted", getRootElement(), playerDied2 )
addEventHandler ( "onPlayerQuit", getRootElement(), playerDied2 )
 
 
 
addCommandHandler("join",
    function(player, command, teamtag)
        if teamtag == tostring(homeTag) then
        setPlayerTeam(player, team[1])
        outputChatBox("You've joined "..homeName, player, 0, 255, 0)
        end
        if teamtag == tostring(enemyTag) then
        setPlayerTeam(player, team[2])
        outputChatBox("You've joined "..enemyName, player, 0, 255, 0)
        end
        if teamtag == "Spectators" then
        setPlayerTeam(player, team[3])
        outputChatBox("You've joined Spectators", player, 0, 255, 0)
        end
    end
,false)
 
-------------------
-- Admin Commands
-------------------
 
-- get string or default
function getString(var,default)
    local result = get(var)
    if not result then
        return default
    end
    return tostring(result)
end
 
-- AdminGroups from settings
adminGroups = getString('Clanwar.Admingroup',"Admin")
 
addCommandHandler("addpoint",
    function(
Link to comment

like this ?

 function RGBToHex(red, green, blue, alpha) 
    if((red < 0 or red > 255 or green < 0 or green > 255 or blue < 0 or blue > 255) or (alpha and (alpha < 0 or alpha > 255))) then 
        return nil 
    end 
    if(alpha) then 
        return string.format("#%.2X%.2X%.2X%.2X", red,green,blue,alpha) 
    else 
        return string.format("#%.2X%.2X%.2X", red,green,blue) 
    end 
end 
  
   for k,v getElementsByType("vehicle")do 
        local player = getVehicleController(k) 
        if(player)then 
            local pTeam = getPlayerTeam(player) 
            if(pTeam)then 
                local r,g,b = getTeamColor(pTeam) 
                      if r and g and b then 
                        --    smth    RGBToHex(r,g,b)  
                  end 
            end 
        end 
    end 
  

Link to comment

Well i tried to get those values then convert them to hex and maybe somehow use them to fix my script .

like this ?

    for k,v in pairs(team) do 
                      local r,g,b = getTeamColor(pTeam) 
                      if r and g and b then 
                        --    smth    RGBToHex(r,g,b) 
                  end 
                    end 

Link to comment

tnx but i don't know if it's the best. For example, those r,g,b are the colors of the first team i think i need another table to save em properly.

And i can't use that table [team}. As i said before, i'm using another resource to set up autoteams. so the teams are already created. I just need to get teamname and teamcolor for the 2 teams that are already created and use them to the script.

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