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.
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.
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’
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