FXServer EventHandler

Hey there!
I have on FXServer two problems with the event handlers (C#).

  1. Getting the caller
  2. Cancel the event

Is there an equivalent to ‘CancelEvent()’ and ‘source’ in C#?

EventHandlers["PlayerConnecting"] += new Action<dynamic, dynamic>((playerName, kickReason) =>
{
     var caller = new Player(source); //source?
     var steamid = caller.Identifiers["steam"];
     if (!DB.isWhitlisted(steamid))
     {
         kickReason("Not whitelisted!");
         CancelEvent(); //cancel?
     }
});

I appreciate every help!

        EventHandlers["csdirt:2"] += new Action<Player, int>(HandleDirt2);

        // ...

        public void HandleDirt2([FromSource] Player player, int dunno)
        {
            Debug.WriteLine($"dirt2 from {player.Name} ({player.Identifiers["steam"]}): {dunno}");

            player.TriggerEvent("chat:addMessage", new { args = new[] { player.Name, $"I'm {player.Identifiers["steam"]}!" } });
        }

Call the CANCEL_EVENT native directly using Function.Call.

1 Like

Works perfect, thanks!

What is the event “csdirt:2”? What is HandleDirt2? Is this the same as the event “PlayerConnecting”??
Is there anyone who can write server event examples for C# in the wiki?
It isn’t possible to use C# if there aren’t any examples/documentation how to add/trigger/register the different events…

2 Likes

It’s the name of his custom event I would assume, the latter is the identifier of the function that handles the event.

And yes it’s possible - it’s called trial & error. Gotta start somewhere when documentation is lacking. Stop being lazy and expect everything to be served on a silver platter.

Figure it out like the rest of us and while at it why don’t YOU fill the wiki with examples?

Wow chill… We’re all trying here and I’m quit sure someone already figured out to create a ServerEvent but keeps it to him.

2 Likes

Lol, I have filled the wiki with some stuff like Vehicle Mods, Ped Components, Weapon Componets s.o.

I’ve learned the FiveM lua scripting basics with help of the wiki and now I can used it.

Ok now I have understood that the example was abstract, sorry about this. If there is a little more documentation from basic fivem functions this thread doesn’t exist.

If I found the right way in C# I promise there will be a edit in the wiki for the server events.

… except this code shows exactly what you need, other than the same BaseScript-inheriting class as on the client?

What about RegisterServerEvent ?

Thanks !

not needed on c#, same as how there’s no RegisterNetEvent on c# either.

How do I POST a json in C# since webclient seems to be blocked on C# client scripts ?

Thanks again :wink:

you do it from the server instead?

Then back to my question : how do i do it in C# ? (calling it from the server, the function works when tested on a Windows console) :slight_smile: