[C#] High Time %

Hey, in every C# Script i write the Time % is complained with a Lua Script extreme high, here for example the PlayerSpawner script in C#

the Code:

using CitizenFX.Core;
using static CitizenFX.Core.Native.API;
using System;
using System.Collections;

namespace PlayerSpawner.Client
{
    internal class Spawner : BaseScript
    {
        public Spawner()
        {
            EventHandlers["onClientResourceStart"] += new Action<string>(OnClientResourceStart);
        }

        private async void OnClientResourceStart(string resourceName)
        {
            if (resourceName != GetCurrentResourceName())
            {
                return;
            }

            Player player = Game.Player;
            Model model = PedHash.FilmNoir;

            if (!model.IsValid)
            {
                return;
            }

            model.Request();
            while (!model.IsLoaded)
            {
                await Delay(1);
            }

            await player.ChangeModel(model);

            model.MarkAsNoLongerNeeded();

            player.Character.Position = new Vector3(126.975f, 3714.419f, 46.827f);
            player.Character.IsPositionFrozen = false;

            ShutdownLoadingScreen();
            ShutdownLoadingScreenNui();
        }
    }
}

Cfx is working on an updated mono runtime, so if the overhead of the current runtime is that much of an issue then swapping is an option. It was just recently enabled with feat(scripting-mono): enable mono v2 runtime · citizenfx/fivem@37986b0 · GitHub.

1 Like

Like Linden mentioned the C# performance issues are solved in the v2 runtime, feel free to try it.

Time % will however depend on the resource’s CPU msec relative to the [Total CPU], so this value is only interesting for finding the biggest CPU hogging resource.

2 Likes

Coul you explain a little more how to use & install this, I have read the whole github, but dont understand it

Follow the setup mono_v2_get_started/Setup.md at main · thorium-cfx/mono_v2_get_started · GitHub

Most is the same as the v1 runtime, but in v2 you need to use the new assemblies (from v2/ directory) and supply the CitizenFX.<Game>.Native.dll with your resource.