❔ How to make a line of code run every x seconds?
I have this function:
This function repeats as fast as it can,
and i want to keep that but make one line run only once every x seconds.
This may sound weird but i think you will understand.
32 Replies
you need Timers
What is a timer?
How do i make it?
Can you give me an example code for this function?
are you using a specific gui/game framework?
Uhhh RagePluginHook
if you write Timer in the ide it should auto-suggest something
are you modding a game?
Yeah gta
ah
does gta allow mods in its ToS?
i forget
Porbably yes theres like milions of them
There are whole mod engines/frameworks for gta
U can create float variable out of this function and add deltaTime to it every time function is called. If variable's value is greater than 1, u set it to 0 and call your EverySecondMethod
yup it is for singleplayer and rp servers
Lemme try
this is not unity
deltaTime could be provided by framework, or u can create stopwatch out of this function and use it's ElapsedSeconds
It isn't provided
im not familiar with any modding libraries but generally id recommend using a PeriodicTimer
So create stopwatch somwhere near float variable. Add it's ElapsedSeconds to varialbe and call Restart every time
no need, use a periodic timer
its also async
RPH just provides functions for doing stuff with the game, no timing and stuff.
WTF is a periodic timer
PeriodicTimer.WaitForNextTickAsync(CancellationToken) Method (Syste...
Waits for the next tick of the timer, or for the timer to be stopped.
ill write an example when i get to my pc
Won't work i gotta use .net 4.8
ah
yeah i know but it isn't my decision, its just RPH stuff
use a regular timer then
or Task.Delay
maybe on a threadpool thread too
Ok, ty
np
But not in Process function
wait do you want the function to return?
yes
ok yeah then Task.Delay and Task.Run or a timers.timer
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.