Dzsozi (h03) Posted October 13, 2017 Share Posted October 13, 2017 (edited) Hello! The title almost explains everything I want to do. I can't get my script working, I would like to freeze/get a specific time whenever a vehicle stops, and when it starts again continue counting back from that time. Something like storing the "time" whenever a vehicle stops and when it starts moving again start from where it stopped. Here's my partial function: if isVehicleOnGround(vehicle) then if getVehicleSpeed(vehicle) >= 10 then currentTime = -- return from the stored time/tick count, how can I do that?!?!? if currentTime - lastTimeAdded[vehicle] >= 5000 then if someVariable < #someTable then someVariable = someVariable+1 lastTimeAdded[vehicle] = getTickCount() else someVariable = #someTable end end else -- how can i store and freeze currentTime variable? it is a getTickCount(), how can I store and then return it above????? end end This is a kind of timer, since I am using onClientRender I thought that this would be the most efficient, also, setTimer functions look ugly to me so I didn't even try them. Is there any other way to do this inside an onClientRender function? I am cracking my head over this since like 2 days but can't get the result I want. How can I do that? Here's an example: Let's say I go forward with the vehicle and the currentTime variable starts counting from 0, when the counter is at 2500 (milliseconds) I stop with the vehicle. I want the timer to stay 2500 and then when I move again start the timer from 2500 until it reaches 5000. Hope you understand my problem! Thank you for your reply in advance! Edited October 13, 2017 by Dzsozi (h03) Link to comment
Moderators IIYAMA Posted October 13, 2017 Moderators Share Posted October 13, 2017 local lastCheckTime -- function () -- ... if isVehicleOnGround(vehicle) then if getVehicleSpeed(vehicle) >= 10 then currentTime = lastCheckTime or getTickCount()-- if lastCheckTime is nil, then use the current tickCount if currentTime - lastTimeAdded[vehicle] >= 5000 then if someVariable < #someTable then someVariable = someVariable+1 lastTimeAdded[vehicle] = getTickCount() else someVariable = #someTable end end else lastCheckTime = getTickCount() end end -- ... -- end function Link to comment
Dzsozi (h03) Posted October 13, 2017 Author Share Posted October 13, 2017 33 minutes ago, IIYAMA said: local lastCheckTime -- function () -- ... if isVehicleOnGround(vehicle) then if getVehicleSpeed(vehicle) >= 10 then currentTime = lastCheckTime or getTickCount()-- if lastCheckTime is nil, then use the current tickCount if currentTime - lastTimeAdded[vehicle] >= 5000 then if someVariable < #someTable then someVariable = someVariable+1 lastTimeAdded[vehicle] = getTickCount() else someVariable = #someTable end end else lastCheckTime = getTickCount() end end -- ... -- end function This does not function the way I would like it to be. Link to comment
Moderators IIYAMA Posted October 13, 2017 Moderators Share Posted October 13, 2017 Ehm, OK... 1 Link to comment
Moderators IIYAMA Posted October 13, 2017 Moderators Share Posted October 13, 2017 -- clear those once you stop the timer it. local lastCheckTime local newStartTime -- -- function () -- ... if isVehicleOnGround(vehicle) then if getVehicleSpeed(vehicle) >= 10 then local currentTime if lastCheckTime then currentTime = lastCheckTime if not newStartTime then newStartTime = getTickCount() else currentTime = currentTime + (getTickCount() - newStartTime) end else currentTime = getTickCount() end if currentTime - lastTimeAdded[vehicle] >= 5000 then if someVariable < #someTable then someVariable = someVariable+1 lastTimeAdded[vehicle] = getTickCount() else someVariable = #someTable end end else lastCheckTime = getTickCount() end end -- ... -- end function Link to comment
Dzsozi (h03) Posted October 13, 2017 Author Share Posted October 13, 2017 Thank you for your reply, but this doesn't work as well. I tried using outputChatBox to see the tick count, and I get a wrong tick number and also, the process doesn't start from the tick where it was paused. Is there any other way to make something similar? Or is there any solution for this one? Link to comment
Moderators IIYAMA Posted October 13, 2017 Moderators Share Posted October 13, 2017 Another method: You could save at the moment of pause all remaining time. When you restart it, you could set the tickCount again for the future. Link to comment
Dzsozi (h03) Posted October 13, 2017 Author Share Posted October 13, 2017 I found a solution by myself, but thank you for your time, I appreciate it! Since I am using onClientRender event I could make my own "timer"/progress thing. I don't know how it doesn't came into my mind faster, it works perfectly. Link to comment
Moderators IIYAMA Posted October 13, 2017 Moderators Share Posted October 13, 2017 P.s there is also onClientPreRender which has a timeslice parameter. Link to comment
Dzsozi (h03) Posted October 13, 2017 Author Share Posted October 13, 2017 This might be useful, I will play around with it, thank you for mentioning! 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