I’m trying to learn C# (completely new to it), but how come resource usage is this high even when i have no loop or anything running that should cause this from what i understand, either way i’m really new, and i want to know the benefits of switching from LUA to C#, it seems to be a better developer experience but does it take more resource usage or is there something i’m missing?
Client Side:
using CitizenFX.Core.UI;
using System.Threading.Tasks;
using static CitizenFX.Core.Native.API;
namespace v_learning.Client
{
public class Client_Coroner
{
private static Vehicle cVanEntity;
private static int cVanBlip;
private static Ped cVanPed1;
private static Ped cVanPed2;
private static bool eventSpawned;
public async static void Summon()
{
Ped player_char = Game.Player.Character;
Screen.ShowNotification("Coroner is on it's way!", true);
Vector3 spawnLocation = new Vector3();
float spawnHeading = 0F;
int unusedVar = 0;
GetNthClosestVehicleNodeWithHeading(player_char.Position.X, player_char.Position.Y, player_char.Position.Z, 77, ref spawnLocation, ref spawnHeading, ref unusedVar, 9, 3.0F, 2.5F);
await LoadModel((uint)VehicleHash.Adder);
cVanEntity = await World.CreateVehicle(VehicleHash.Adder, spawnLocation, spawnHeading);
cVanEntity.Mods.PrimaryColor = VehicleColor.MetallicBlack;
cVanEntity.Mods.LicensePlate = "V";
cVanEntity.Mods.LicensePlateStyle = LicensePlateStyle.YellowOnBlack;
cVanBlip = AddBlipForEntity(cVanEntity.Handle);
SetBlipColour(cVanBlip, 40);
BeginTextCommandSetBlipName("STRING");
AddTextComponentString("Coroner");
EndTextCommandSetBlipName(cVanBlip);
await LoadModel((uint) PedHash.Doctor01SMM);
cVanPed1 = await World.CreatePed(PedHash.Doctor01SMM, spawnLocation, spawnHeading);
cVanPed1.SetIntoVehicle(cVanEntity, VehicleSeat.Driver);
cVanPed1.CanBeTargetted = false;
await LoadModel((uint)PedHash.Scientist01SMM);
cVanPed2 = await World.CreatePed(PedHash.Scientist01SMM, spawnLocation, spawnHeading);
cVanPed2.CanBeTargetted = false;
Vector3 targetLocation = new Vector3();
float targetHeading = 0F;
GetClosestVehicleNodeWithHeading(player_char.Position.X, player_char.Position.Y, player_char.Position.Z, ref targetLocation, ref targetHeading, 1, 3.0F, 0);
cVanPed1.Task.DriveTo(cVanEntity, targetLocation, 10F, 20F, 262972);
eventSpawned = true;
}
public static async Task<bool> LoadModel(uint model)
{
if (model == 0 || !IsModelInCdimage(model))
{
Debug.WriteLine("Invalid Model!");
return false;
}
RequestModel(model);
while (!HasModelLoaded(model))
{
Debug.WriteLine($"Loading model {model}");
await BaseScript.Delay(100);
}
return true;
}
}
}
Server Side:
using System.Threading.Tasks;
using CitizenFX.Core;
namespace v_learning.Server
{
public class ServerMain : BaseScript
{
public ServerMain()
{
Debug.WriteLine("Hi from v_learning.Server!");
}
[Command("hello_server")]
public void HelloServer()
{
Debug.WriteLine("Sure, hello.");
}
}
}