Guys , anyone that tries to script with c# please join me on discord https://discord.gg/Jzw7GU5 i will help with whatever i’ll find and i will expect same from you.Please join , this will be faster.Because everyone is coding in Lua so it’s hard to find c# scripters , please join.
Oh nice, (nearly) the last missing Server events. I will check this out now. Thank you so much.
For your crashing client script you can use:
private void OnPlayerSpawned([FromSource]Vector3 pos)
{
Vector3 whateveryouneeditfor = LocalPlayer.Character.Position;
There comes no position with this event, so “pos” is null and thats the cause of the crash.
Mrm I tested your code, but all these baseevents do not response.
I do not understand what is wrong.
Add baseevents rescource in serve.cfg
You need to start the “baseevents” resource
After some testing i found that Vehicle events doesn’t return seat properly.
Kerosini provided client script still crashes.
OnPlayerDied doesn’t respond nor gives any error.
What I told is wrong… the pos parameter is not null, but its not filled. But a crash is not happend to me.
this code
private void OnPlayerSpawned([FromSource]Vector3 pos)
{
if (pos == null)
Debug.WriteLine("Yes it is NULL");
else
{
Debug.WriteLine("Oh it works, players pos is: " + pos.ToString()); //<---
}
Debug.WriteLine("try to acces localplayers pos...");
try
{
Debug.WriteLine("it is: " + LocalPlayer.Character.Position.ToString()); //<---
}
catch
{
Debug.WriteLine("Oh it crashed :(");
}
creates this output:
Maybe it causes a crash after I add the baseevents to my cfg thanks for that hint I will try it now.
YEAH GOOD NEWS
After adding to start these baseevents into the server config I got all events
And I got onPlayerDied two
It is also a baseevent aand it comes with the following parameters
//in constructor
EventHandlers.Add("baseevents:onPlayerDied", new Action<Player, string>(OnPlayerDied));
private void OnPlayerDied([FromSource]Player player, string deathReason)
{
Debug.WriteLine("OnPlayerDied! " + player.Name + " reason = " + deathReason );
}
Now everthing is possible
Ohhhhhhhhhhh ! Very nice bro ! Ty !
Can someone explain how NativeUI or NUI with C# works?
Thanks! c:
Thank you… c:
#morethan20characters
Hi fellow C# developpers !
Anyone has a piece of idea about my problem posted here : [C#] TriggerClientEvent
Thanks in advance !
Hello Guys,
i’am trying to iterate through an object in c# which i got from an Event in LUA.
some code:
LUA Code
RegisterNetEvent('esx_dmvschool:loadLicenses')
AddEventHandler('esx_dmvschool:loadLicenses', function(licenses)
Licenses = licenses
end)
Client Side C#
public NoLicenseDrivingClient()
{
EventHandlers.Add("esx_dmvschool:loadLicenses", new Action<dynamic>(LoadLicenses));
Tick += OnTick;
}
private void LoadLicenses(dynamic obj)
{
Licenses = obj;
if(Licenses == null)
{
Debug.WriteLine("Licenses == null");
}
else
{
Debug.WriteLine("Not Null");
Debug.Write("Size : " + Licenses.Count);
foreach(Object o in Licenses)
{
Debug.WriteLine(o);
}
}
}
Maybe someone can help me.
A couple of commands
// Give player a pistol
RegisterCommand("pistol", new Action<int, List<object>, string>((source, args, raw) =>
{
LocalPlayer.Character.Weapons.Give(WeaponHash.Pistol, 0, false, false);
}), false);
// Give pistol ammo only if player has a pistol
RegisterCommand("ammo", new Action<int, List<object>, string>((source, args, raw) =>
{
if (LocalPlayer.Character.Weapons.HasWeapon(WeaponHash.Pistol))
{
GiveWeaponToPed(GetPlayerPed(-1), (uint)WeaponHash.Pistol, 12, false, false);
}
}), false);
This class will sync game time with the system clock on the client side.
public class SyncTime : BaseScript
{
private byte hour;
private byte minute;
private Thread clock;
public SyncTime()
{
this.hour = 0;
this.minute = 0;
clock = new Thread(new ThreadStart(ClockTick));
clock.Start();
Tick += OnSlowTick;
}
private async Task OnSlowTick()
{
await Delay(0);
NetworkOverrideClockTime(this.hour, this.minute, 0);
}
private void ClockTick()
{
while (true)
{
Thread.Sleep(1000);
this.hour = (byte)System.DateTime.Now.Hour;
this.minute = (byte)System.DateTime.Now.Minute;
}
}
}
Forget about that crap, I just learned how to deal with Tasks, this should do the trick way better:
public class Realtime : BaseScript
{
private const int MILISECONDS_FOR_GAME_MINUTE = 60000;
private const int GTAV_CLOCK_TICK = 2000;
private bool serverSync;
private byte hour;
private byte minute;
private int mark;
public Realtime()
{
SetServerSync(false); // TODO: Get from config
Sync();
mark = GetGameTimer();
Tick += Update;
}
private async Task Update()
{
await Delay(GTAV_CLOCK_TICK);
if (GetGameTimer() - mark >= MILISECONDS_FOR_GAME_MINUTE)
{
minute++;
mark = GetGameTimer();
if (minute >= 60)
{
minute = 0;
hour++;
if (hour >= 24)
{
hour = 0;
}
}
}
NetworkOverrideClockTime(hour, minute, 0);
}
private void Sync()
{
if (serverSync)
{
// TODO: Sync with server
}
else
{
hour = (byte)System.DateTime.Now.Hour;
minute = (byte)System.DateTime.Now.Minute;
}
}
public void SetServerSync(bool set)
{
serverSync = set;
Sync();
}
}
Some constant to have in hand while managing weather
public const string CLEAR = "CLEAR";
public const string EXTRASUNNY = "EXTRASUNNY";
public const string CLOUDS = "CLOUDS";
public const string OVERCAST = "OVERCAST";
public const string RAIN = "RAIN";
public const string CLEARING = "CLEARING";
public const string THUNDER = "THUNDER";
public const string SMOG = "SMOG";
public const string FOGGY = "FOGGY";
public const string XMAS = "XMAS";
public const string SNOWLIGHT = "SNOWLIGHT";
public const string BLIZZARD = "BLIZZARD";
Does anyone have a code snippet about drawing text? Can’t seem to figure it out.
Not sure if you mean simple Text like that
Text text = new Text(“Text you want to display.”, new PointF(posx , posY) , 0.3F);
text.Draw();
Simple text. I can’t seem to figure it out