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(