meh Posted April 16, 2012 Author Share Posted April 16, 2012 Which script is that? could you post it? sure. it's DrakeN's script: local tVehicles = -- what draken was saying is, its alot easier to find and edit it now, the code looks more organized too. { [ 598 ] = true; [ 596 ] = true; [ 597 ] = true; [ 411 ] = true; [ 599 ] = true; } -- Simple Police-Lights by MuLTi! p_lights = {} p_timer = {} p_lvar = {} p_pvar = {} p_lvar2 = {} p_lvar3 = {} p_lvar4 = {} function toggleLights(thePlayer, cmd, level) local level = tonumber(level) if not(level) then outputChatBox("#FF0000 Please select a level![1-2]", thePlayer, 255, 255, 255, true) return end if(level < 1) or (level > 2) then outputChatBox("#FF0000 Please select a level between 1-2!", thePlayer, 255, 255, 255, true) return end local veh = getPedOccupiedVehicle(thePlayer) local id = getElementModel(veh) if ( tVehicles [ getPedOccupiedVehicle ( thePlayer ) ] ) then if(level == 1) then if(p_lights[veh] == 0) or(p_lights[veh] == nil) then p_pvar[veh] = 1 p_lights[veh] = 1 outputChatBox("#FFFFFFYour Police-lights has been #00FF00enabled.", thePlayer, 0, 200, 100, true) setVehicleOverrideLights ( veh, 2 ) p_timer[veh] = setTimer( function() if(p_lvar[veh] == 0) or (p_lvar[veh] == nil) then p_lvar[veh] = 1 setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 0, 1) setVehicleLightState ( veh, 3, 1) setVehicleHeadLightColor(veh, 0, 0, 255) else setVehicleLightState ( veh, 3, 0) setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 1) setVehicleLightState ( veh, 2, 1) setVehicleHeadLightColor(veh, 255, 0, 0) p_lvar[veh] = 0 end end, 500, 0) else p_lights[veh] = 0 outputChatBox("#FFFFFFYour Police-lights has been #00FF00disabled.", thePlayer, 0, 200, 100, true) killTimer(p_timer[veh]) setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 3, 0) setVehicleHeadLightColor(veh, 255, 255, 255) setVehicleOverrideLights ( veh, 1 ) end elseif(level == 2) then if(p_lights[veh] == 0) or(p_lights[veh] == nil) then p_lights[veh] = 1 outputChatBox("#FFFFFFYour Police-lights has been #00FF00enabled.", thePlayer, 0, 200, 100, true) setVehicleOverrideLights ( veh, 2 ) p_timer[veh] = setTimer( function() if(p_lvar3[veh] == 4) then setTimer(function() p_lvar3[veh] = 0 end, 1000, 1) setTimer( function() if(p_lvar4[veh] == 1)then p_lvar4[veh] = 0 -- 0 = vorne links 1 = vorne rechts 2 = hinten links 3 = hinten rechts setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 0, 1) setVehicleLightState ( veh, 3, 1) setVehicleHeadLightColor(veh, 77, 77, 255) else setVehicleLightState ( veh, 3, 0) ш setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 1) setVehicleLightState ( veh, 2, 1) setVehicleHeadLightColor(veh, 255, 77, 77) p_lvar4[veh] = 1 end end, 50, 5) return end if(p_lvar2[veh] == 0) or (p_lvar2[veh] == nil) then p_lvar2[veh] = 1 -- 0 = vorne links 1 = vorne rechts 2 = hinten links 3 = hinten rechts setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 0, 1) setVehicleLightState ( veh, 3, 1) setVehicleHeadLightColor(veh, 0, 0, 255) else setVehicleLightState ( veh, 3, 0) setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 1) setVehicleLightState ( veh, 2, 1) setVehicleHeadLightColor(veh, 255, 0, 0) p_lvar2[veh] = 0 end if(p_lvar3[veh] == nil) then p_lvar3[veh] = 0 end p_lvar3[veh] = (p_lvar3[veh]+1) end, 500, 0) else p_lights[veh] = 0 outputChatBox("#FFFFFFYour Police-lights has been #00FF00disabled.", thePlayer, 0, 200, 100, true) killTimer(p_timer[veh]) setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 3, 0) setVehicleHeadLightColor(veh, 255, 255, 255) setVehicleOverrideLights ( veh, 1 ) end end end end addCommandHandler("lights", toggleLights) addEventHandler ( "onVehicleExplode", getRootElement(), function() if(p_lights[source] == 1) then killTimer(p_timer[source]) end end ) addEventHandler ( "onVehicleRespawn", getRootElement(), function() if(p_lights[source] == 1) then killTimer(p_timer[source]) end end ) addEventHandler("onElementDestroy", getRootElement(), function () if getElementType(source) == "vehicle" then if(p_lights[source] == 1) then killTimer(p_timer[source]) end end end) Link to comment
Smart. Posted April 16, 2012 Share Posted April 16, 2012 Tested and working perfectly.. local tVehicles = { [ 598 ] = true; [ 596 ] = true; [ 597 ] = true; [ 411 ] = true; [ 599 ] = true; } p_lights = {} p_timer = {} p_lvar = {} p_pvar = {} p_lvar2 = {} p_lvar3 = {} p_lvar4 = {} function toggleLights(thePlayer, cmd, level) local level = tonumber(level) if not(level) then outputChatBox("#FF0000 Please select a level![1-2]", thePlayer, 255, 255, 255, true) return end if(level < 1) or (level > 2) then outputChatBox("#FF0000 Please select a level between 1-2!", thePlayer, 255, 255, 255, true) return end local veh = getPedOccupiedVehicle(thePlayer) local id = getElementModel(veh) if ( tVehicles [ getPedOccupiedVehicle ( thePlayer ) ] ) then if(level == 1) then if(p_lights[veh] == 0) or(p_lights[veh] == nil) then p_pvar[veh] = 1 p_lights[veh] = 1 outputChatBox("#FFFFFFYour Police-lights has been #00FF00enabled.", thePlayer, 0, 200, 100, true) setVehicleOverrideLights ( veh, 2 ) p_timer[veh] = setTimer( function() if(p_lvar[veh] == 0) or (p_lvar[veh] == nil) then p_lvar[veh] = 1 setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 0, 1) setVehicleLightState ( veh, 3, 1) setVehicleHeadLightColor(veh, 0, 0, 255) else setVehicleLightState ( veh, 3, 0) setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 1) setVehicleLightState ( veh, 2, 1) setVehicleHeadLightColor(veh, 255, 0, 0) p_lvar[veh] = 0 end end, 500, 0) else p_lights[veh] = 0 outputChatBox("#FFFFFFYour Police-lights has been #00FF00disabled.", thePlayer, 0, 200, 100, true) killTimer(p_timer[veh]) setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 3, 0) setVehicleHeadLightColor(veh, 255, 255, 255) setVehicleOverrideLights ( veh, 1 ) end elseif(level == 2) then if(p_lights[veh] == 0) or(p_lights[veh] == nil) then p_lights[veh] = 1 outputChatBox("#FFFFFFYour Police-lights has been #00FF00enabled.", thePlayer, 0, 200, 100, true) setVehicleOverrideLights ( veh, 2 ) p_timer[veh] = setTimer( function() if(p_lvar3[veh] == 4) then setTimer(function() p_lvar3[veh] = 0 end, 1000, 1) setTimer( function() if(p_lvar4[veh] == 1)then p_lvar4[veh] = 0 -- 0 = vorne links 1 = vorne rechts 2 = hinten links 3 = hinten rechts setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 0, 1) setVehicleLightState ( veh, 3, 1) setVehicleHeadLightColor(veh, 77, 77, 255) else setVehicleLightState ( veh, 3, 0) setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 1) setVehicleLightState ( veh, 2, 1) setVehicleHeadLightColor(veh, 255, 77, 77) p_lvar4[veh] = 1 end end, 50, 5) return end if(p_lvar2[veh] == 0) or (p_lvar2[veh] == nil) then p_lvar2[veh] = 1 -- 0 = vorne links 1 = vorne rechts 2 = hinten links 3 = hinten rechts setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 0, 1) setVehicleLightState ( veh, 3, 1) setVehicleHeadLightColor(veh, 0, 0, 255) else setVehicleLightState ( veh, 3, 0) setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 1) setVehicleLightState ( veh, 2, 1) setVehicleHeadLightColor(veh, 255, 0, 0) p_lvar2[veh] = 0 end if(p_lvar3[veh] == nil) then p_lvar3[veh] = 0 end p_lvar3[veh] = (p_lvar3[veh]+1) end, 500, 0) else p_lights[veh] = 0 outputChatBox("#FFFFFFYour Police-lights has been #00FF00disabled.", thePlayer, 0, 200, 100, true) killTimer(p_timer[veh]) setVehicleLightState ( veh, 0, 0) setVehicleLightState ( veh, 1, 0) setVehicleLightState ( veh, 2, 0) setVehicleLightState ( veh, 3, 0) setVehicleHeadLightColor(veh, 255, 255, 255) setVehicleOverrideLights ( veh, 1 ) end end end end addCommandHandler("lights", toggleLights) addEventHandler ( "onVehicleExplode", getRootElement(), function() if(p_lights[source] == 1) then killTimer(p_timer[source]) end end ) addEventHandler ( "onVehicleRespawn", getRootElement(), function() if(p_lights[source] == 1) then killTimer(p_timer[source]) end end ) addEventHandler("onElementDestroy", getRootElement(), function () if getElementType(source) == "vehicle" then if(p_lights[source] == 1) then killTimer(p_timer[source]) end end end) Link to comment
Castillo Posted April 16, 2012 Share Posted April 16, 2012 local tVehicles = -- what draken was saying is, its alot easier to find and edit it now, the code looks more organized too. { [ 598 ] = true; [ 596 ] = true; [ 597 ] = true; [ 411 ] = true; [ 599 ] = true; } -- Simple Police-Lights by MuLTi! p_lights = {} p_timer = {} p_lvar = {} p_pvar = {} p_lvar2 = {} p_lvar3 = {} p_lvar4 = {} function toggleLights ( thePlayer, cmd, level ) local level = tonumber ( level ) if ( not level ) then outputChatBox ( "#FF0000 Please select a level![1-2]", thePlayer, 255, 255, 255, true ) return end if ( level < 1 ) or ( level > 2 ) then outputChatBox ( "#FF0000 Please select a level between 1-2!", thePlayer, 255, 255, 255, true ) return end local veh = getPedOccupiedVehicle ( thePlayer ) local id = getElementModel ( veh ) if ( tVehicles [ id ] ) then -- You we're using the vehicle element instead of the vehicle model. if ( level == 1 ) then if ( p_lights [ veh ] == 0) or ( p_lights [ veh ] == nil ) then p_pvar [ veh ] = 1 p_lights [ veh ] = 1 outputChatBox ( "#FFFFFFYour Police-lights has been #00FF00enabled.", thePlayer, 0, 200, 100, true ) setVehicleOverrideLights ( veh, 2 ) p_timer [ veh ] = setTimer ( function ( ) if ( p_lvar [ veh ] == 0) or ( p_lvar [ veh ] == nil ) then p_lvar [ veh ] = 1 setVehicleLightState ( veh, 1, 0 ) setVehicleLightState ( veh, 2, 0 ) setVehicleLightState ( veh, 0, 1 ) setVehicleLightState ( veh, 3, 1 ) setVehicleHeadLightColor ( veh, 0, 0, 255 ) else setVehicleLightState ( veh, 3, 0 ) setVehicleLightState ( veh, 0, 0 ) setVehicleLightState ( veh, 1, 1 ) setVehicleLightState ( veh, 2, 1 ) setVehicleHeadLightColor ( veh, 255, 0, 0 ) p_lvar [ veh ] = 0 end end , 500, 0 ) else p_lights [ veh ] = 0 outputChatBox ( "#FFFFFFYour Police-lights has been #00FF00disabled.", thePlayer, 0, 200, 100, true ) if ( isTimer ( p_timer [ veh ] ) ) then killTimer ( p_timer [ veh ] ) end setVehicleLightState ( veh, 0, 0 ) setVehicleLightState ( veh, 1, 0 ) setVehicleLightState ( veh, 2, 0 ) setVehicleLightState ( veh, 3, 0 ) setVehicleHeadLightColor ( veh, 255, 255, 255 ) setVehicleOverrideLights ( veh, 1 ) end elseif ( level == 2 ) then if ( p_lights [ veh ] == 0) or ( p_lights [ veh ] == nil ) then p_lights [ veh ] = 1 outputChatBox ( "#FFFFFFYour Police-lights has been #00FF00enabled.", thePlayer, 0, 200, 100, true ) setVehicleOverrideLights ( veh, 2 ) p_timer [ veh ] = setTimer ( function ( ) if ( p_lvar3 [ veh ] == 4 ) then setTimer ( function ( ) p_lvar3 [ veh ] = 0 end ,1000, 1 ) setTimer ( function ( ) if ( p_lvar4 [ veh ] == 1 ) then p_lvar4 [ veh ] = 0 -- 0 = vorne links 1 = vorne rechts 2 = hinten links 3 = hinten rechts setVehicleLightState ( veh, 1, 0 ) setVehicleLightState ( veh, 2, 0 ) setVehicleLightState ( veh, 0, 1 ) setVehicleLightState ( veh, 3, 1 ) setVehicleHeadLightColor ( veh, 77, 77, 255 ) else setVehicleLightState ( veh, 3, 0 ) setVehicleLightState ( veh, 0, 0 ) setVehicleLightState ( veh, 1, 1 ) setVehicleLightState ( veh, 2, 1 ) setVehicleHeadLightColor ( veh, 255, 77, 77 ) p_lvar4 [ veh ] = 1 end end ,50, 5 ) return end if ( p_lvar2 [ veh ] == 0) or ( p_lvar2 [ veh ] == nil ) then p_lvar2 [ veh ] = 1 -- 0 = vorne links 1 = vorne rechts 2 = hinten links 3 = hinten rechts setVehicleLightState ( veh, 1, 0 ) setVehicleLightState ( veh, 2, 0 ) setVehicleLightState ( veh, 0, 1 ) setVehicleLightState ( veh, 3, 1 ) setVehicleHeadLightColor ( veh, 0, 0, 255 ) else setVehicleLightState ( veh, 3, 0 ) setVehicleLightState ( veh, 0, 0 ) setVehicleLightState ( veh, 1, 1 ) setVehicleLightState ( veh, 2, 1 ) setVehicleHeadLightColor ( veh, 255, 0, 0 ) p_lvar2 [ veh ] = 0 end if ( p_lvar3 [ veh ] == nil ) then p_lvar3 [ veh ] = 0 end p_lvar3 [ veh ] = ( p_lvar3 [ veh ]+1 ) end ,500, 0 ) else p_lights [ veh ] = 0 outputChatBox ( "#FFFFFFYour Police-lights has been #00FF00disabled.", thePlayer, 0, 200, 100, true ) if ( isTimer ( p_timer [ veh ] ) ) then killTimer ( p_timer [ veh ] ) end setVehicleLightState ( veh, 0, 0 ) setVehicleLightState ( veh, 1, 0 ) setVehicleLightState ( veh, 2, 0 ) setVehicleLightState ( veh, 3, 0 ) setVehicleHeadLightColor ( veh, 255, 255, 255 ) setVehicleOverrideLights ( veh, 1 ) end end end end addCommandHandler ( "lights", toggleLights ) addEventHandler ( "onVehicleExplode", getRootElement(), function ( ) if ( p_lights [ source ] == 1 ) then if ( isTimer ( p_timer [ source ] ) ) then killTimer ( p_timer [ source ] ) end end end ) addEventHandler ( "onVehicleRespawn", getRootElement(), function ( ) if ( p_lights [ source ] == 1 ) then if ( isTimer ( p_timer [ source ] ) ) then killTimer ( p_timer [ source ] ) end end end ) addEventHandler ( "onElementDestroy", getRootElement(), function ( ) if ( getElementType ( source ) == "vehicle" ) then if ( p_lights [ source ] == 1 ) then if ( isTimer ( p_timer [ source ] ) ) then killTimer ( p_timer [ source ] ) end end end end ) Link to comment
meh Posted April 16, 2012 Author Share Posted April 16, 2012 thanx a million guys, now everything works just great. and i've 1 more question. this one is my last(i hope). is it possible to make the command /lights 1 last for the whole session, and not for 1 round only? because as for now, a player has to type /lights 1 each round and it's kind of uncomfortable imo. Link to comment
Castillo Posted April 16, 2012 Share Posted April 16, 2012 Do you mean on "race" game mode? Link to comment
meh Posted April 16, 2012 Author Share Posted April 16, 2012 Do you mean on "race" game mode? shit, i always forget to mention that i mean race mode ! yes, you're totally right, Solidsnake. 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