Only C# developing

Hello,

sorry if this is a really dumb question, but I’m trying to figure out how to properly use C# for midding in FiveM. On the main website I see that C# is supported in server and client, so if I understand correctly, everything I need could be coded in C# and I don’t even have to touch Lua in any way?

If so, here’s what I’m trying to figure out. How do I even use server function like GetPlayerPing() and stuff because even after I added CitizenFX.Core reference to my project, the function GetPlayerPing and others just don’t exist. Do I need to add some other references as well or am I doing something wrong?

Hey man, so basically as you seem to know you can reference the citizenFX lib found in your fivem install directory at
FiveM Application Data > citizen > clr2 > lib > mono > 4.5 > CitizenFX.core.dll
Now you can use the namespaces
citizenFX.Core;
citizenFX.Core.native;
citizenFX.Core.UI;

This gives you access to client side scripting and all its goodies, however, for the server side you will need to download the new FXserver (only the fx server supports c# server scripting) from https://runtime.fivem.net/artifacts/fivem/
you can then extract it and set a reference at
FXserver > citizen > clr2 > lib > mono > 4.5 > citizenFX.core.dll
Now you can use the namespaces
citizenFX.Core;
citizenFX.Core.native;

this gives you access to all the server side functions, so to now get the ping of the player you could do something like:

Player plr;
int currentPing;
currentPing = plr.ping;

Hope this helps you out, feel free to say if you need any more help.

2 Likes

Well that’s exactly what I did to be honest, but I see only these 2:
citizenFX.Core;
citizenFX.Core.Native;

I’ve downloaded the latest master from https://runtime.fivem.net/artifacts/fivem/build_server_windows/master/ and put CitizenFX.Core.dll into the reference, but still don’t have access to server functions

My CitizenFX.Core.dll file is 147KB big if that helps you

//EDIT
Actually, plr.Ping; works for me, but I can’t use any of functions like
GetPlayers();
CancelEvent();
etc
etc

Testing it out right now, give me a few mins.

Right I need to sort something else out, but I will test it out later but one idea i had was to try this

PlayerList playerList;
playerList = Players;
string playerCounter = "There are currently: " + playerList.Count();
Debug.Write(playerCounter);

1 Like

Well, if not a single function is working as it should be and I need to write everything like this, that’s pretty shitty tbh :smiley:

how i can send a chat message in c# ? :slight_smile:

Back now!
I just tested that script and it works, you also need to use the PlayerList type because its a custom data type (i think), there is straight up no documentation on server c# scripts so you just need to test things out a bit more than usual.

1 Like

You can send a message in chat by using the event “chatMessage”,
e.g.
TriggerEvent(“chatMessage”, “IM A TEXTCHAT MESSAGE!”);

That i can call server side? :slight_smile:
Thanks.

It exist a litte wiki for c# server side?

I try to use that:

using System;
using System.Collections.Generic;
using System.Text;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using System.Threading.Tasks;

namespace FXCore
{
    public class main : BaseScript
    {
        public main()
        {
            EventHandlers["chatMessage"] += new Action<int, string, string>(OnPlayerText);
            EventHandlers["onResourceStart"] += new Action<string>(OnResourceStart);
            EventHandlers["playerConnecting"] += new Action<string, string>(OnPlayerConnecting);

            
        }

        private void OnPlayerText(int player, string playerName, string chatMessage)
        {
            TriggerEvent("chatMessage", "test");
        }

        private void OnResourceStart(string resourceName)
        {
            Debug.Write("Resource: " + resourceName);
        }

        private void OnPlayerConnecting(string playerName, string setKickReason)
        {
            TriggerEvent("chatMessage", "hey");
        }
    }
}

Are you asking if there is a wiki for c# server scripting? If so, not yet (at least i don’t think so).

I try the simplest stuff, but it wont work.
how i can trigger stuff like “onResourceStart”, you see in my last post my try but it wont work. :frowning:

I’m kinda new to everything but what are you trying to do with onResourceStart anyway? and are you adding the parameter for it?

i only try to call a server side stuff. :smiley:
I see my c# file wont be loading :open_mouth:

how i can load my .dll?
I create a folder with a __resource.lua and there i write server_script ‘FXCore.dll’
But not working :frowning:

I dont know if its still an issue but you should make all c# scripts end in .net.dll
e.g.
‘FXCore.net.dll’
then in __resource.lua write
server_script ‘FXCore.net.dll’

1 Like

your ressource file should look like this :

server_scripts { 
'304FrameworkSV.net.dll'
}

client_script{
'304FrameworkCL.net.dll',
}

never forget to name your dll : yourScriptName.net.dll it’s needed by fivem , you can go in project propertie and in assembly name put the final dll name with youScript.net.dll , like this all the time you build your script it’s already correctly named.

if you follow this few points and your dll is build successfuly then in the log (both side) you should see your script loading