DakiLLa Posted August 13, 2008 Share Posted August 13, 2008 (edited) Hi there! I want to make a flashing ligts on vehicles when toggled L, and when L toggled again, stop flashing. But I dont understand what i need to do. I think, it should be a timer for function of toggle lights or not ? Script from vehicleligts resource ... function toggleVehicleLights ( player, key, state ) if ( getPlayerOccupiedVehicleSeat ( player ) == 0 ) then local veh = getPlayerOccupiedVehicle ( player ) if ( getVehicleOverrideLights ( veh ) ~= 2 ) then setVehicleOverrideLights ( veh, 2 ) else setVehicleOverrideLights ( veh, 1 ) end end end It will be effectly for cop-cars, like in Most Wanted. Thank's for replies Edited August 14, 2008 by Guest Link to comment
[UVA]Bart Posted August 13, 2008 Share Posted August 13, 2008 use a timer for when the player presses "l" it then calles the timer function which then tells the lights to flash Link to comment
haybail Posted August 14, 2008 Share Posted August 14, 2008 and an if to kill the timer if its already running, on i. but make it client side, so if the player quits and the timers still running... it won't be a problem. Link to comment
DakiLLa Posted August 14, 2008 Author Share Posted August 14, 2008 ok, but in what function i need to create timer, for what ? for setVehicleOverrideLights or for other ? I cant understand what i need to do. Link to comment
=FAS=Shigawire Posted August 14, 2008 Share Posted August 14, 2008 When i use a timer to update a text (e.g. Health) i let him write the information, then i let him clear all and ket him write again. Then i set this function into a timer (e.g. to 50ms ) Then he updates the Health each 50 ms But i dont know if that works with your project. Updating a function without clearing the event before .. lol. When i did that, my MTA used 2 GB RAM after10 seconds of playing Link to comment
Gamesnert Posted August 14, 2008 Share Posted August 14, 2008 When i use a timer to update a text (e.g. Health) i let him write the information, then i let him clear all and ket him write again. Then i set this function into a timer (e.g. to 50ms )Then he updates the Health each 50 ms But i dont know if that works with your project. Updating a function without clearing the event before .. lol. When i did that, my MTA used 2 GB RAM after10 seconds of playing 50 ms repeadetly? 1000:50=20 times/second. If your script then is approx 5 lines each time (example) then your PC will lag! I think like 100ms is even too fast! Although when you set it higher, players will tell it lag. So what? Do they want the GUI, or their PC to lag? Link to comment
=FAS=Shigawire Posted August 14, 2008 Share Posted August 14, 2008 lol that was only an example I let him my Health update 400 ms But ATM my FPS is going down by 10 because i have a Weapon Script that contains 200 lines ^^ and it has to be updated with 150 ms ^^ So my only chance to get up my FPS, is making less lines (possible but very much work) or less iterations Link to comment
Gamesnert Posted August 14, 2008 Share Posted August 14, 2008 How did you get your weapon script so large? And it loops every 150 ms? NOT GOOD... Link to comment
Mr.Hankey Posted August 14, 2008 Share Posted August 14, 2008 what about a clientside script using the onClientRender event like this? function set () if flashing == false or not flashing then flashing == true else flashing == false end end addCommandHandler ("setflash", set) function flash () if flashing == true then if getTickCount () - previousTickCount >= 250 or not previousTickCount then previousTickCount = getTickCount () if ( getVehicleOverrideLights ( playerVehicle ) ~= 2 ) then setVehicleOverrideLights ( playerVehicle, 2 ) else setVehicleOverrideLights ( playerVehicle, 1 ) end end end end addEventHandler ("onClientRender", getLocalPlayer(), flash) i could not test the script yet so there might be typing mistakes and i hope turning on/off the light 4 times per second is fast enough Link to comment
=FAS=Shigawire Posted August 14, 2008 Share Posted August 14, 2008 rofl, thats nearly not visible @nerd: lol, now the script ahs got less lines, BUT even though i disabled the setTimer: when the script is turned on, the FPS still decreases by 10 (or its more, 20 i think ) Link to comment
Gamesnert Posted August 14, 2008 Share Posted August 14, 2008 what about a clientside script using the onClientRender event like this? function set () if flashing == false or not flashing then flashing == true else flashing == false end end addCommandHandler ("setflash", set) function flash () if flashing == true then if getTickCount () - previousTickCount >= 250 or not previousTickCount then previousTickCount = getTickCount () if ( getVehicleOverrideLights ( playerVehicle ) ~= 2 ) then setVehicleOverrideLights ( playerVehicle, 2 ) else setVehicleOverrideLights ( playerVehicle, 1 ) end end end end addEventHandler ("onClientRender", getLocalPlayer(), flash) i could not test the script yet so there might be typing mistakes and i hope turning on/off the light 4 times per second is fast enough I LOLed @ line 2: "if flashing == false or not flashing then". Or not flashing... Anyway, onClientRender is executed every frame, right? If so, you might want to set something like a var that counts how many times it had been executed. Or does getTickCount serve for that? =/ And note that this doesn't seem to be synched... I think others want to see these flashing headlights too. @Shigawire: Still, is that a piece of code to check their ammo etc?!? That's just way too big! Also, try out some of the events I gave you once! Might decrease it's amount of lines to... Dunno... Alot less? Link to comment
=FAS=Shigawire Posted August 14, 2008 Share Posted August 14, 2008 rofl, sry im spamming the wrong thread with my questions But damn, you are right, the problem is the weapon code... so i will try the function you gave me Link to comment
tma Posted August 14, 2008 Share Posted August 14, 2008 Based on Mr. Hankey's code: addCommandHandler("setflash", function() flashing = not flashing end ) addEventHandler("onClientRender",getLocalPlayer(), function() local v = getPlayerOccupiedVehicle(getLocalPlayer()) if v and flashing and getTickCount () > (previousTickCount or 0) then previousTickCount = getTickCount() + 250 setVehicleOverrideLights(v,(getVehicleOverrideLights ( v ) == 2) and 1 or 2 ) end end ) Link to comment
haybail Posted August 14, 2008 Share Posted August 14, 2008 and / or: timing = { } -- make the variable a table function toggleFlashingLights ( thePlayer ) -- thePlayer who initiated the command if timing[thePlayer] then killTimer ( timing[thePlayer] ) timing[thePlayer] = nil -- remove the old variable else timing[thePlayer] = setTimer ( toggleVehicleLights, 250, 500, thePlayer ) -- set a timer every 250ms for 500 times, in case the timer overruns, for thePlayer end end addCommandHandler ( "flash", toggleFlashingLights ) function onPlayerQuit ( reason ) if timing[source] then -- if the timer is active when a player quits killTimer ( timing[source] ) timing[source] = nil end end addEventHandler ( "onPlayerQuit", getRootElement(), onPlayerQuit ) bindKey ( source, "I", "down", "toggleFlashingLights" ) -- assuming its onJoin u make a variable for each individual ( timing[thePlayer] ) so if someone kills their timer, it won't kill it for everyone. u need timing = { } so u can use timing[whateverulikeinhereincludingtextbuttextneedstobeinquations] otherwise u can only use timing = 0 or it will error. You may also like to do it for the vehicle, so if a player hops out it will continue flashing: function toggleFlashingLights ( thePlayer ) if getPlayerOccupiedVehicleSeat ( thePlayer ) == 0 then if vehicles[getPlayerOccupiedVehicle ( thePlayer )] then killTimer ( vehicles[getPlayerOccupiedVehicle ( thePlayer )] ) vehicles[getPlayerOccupiedVehicle ( thePlayer )] = nil else vehicles[getPlayerOccupiedVehicle ( thePlayer )] = setTimer ( toggleVehicleLights, 250, 0, getPlayerOccupiedVehicle ( thePlayer ) ) end end end addCommandHandler ( "flash", toggleFlashingLights ) function toggleVehicleLights ( car ) if ( getVehicleOverrideLights ( car ) ~= 2 ) then setVehicleOverrideLights ( car, 2 ) else setVehicleOverrideLights ( car, 1 ) end end vehicles = { } Link to comment
DakiLLa Posted August 15, 2008 Author Share Posted August 15, 2008 wow, it's really great, thanks guys, but if i want to use effect like this: https://www.youtube.com/watch?v=QyhZtajA ... re=related i think that it will be setVehicleLightState ? Link to comment
Gamesnert Posted August 15, 2008 Share Posted August 15, 2008 wow, it's really great, thanks guys, but if i want to use effect like this:https://www.youtube.com/watch?v=QyhZtajA ... re=related i think that it will be setVehicleLightState ? Lol! http://development.mtasa.com/index.php? ... LightState "A whole number determining the new state of the light. 0 represents normal lights, and 1 represents broken lights." I presume you want it to flash, not to be broken? Link to comment
Michael_Sund Posted August 15, 2008 Share Posted August 15, 2008 Not broken, broken, not broken, broken? instead of Blink, blink, blink? Link to comment
Gamesnert Posted August 15, 2008 Share Posted August 15, 2008 Lol it may work, but I think it might look a little weird. 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