GetTickCount (Not the same as GetGameTimer)

Hello, I wanted to request a native called GetTickCount, which returns the current Tick. I’m aware of the native GetGameTimer; the reason I’m asking for the native is that GetGameTimer isn’t accurate - GetGameTimer is influenced by SetTimeScale, and whether the game is minimized or not.
I would like to have it client-sided native, and in milliseconds or faster.
Thanks for reading this.

1 Like

…? why

I made some scripts which uses objects and calculate it’s position with the time passed between the last frame and the new frame (synced with all players). And when someone gone AFK, he sees the object behind everyone else, and it makes him desynced.
Also I use SetTimeScale native, and all the Wait stuff getting broken because the coroutine function also uses GetGameTimer, which is influenced by SetTimeScale and don’t resume the coroutine(my CreateThread) in time.

Timestep might satisfy your need.

Then use GET_NETWORK_TIME if you want the same timestamp on ‘all players’?

Then why FiveM using GetGameTimer instead of GetNetworkTime if they know GetGameTimer has negative sides? (in citizen/scripting/lua/scheduler.lua)

Because this needs to work for non-network games too, nor does it need to be synced for all players?

It doesn’t need to be synced, but in online mode, it needs to run fairly to all players (whether because SetTimeScale or just being AFK), so none of the timers get influenced. In offline mode, it doesn’t matter because it doesn’t ruin any timer. (Which offline mode allows you to be AFK, pause the game, and if you use SetTimeScale EVERYTHING really goes slower and not just your character like in online mode.)

Solution:
Looks like the best decision for offline is: GetGameTimer. and for online is: GetNetworkTime.

Can’t FiveM just check whether its online or offline mode and choose the correct native to the current mode?

Edit:
A native I found to check whether you should use GetGameTimer or GetNetworkTime - HasNetworkTimeStarted (this native is even being called by R* scripts)

For those who are using C#, this is already possible:

ulong tickCount = 0;

public ClassName()
{
    EventHandlers["onClientResourceStart"] += new Action<string>(OnClientResourceStart);
}

private void OnClientResourceStart(string resName)
{
    if (GetCurrentResourceName() != resName)
        return;

    Tick += OnTick;
}

private async Task OnTick()
{
    tickCount++; // will contain the exact number of ticks since the resource start
}

Though, I tried to use it to detect Cheat Engine’s speedhack feature, after reading some comment saying that enabling the CE speedhacks increased the ticks per second, however it actually doesn’t, so don’t try to use it for that reason.