Admigo Posted February 4, 2012 Share Posted February 4, 2012 Dear scripters, I have a problem with this script: function setTheCarColors( ) local endteam = getTeamFromName( "END#" ) for i, car in ipairs( getElementsByType( "vehicle" ) ) do local theplayer = getVehicleOccupant( car ) local nowteam = getPlayerTeam( theplayer ) if theplayer then if(nowteam == endteam) then setVehicleColor(car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) end end end end addEvent("onVehColorChange",true) addEventHandler("onVehColorChange",getRootElement(),setTheCarColors) function timer() --Delay it a bit to allow players to warp in their vehicle... setTimer(setTheCarColors,500,0) end addEventHandler("onMapStarting",getRootElement(),timer) addCommandHandler ( "set_vehicle_color", setTheCarColors ) I want that players is admin team get a yellow carpaint with a time of 500 so its detecting it. But why this code dont work? Thanks Admigo Link to comment
arezu Posted February 4, 2012 Share Posted February 4, 2012 onMapStarting is a custom event so you need to add; addEvent too. But since you are never killing the timer, you dont need to put it inside that event. function setTheCarColors( ) local endteam = getTeamFromName( "END#" ) for i, car in ipairs( getElementsByType( "vehicle" ) ) do local theplayer = getVehicleOccupant( car ) local nowteam = getPlayerTeam( theplayer ) if theplayer then if(nowteam == endteam) then setVehicleColor(car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) end end end end addEvent("onVehColorChange",true) addEventHandler("onVehColorChange",getRootElement(),setTheCarColors) setTimer(setTheCarColors,500,0) Link to comment
Kenix Posted February 5, 2012 Share Posted February 5, 2012 Server side. addEvent( "onVehColorChange",true ) addEvent( "onMapStarting",true ) function setTheCarColors( ) for i, car in ipairs( getElementsByType( "vehicle" ) ) do local theplayer = getVehicleOccupant( car ) if isElement( theplayer ) then local nowteam = getPlayerTeam( theplayer ) local endteam = getTeamFromName( "END#" ) if nowteam == endteam then setVehicleColor( car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) end end end end addEventHandler( "onVehColorChange",root,setTheCarColors ) function timer( ) --Delay it a bit to allow players to warp in their vehicle... setTimer( setTheCarColors,500,0 ) end addEventHandler("onMapStarting",root,timer ) addCommandHandler ( "set_vehicle_color", setTheCarColors ) Link to comment
Admigo Posted February 5, 2012 Author Share Posted February 5, 2012 onMapStarting is a custom event so you need to add; addEvent too.But since you are never killing the timer, you dont need to put it inside that event. function setTheCarColors( ) local endteam = getTeamFromName( "END#" ) for i, car in ipairs( getElementsByType( "vehicle" ) ) do local theplayer = getVehicleOccupant( car ) local nowteam = getPlayerTeam( theplayer ) if theplayer then if(nowteam == endteam) then setVehicleColor(car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) end end end end addEvent("onVehColorChange",true) addEventHandler("onVehColorChange",getRootElement(),setTheCarColors) setTimer(setTheCarColors,500,0) I get spam error:bad argument@GetPlayerTeam How can i fix this? Link to comment
Castillo Posted February 5, 2012 Share Posted February 5, 2012 addEvent( "onVehColorChange",true ) addEvent( "onMapStarting",true ) function setTheCarColors( ) for i, car in ipairs( getElementsByType( "vehicle" ) ) do local theplayer = getVehicleController( car ) if (theplayer and isElement( theplayer )) then local nowteam = getPlayerTeam( theplayer ) local endteam = getTeamFromName( "END#" ) if (nowteam == endteam) then setVehicleColor( car, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) end end end end addEventHandler( "onVehColorChange",root,setTheCarColors ) function timer( ) --Delay it a bit to allow players to warp in their vehicle... setTimer( setTheCarColors,500,0 ) end addEventHandler("onMapStarting",root,timer ) addCommandHandler ( "set_vehicle_color", setTheCarColors ) Link to comment
Admigo Posted February 5, 2012 Author Share Posted February 5, 2012 Thanks dude,Code works great:P Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now