Scripting in C#
Setting up our environment
Before you can create your first C# resource, you’ll need to install Visual Studio 2022 (the community/free version will work just fine).
Creating your project
- Open a command window by pressing
Win + R
, type incmd
and then pressEnter
. Now you should have a console like the one below:
- Once that window shows up we’re going to be following the FiveM’s Cookbook modern guide to setup our scripting environment, so make sure you enter the following commands in the console window:
dotnet new -i CitizenFX.Templates
mkdir MyResource
cd MyResource
dotnet new cfx-resource
- If everything went right, you should get a folder named
MyResource
with a solution file namedMyResource.sln
. This is the solution file to manage your projects. - To build the project, you can click on
build.cmd
, which will build a release server and client dll for you, both targeting the correct.NET Framework
needed for FiveM and FXServer.
Setting up and running the project
If you built the resource, you should now have a dist
folder available, so you should be able to run the following commands:
Change directory to the resource path named MyResource
:
cd /d [PATH TO THIS RESOURCE]
Make a symbolic link. For more information about mklink
, visit the following article by Microsoft.
mklink /d X:\cfx-server-data\resources\[local]\MyResource dist
Make sure you provide the right paths.
Afterwards, you can use ensure MyResource
in your server.cfg
or server console to start the resource.
Congratulations, you’ve created a resource using FiveM’s C# templates!
Let’s write some code
It’s finally time to actually start writing some code! 🎉
Last modified August 12, 2024: Correct typos throughout the docs wiki. (#355) (0dc536a)