Jump to content

Team script


Viirus

Recommended Posts

Hello everybody,

I have a DD server on MTA, with a team script. Everything is okay with the script, but I want to add one thing.

When I put players in the team, their name have the same color than the team, but I want that the car haves the color too, and the ones who don't have a car, just white.

Wan someone help me for this? Thank you!

Link to comment

try this:

addEventHandler("onResourceStart",resourceRoot,function() 
    for i,v getElementsByType("vehicle")do 
        local player = getVehicleController(i) 
        if(player)then 
            local pedTeam = getPlayerTeam(player) 
            if(pedTeam)then 
                local r,g,b = getTeamColor(pedTeam) 
                setVehicleColor(i,r,g,b) 
            else 
                setVehicleColor(i,255,255,255) 
            end 
        else 
            setVehicleColor(i,255,255,255) 
        end 
    end 
end) 
  
addEventHandler("onVehicleStartEnter",root,function(player,_,jacked) 
    local r,g,b = getTeamColor(getPlayerTeam(player)) 
    setVehicleColor(source,r,g,b) 
end) 
addEventHandler("onVehicleExit",root,function() 
    setVehicleColor(source,255,255,255) 
end) 

And next time, please try making a script before coming here.

Link to comment

Jaysds1 your code will working only when resource start

if player got racepickup his color will changed

use this:

function onSetTeamColorToCar(thePlayer) -- start our function 
        if isPedInVehicle (thePlayer) then --player have vehicle? 
            local hisTeam = getPlayerTeam(thePlayer) -- get player team 
            if (hisTeam) then -- if player have team then 
                local r,g,b = getTeamColor(hisTeam) -- get colors 
                local hisVehicle = getPedOccupiedVehicle(thePlayer) --get player vehicle 
                setVehicleColor(hisVehicle,tonumber(r),tonumber(g),tonumber(b)) -- set colors 
            else -- if player not have team then 
                local r,g,b = math.random(255),math.random(255),math.random(255) -- make random colors 
                local hisVehicle = getPedOccupiedVehicle(thePlayer) -- get player vehicle 
                setVehicleColor(hisVehicle,r,g,b) -- set random colors | or you can set here only white color (255,255,255) 
            end 
        end 
    end 
end 
  
function onWaitingForLaggers() --Delay it a bit to allow players to warp in their vehicle 
    setTimer(onSetTeamColorToCar,2000,1,source) -- our timer 
end 
addEventHandler("onNotifyPlayerReady",getRootElement(),onWaitingForLaggers) -- when player is ready, set team color 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),onSetTeamColorToCar) -- do set colors when player got pickup 
addEventHandler("onPlayerReachCheckpoint",getRootElement(),onSetTeamColorToCar) -- do set colors when player got checkpoint 

Edited by Guest
Link to comment

I doesn't work :/ Here's the script

---------------do not change or touch this---------- 
Names={} 
Tags={} 
Colors={} 
ACL={} 
-------------------------------------------------------------- 
  
---------------------------here put your clans read readme for instructions--------------------------------------- 
local names ={} 
local tags  ={} 
local colors ={} 
local acls={} --- put the acl name if you wanna check ACL group or "none" if you don't wanna check 
  
-------- load------------ 
  
function loadTeams() 
 for i,name in pairs(names) do 
Names[i]=name 
end 
  
for i,tag in pairs(tags) do 
Tags[i]=tag 
end 
  
for i,color in pairs(colors) do 
Colors[i] = color 
end 
  
  
for i,acl in pairs(acls) do 
ACL[i] = acl 
end 
 end 
  
  
addEventHandler("onResourceStart",getRootElement(),loadTeams) 
  
--------------------------------------------------- 
  
----- move on start------------------ 
  
function moveOnStart() 
for i,player in pairs(getElementsByType("player")) do 
check(player) 
end 
end 
  
addEventHandler("onResourceStart",getRootElement(),moveOnStart) 
------------------------------------------------------------------------- 
  
-----------check---------------------------- 
  
function check (player) 
setPlayerTeam(player,nil) 
 for i,tag in pairs(tags) do 
    if string.find(getPlayerName(player),tag) then 
local account=getPlayerAccount(player) 
   if ACL[i]~="none" and not  isObjectInACLGroup ( "user." ..getAccountName(account) , aclGetGroup ( ACL[i] ) ) then 
return end 
local name = Names[i] 
local color = Colors[i] 
  if  not getTeamFromName(name) then 
createTeam(name,getColorFromString(color)) 
end 
local team = getTeamFromName(name) 
setPlayerTeam(player,team) 
  
end 
   end 
      end 
  
  
-------------------------------- 
  
  
----------remove Empty Team ---------- 
  
function remove() 
 for t,teams in pairs(names) do 
 local team = getTeamFromName(teams) 
  if team then 
     if  countPlayersInTeam ( team )==0 then 
         destroyElement(team) 
end 
   end 
       end 
          end 
  
----------------------------------------------------- 
  
-------NickChange------------- 
  
function nick(old,new) 
setTimer(check,1000,1,source) 
setTimer(remove,1500,1) 
end 
  
addEventHandler("onPlayerChangeNick",getRootElement(),nick) 
--------------------------------------------- 
  
-------Join-------------------------------- 
  
function join() 
setTimer(check,4000,1,source) 
end 
  
addEventHandler("onPlayerJoin",getRootElement(),join) 
------------------------------- 
  
---------Quit--------------------- 
  
function quit(player) 
setTimer(remove,1000,1) 
end 
  
addEventHandler("onPlayerQuit",getRootElement(),quit) 
------------------------------------ 
  
---------Login--------------------- 
  
function login() 
setTimer(check,1000,1,source) 
setTimer(remove,1500,1) 
end 
  
addEventHandler("onPlayerLogin",getRootElement(),login) 
------------------------------------ 
  
---------Logout--------------------- 
  
function logout() 
setTimer(check,1000,1,source) 
setTimer(remove,1500,1) 
end 
  
addEventHandler("onPlayerLogout",getRootElement(),logout) 
------------------------------------ 
  
  
----------blip-------------- 
  
function blip(player) 
  
 local team = getPlayerTeam(player) 
if team then 
 for v,blip in pairs(getAttachedElements(player)) do 
    if getElementType(blip)=="blip" then 
          local r,g,b =getTeamColor(team) 
             setBlipColor(blip,r,g,b,255) 
         end 
              end 
                     end  
 end 
    
  
function timer() 
setTimer(blip,3000,1,source) 
end 
  
addEventHandler("onPlayerSpawn",getRootElement(),timer) 
  
  
function onSetTeamColorToCar(thePlayer) -- start our function 
        if isPedInVehicle (thePlayer) then --player have vehicle? 
            local hisTeam = getPlayerTeam(thePlayer) -- get player team 
            if (hisTeam) then -- if player have team then 
                local r,g,b = getTeamColor(hisTeam) -- get colors 
                local hisVehicle = getPedOccupiedVehicle(thePlayer) --get player vehicle 
                setVehicleColor(hisVehicle,tonumber(r),tonumber(g),tonumber(b)) -- set colors 
            else -- if player not have team then 
                local r,g,b = math.random(255),math.random(255),math.random(255) -- make random colors 
                local hisVehicle = getPedOccupiedVehicle(thePlayer) -- get player vehicle 
                setVehicleColor(hisVehicle,r,g,b) -- set random colors | or you can set here only white color (255,255,255) 
            end 
        end 
    end 
end 
  
function onWaitingForLaggers() --Delay it a bit to allow players to warp in their vehicle 
    setTimer(onSetTeamColorToCar,2000,1,source) -- our timer 
end 
addEventHandler("onNotifyPlayerReady",getRootElement(),onWaitingForLaggers) -- when player is ready, set team color 
addEventHandler("onPlayerPickUpRacePickup",getRootElement(),onSetTeamColorToCar) -- do set colors when player got pickup 
addEventHandler("onPlayerReachCheckpoint",getRootElement(),onSetTeamColorToCar) -- do set colors when player got checkpoint 

Is there any sollution to edit that in the admin panel ? If not is there another sollution?

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