Hello, I’m writing this post because I have some questions about developing my gamemode. I’m coming from another platform and have jumped into the deep end with FiveM. I want to create a gamemode, I’ll do it in C#, and I want to start with the most basic thing, which is giving me the most trouble: spawning. I want to encapsulate all my code in a single resource, let’s call it gamemode-test. I’ve already seen that the server comes with some pretty useful resources by default, such as mapmanager, baseevents, spawnmanager, etc. Currently, I can spawn because the default resource in basic-gamemode is handling it, and it’s loading the points from the fivem-map-skater map.
These are my questions:
Can a server work without a mapmanager? I dont really need more than one map
Can I get rid of fivem-map-skater and put that “map” inside my gamemode-test?
Can I simply not have a map.lua file? And force spawns using the spawnManager (spawnPlayer) exports.
Imagine what I want to do is: Okay, once the player has finished loading the server, they’ll see a camera pointing at a landscape, and when they press the E key, they’ll be “spawned/teleported” to a location I specify. What’s the event flow to accomplish this? In other environments, I would listen for the onPlayerConnected, freeze the spawn, create a camera, perform the necessary operations, and then release the player. The problem with this logic is, what’s the correct event to use as the entry point? Is it onPlayerConnecting? onResourceStart? playerSpawned? playerJoining? (server)
I know what I’m writing might sound like a beginner’s topic, but it’s getting complicated because I don’t really understand which resources are needed/essential for a functional server. Thanks in advance. If the post isn’t well-written or I’m being ambiguous, please let me know and I’ll clarify it as much as possible. I think what I might not understand is the concept of “spawning” in general or when the player client is ready to start being manipulated. Also im not asking for a piece of code. I only want to know what’s the entry point where I should start doing the thing I said and if the mapmanager is really mandatory…
It’s refreshing to see someone tackling something difficult and non-roleplay related on the fourm for a change (and in my favorite language no less!), good on you.
Yes
Yes, and yes
Yes, and sort of
So first of all, as a point of clarification, ‘map’ is a bit of a misnomer. I’m sure there’s a good historical reason why it is called as such, but everywhere it says ‘map’, you can safely replace that in your mind with “spawn point list”.
To address your first question, do you needmapmanager: no, not at all. FiveM/FXServer is your oyster, and the sky is the limit. All the resources provided in cfx-server-data are incredibly useful, and you’ll generally find that a lot of public resources rely on the functionality they provided (e.g., player spawning, chat messages, etc.); however, in a fully custom environment like yours, you’re under no obligation to use them.
Regarding question two, can you re/move fivem-map-skater: for sure. They’re just resources like everything else; you can move or remove them as you please. However, be wary of load ordering. For example, if you move the map file inside your custom resource, then start said resource before starting mapmanager, that would break it, as mapmanager listens for new resource start-ups and then checks if they contain a map for it to use - it can’t check your resource if it has already started.
And your final questions, can you not have a map file and force spawns with spawnmanager: to misquote a famous captain: “well yes, but actually no”. spawnmanagerrelies on mapmanager (and by extension, map resources like fivem-map-skater) to provide it with spawn points (remember, ‘map’ = “list of spawn points”). No maps or mapmanager means no spawn points, no spawn points means spawnmanager cannot spawn any players - even if you call the spawnPlayer export, as if you inspect the code, you’ll see it requires at least one spawn point, or else you’re headed for a runtime error:
-- spawns the current player at a certain spawn point index (or a random one, for that matter)
function spawnPlayer(spawnIdx, cb)
[...]
Citizen.CreateThread(function()
-- if the spawn isn't set, select a random one
if not spawnIdx then
spawnIdx = GetRandomIntInRange(1, #spawnPoints + 1)
end
-- get the spawn from the array
local spawn
if type(spawnIdx) == 'table' then
spawn = spawnIdx
else
spawn = spawnPoints[spawnIdx]
end
[...]
So what does this all mean for your custom gamemode? Well, you have two options:
Use a map resource, mapmanager, and spawnmanager.
This is what the FiveM purists will tell you is the best option, and really, it’s not so bad.
spawnmanager has exports like setAutoSpawn which give you pretty good control over how spawning is handled (i.e.: don’t autospawn the player when they join, let my resource handle that; and don’t autospawn the player when they die, let my resource handle that).
You can edit or create a new map that contains spawn points that better suit your gamemode, or you can just use the existing ones and then TP the player around the map as you need, much of a muchness.
You can rename both the map and gamemode so they show up in the server browser with new names, if you’re so inclined.
Burn it all down! Write something entirely custom!
This one will be the most fun.
maps, mapmanager, basic-gamemode, spawnmanager, blah blah blah - it’s all just code! Regular old FiveM resources. Nothing is stopping you from cherry-picking the logic that you want, removing these resources, and creating something custom yourself.
Since you’re brand new to FiveM, going down the route of Option 1 for now, and then revisiting this later might be the more sound idea. Focus on the core of your gamemode, rather than getting suck messing around with this nonsense, but the choice is yours.
Keep in mind that some of these events (and other events listed in the docs) come from resources like spawnmanager (e.g., playerSpawned) - so if you decide to write something custom, you might not be able to rely on these events, and might need to roll your own system.
If you haven’t already, go tear apart spawnmanager. Even if you don’t use it, it’ll help you understand the flow of spawning - particularly look at the spawnPlayer function.
Hopefully that helps point you in the right direction - reach out if you need anything else.
Thank you so much for your reply, it was a great help and clarified many concepts I wasn’t entirely clear on. The game mode I want to make will be a tycoon type game, so I’m really excited to get started. I hope we cross paths again soon, and again thank you very much!