C
C#7mo ago
xTagz_

❔ How to make a line of code run every x seconds?

I have this function:
public override void Process()
{
Suspect.Tasks.PlayAnimation("amb@world_human_aa_smoke@male@idle_a", "idle_a", 1, AnimationFlags.None); //Line that i want to be run every x seconds
Thread.Sleep(1000);
if (STPFunctions.isPedStopped(Suspect))
{
End();
}
base.Process();
}
public override void Process()
{
Suspect.Tasks.PlayAnimation("amb@world_human_aa_smoke@male@idle_a", "idle_a", 1, AnimationFlags.None); //Line that i want to be run every x seconds
Thread.Sleep(1000);
if (STPFunctions.isPedStopped(Suspect))
{
End();
}
base.Process();
}
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
WEIRD FLEX
WEIRD FLEX7mo ago
you need Timers
xTagz_
xTagz_7mo ago
What is a timer? How do i make it? Can you give me an example code for this function?
sibber
sibber7mo ago
are you using a specific gui/game framework?
xTagz_
xTagz_7mo ago
Uhhh RagePluginHook
WEIRD FLEX
WEIRD FLEX7mo ago
if you write Timer in the ide it should auto-suggest something
sibber
sibber7mo ago
are you modding a game?
xTagz_
xTagz_7mo ago
Yeah gta
sibber
sibber7mo ago
ah does gta allow mods in its ToS? i forget
xTagz_
xTagz_7mo ago
Porbably yes theres like milions of them There are whole mod engines/frameworks for gta
RumTery
RumTery7mo ago
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
sibber
sibber7mo ago
yup it is for singleplayer and rp servers
xTagz_
xTagz_7mo ago
Lemme try
sibber
sibber7mo ago
this is not unity
RumTery
RumTery7mo ago
deltaTime could be provided by framework, or u can create stopwatch out of this function and use it's ElapsedSeconds
xTagz_
xTagz_7mo ago
It isn't provided
sibber
sibber7mo ago
im not familiar with any modding libraries but generally id recommend using a PeriodicTimer
RumTery
RumTery7mo ago
So create stopwatch somwhere near float variable. Add it's ElapsedSeconds to varialbe and call Restart every time
sibber
sibber7mo ago
no need, use a periodic timer its also async
xTagz_
xTagz_7mo ago
RPH just provides functions for doing stuff with the game, no timing and stuff. WTF is a periodic timer
sibber
sibber7mo ago
ill write an example when i get to my pc
xTagz_
xTagz_7mo ago
Won't work i gotta use .net 4.8
sibber
sibber7mo ago
ah
xTagz_
xTagz_7mo ago
yeah i know but it isn't my decision, its just RPH stuff
sibber
sibber7mo ago
use a regular timer then or Task.Delay maybe on a threadpool thread too
xTagz_
xTagz_7mo ago
Ok, ty
sibber
sibber7mo ago
np
RumTery
RumTery7mo ago
But not in Process function
sibber
sibber7mo ago
wait do you want the function to return?
xTagz_
xTagz_7mo ago
yes
sibber
sibber7mo ago
ok yeah then Task.Delay and Task.Run or a timers.timer
Accord
Accord7mo ago
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.