Node.js setTick problem

Hello!

I’m trying to create client side scripting based on js, but i found a problem of the tick system. Basically if i’m using setTick method it will not run on every frame. I started to debugging the problem and i saw 30-50 frame ( based on the Citizen.getTickCount() ) skipping each setTick callback. This could be a problem if you want to call a native function each tick (like disable traffic related functions).

1 Like

Huh? This function returns milliseconds, not ‘frames’ (and it should not exist, probably a leftover from an early scheduling iteration, since now GetGameTimer exists).

Do you have a repro of whatever not running every frame?

Sure! This is a lua code piece which is running every tick and turning off all of the traffic.

Citizen.CreateThread(function()
    local playerPed = GetPlayerPed(-1);
    while true do
        SetPoliceIgnorePlayer(playerPed, true);
        SetMaxWantedLevel(0);
        ClearPlayerWantedLevel(playerPed);
        SetEveryoneIgnorePlayer(playerPed, true);
        SetPlayerCanBeHassledByGangs(playerPed, false);
        SetIgnoreLowPriorityShockingEvents(playerPed, true);
        SetCreateRandomCopsNotOnScenarios(false);
        SetCreateRandomCops(false);
        SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0);
        SetPedDensityMultiplierThisFrame(0.0);
        SetVehicleDensityMultiplierThisFrame(0.0);
        SetAmbientVehicleRangeMultiplierThisFrame(0.0);
        SetRandomVehicleDensityMultiplierThisFrame(0.0);
        SetParkedVehicleDensityMultiplierThisFrame(0.0);
        SetVehicleDensityMultiplierThisFrame(0.0);
        SetPedDensityMultiplierThisFrame(0.0);
        SetRandomVehicleDensityMultiplierThisFrame(0.0);
        SetParkedVehicleDensityMultiplierThisFrame(0.0);
        SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0);
        Wait(0)
    end
end)

If i want to run the same code in javascript

const playerPed = GetPlayerPed(-1);

setTick(() => {
  SetPoliceIgnorePlayer(playerPed, true);
  SetMaxWantedLevel(0);
  ClearPlayerWantedLevel(playerPed);
  SetEveryoneIgnorePlayer(playerPed, true);
  SetPlayerCanBeHassledByGangs(playerPed, false);
  SetIgnoreLowPriorityShockingEvents(playerPed, true);
  SetCreateRandomCopsNotOnScenarios(false);
  SetCreateRandomCops(false);
  SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0);
  SetPedDensityMultiplierThisFrame(0.0);
  SetVehicleDensityMultiplierThisFrame(0.0);
  SetAmbientVehicleRangeMultiplierThisFrame(0.0);
  SetRandomVehicleDensityMultiplierThisFrame(0.0);
  SetParkedVehicleDensityMultiplierThisFrame(0.0);
  SetVehicleDensityMultiplierThisFrame(0.0);
  SetPedDensityMultiplierThisFrame(0.0);
  SetRandomVehicleDensityMultiplierThisFrame(0.0);
  SetParkedVehicleDensityMultiplierThisFrame(0.0);
  SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0);
});

The javascript method don’t disable fully the traffic. The traffic is reduced but not fully disabled. The best example for this are using SetAmbientVehicleRangeMultiplierThisFrame(0.0); which creates ghost cars ( cars popping out and disappearing in a second ).
I try to do a workaround by creating a simple event trigger in lua which is running on that loop and just triggering the javascript code piece but the result was the same.

1 Like

I confirm the bug, I have the same problem. Anyone has an idea for fixing this bug?
I don’t think it’s due to setTick, the following code result in the same bug :

client.lua

Citizen.CreateThread(function()
    while true do
        TriggerEvent("test")
        Wait(0)
    end
end)

client.js

on('test', (playerPed) => {
    SetPoliceIgnorePlayer(playerPed, true);
    SetMaxWantedLevel(0);
    ClearPlayerWantedLevel(playerPed);
    SetEveryoneIgnorePlayer(playerPed, true);
    SetPlayerCanBeHassledByGangs(playerPed, false);
    SetIgnoreLowPriorityShockingEvents(playerPed, true);
    SetCreateRandomCopsNotOnScenarios(false);
    SetCreateRandomCops(false);
    SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0);
    SetPedDensityMultiplierThisFrame(0.0);
    SetVehicleDensityMultiplierThisFrame(0.0);
    SetAmbientVehicleRangeMultiplierThisFrame(0.0);
    SetRandomVehicleDensityMultiplierThisFrame(0.0);
    SetParkedVehicleDensityMultiplierThisFrame(0.0);
    SetVehicleDensityMultiplierThisFrame(0.0);
    SetPedDensityMultiplierThisFrame(0.0);
    SetRandomVehicleDensityMultiplierThisFrame(0.0);
    SetParkedVehicleDensityMultiplierThisFrame(0.0);
    SetScenarioPedDensityMultiplierThisFrame(0.0, 0.0);
});

Hey, this thread can be closed, as I thought the bug isn’t from the JS wrapper loop, but from the JS wrapper float arguments.

Check out this thread to follow the issue : JavaScript float natives arguments bug

1 Like