[Discussion] Building a server "from scratch"

I want to start a discussion around coding your own server(by server, I mean gamemode/framework).

I have well over 100 hours on FiveM already, but I think less than 10 of that is actually on other servers, and most of them on my own, not-actually-opened-for-public test server. Partly because I want to play a RPG-like gamemode, without the RP element, and partly because almost every server feels…unfinished.

I’m writing this more as a self-post, but I think this might be some good information for people that want to create their own server, and not be dependent on big frameworks like ESX or VRP.

Warning: long post ahead.

First of all, why?
Well…because.
Building your own server “from scratch” can have great advantages like:

  1. Knowing what all your scripts actually do.
  2. Being able to fix your scripts.
  3. Not relying on other people to build resources that are compatible with your server.
  4. Actually make your server the way you want it be, with only the features that you want and need.
  5. Hackers using Lua executors will have a harder time cheating because your server’s source code is not available on the interwebs for all to see.

Disadvantages might include:

  1. Effort required to code the server.
  2. ughhh…it’s not installed automatically by ZAP-Hosting…I guess…

The plan.
Before you start building your server, you might want to first think about what you actually WANT and NEED your server to have.

For my server, I’m trying to replicate the feel of SA-MP Godfather / RPG gamemodes that I used to play like 10 years ago. Power-gaming and non-RP behavior are allowed because RP is not the focus of those servers.

To create a server like that I need the following:

  1. Player sandboxing.
    I need to know what the player does at every moment, to make sure that he doesn’t use a command or menu when he is not supposed to (for example , starting 10 activities at once). Player sandboxing is also important to make sure that the player is who he claims he is. Player Registration and saving are included here.
  2. Ranks.
    While ACE permissions are nice-n-all, I will make my own rank system that will be saved on the DB for each player. This might sound complicated to some people, but both ranks and sandboxing mechanics will be just 2 server-only variables that I will keep track of for all players.
  3. Money Generators.
    RPGs are usually “economy-based”, so having a currency($ in this case) and a bunch of activities that can generate the currency is important. Jobs, Races, and other types of missions are included here. Those activities need to be both GRINDABLE AND FUN. THIS IS THE MAIN GAMEPLAY LOOP FOR AN ECONOMY SERVER. During development, if you don’t feel like doing some jobs for fun, even alone on the server, the players will probably not like it either.
  4. Money Sinks.
    Buying cars, buying clothes (or skins), buying everything that’s worth buying goes here. Money sinks are important for an RPG to make sure that hyperinflation does not happen (that fast). Things like taxes, rent, fines or anything that can take currency from the player without giving it to another are also important. Keep in mind that this is not real life. If you don’t regulate your economy, your currency will be as worthless as the Venezuelan bolívar.
  5. End-game content.
    For my RPG server, the end-game content is represented by Factions. Police, Taxi, Gangs, News Reporters, etc. This will act like complex jobs, that are also coordinated by players. Gang factions will fight over territories, Police faction will have to enforce “RP” server rules, like No-Deathmatch, and will hunt down players with wanted levels, etc.
    Factions will have limited player slots; level or other stat requirements to join and regular checks to make sure only active players are part of that faction.

Dependencies
This is why I added “from scratch” in quotations. Just because you don’t use a big framework, it does not mean that you can’t use resources from other people.

MySQL-Async by zr0iq and Warmenu by Warxander are essential for my server. I use them everywhere.
XNLRankBar by VenomXNL is also a great resource that I use. While not a hard dependency like mysql-async or warmenu, I think it should still be mentioned here.

Starting out.
Ok, so we know what we want. Now what?
Welp…start coding. :smiley:

I started out with making some copies of the default resources that you get from Cfx. I copied the gametype, map, and playernames resources and I modified them to what I needed.

For Gametype, I didn’t do much at first, but because I want to handle my own player spawn (while still using spawnmanager), I needed to have a way to change the auto-respawn setting. Gametype resource is also good for setting the gametype name in the server list, and to add ASCII art in the client/server console :stuck_out_tongue: .
Map resource is important for setting up spawnpoints. For now, there is only one spawnpoint, but I will later use that when spawning the player at its own house is needed.
For playernames, I modified the distance from where the name is visible.

After that, I started my Core resource. This resource will keep track of the player. This will include the login/register system, the player stats and player character system, and general admin commands and menus.

Learning the ropes.
I think the start is the hardest part when it comes to FiveM scripting. For lua at least, the only thing that you need to know, language-wise, is how to store data (variable and arrays), how to access that data, functions and loops. That’s all. Maybe a bit of maths too, but not that much.

The main thing that you WILL use ALOT is natives. And thankfully, you can search and find them in the Native Reference documentation!

Want to change the player’s coords? Search “coords” on the native reference, scroll around, and look at that! SetEntityCoords(). But what if I want to give them a weapon? Idk… “weapon”…oh, look! GiveWeaponToPed()

You can do the same thing on the forums, by the way.

Linking resources
Events and exported functions are the “name of the game” here.
I use exported functions to gather very specific data from one resource to use in another, and events for syncing data between resources.

My core server script triggers a server event and a client event every time a piece of data is changed for one player. Every single resource has a handler for those events in their server/client scripts, that takes the data modification and updates its own player data array.
This is how I keep all my resources in sync. One resource uses a TriggerEvent to change data in the Core resource, and then the Core sends the modification to all other resources. Everything stays in sync. Everyone stays happy.

Hitting a roadblock.
There’s no doubt that at one point you will hit a roadblock during development. That’s normal. You can’t just code day-n-night without burning out. Just take a break, go on other servers, play other games or whatnot. Take. your. time. Nobody is gonna force you to finish the whole server in a month (hopefully).

My server is in development since April 2020… but more than half of that is slacking or just not having enough motivation to finish it. Writing maybe 2 - 3 lines of code per week, or sometimes even per month.

Motivation
Or, as 2klicksphilip puts it: Mid-development Hell.
Oh boy, this is a hard one, especially if you don’t have someone that you can show your progress to.

For me, whenever I lose motivation, I invite a couple of friends to play-test and screw around on the server, or just leave the project on hold for a couple of days, until I get the inspiration to code again.

Just keep in mind that this WILL TAKE TIME. More that you will want to anyway.

Final Notes
This post when all over the place (mostly because I wrote it during multiple days), but I hope some of the information here can help someone that tries to make their own scripts and/or server.

Also, I tried not to use the work framework, mostly because your server does not need to be modular. Embrace the spaghetti code!

6 Likes