So i have recently started coding in c# but i don’t really get what this does
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CitizenFX.Core;
using CitizenFX.Core.UI;
using CitizenFX.Core.Native;
namespace testing.Client
{
public class ClientScript : BaseScript
{
public ClientScript()
{
Tick += OnTick;
}
private async Task OnTick()
{
}
}
}
And how is the Tick used? can it be used on the client and on the server side?
I have been coding much on Lua, and does it work as a thread?
You should only use a Tick if you want to do something every tick, like checking whether the player is a certain distance away or drawing a marker on the ground. It’s the same as in Lua where you’d put stuff in a while true loop.
You can have a class without any tick and just have events, which would be .
EventHandlers.Add("someName", new Action<string>(OnSomeName)); // in the constructor
private void OnSomeName(string myName)
{
Debug.WriteLine(name);
}
Tick is a standard .NET event which is an implementation of the observer pattern.
protected event Func<Task> Tick
You subscribe handlers to the trigger of the event. The observer pattern allows subscription of multiple Observers to a Publisher. So Tick is the Publisher in this case and you can subscribe as many Observers as you like (event handlers).
When the events triggers (Publishes) each subscribed observer is called in an undetermined order asynchronously, so a thread is created for each at the time it triggers. Really efficient compared with the Lua counterpart.
Dear experts? For me, using Tick causes the program to slow down. What are the more Ticks that are associated with drawing markers? by calculating the distance, etc., the stronger the brakes. My main program rolls over in 2 ms! At the same time, a similar amount on the lua does not cause any problems. What’s the catch for Tutu?