[HELP] FiveM alternative to .ini files from SP mods or how to store script settings?

Hello everyone, I am very new to FiveM and need help.

I am porting my ViewPointV mod from SP to FiveM, and currently looking for the best approach to storing client settings.

The way I handled this in SP is by having a few .ini files that I was reading and writing to/from, which is impossible in FiveM due to IO being blocked.

I understand that I’ll have to store the settings server side, but I don’t understand how would that work?
Will there be a separate file for every user? My settings contain parameters like offsets for the cameras, amount of camera shake etc. I want the user to be able to configure those parameters for themselves client side, via the mod’s menu, and of course I want the settings to persist.

Thank you in advance!

Hi.

Easiest way would be to use KVP to store settings client-side directly. (assuming you don’t care that a malicious user can change their settings without your consent)

(keep in mind that GetKvp_* natives are different based on the type of value that you want to receive. Int, float, string, …)

KVPs are shared between servers if they are stored client-side. So, if a player joins a server with your ViewPointV resource, changes settings, and joins another server with the same resource, the settings will carry.


Additionally, you can store them server-side, for each player, either using json files (IO is not blocked server-side), or in a database, like mysql. Depending on what you need to save, this might be overkill.

1 Like

KVPs are exactly what I was looking for!
Thank you for the quick and helpful response.

1 Like

I struggle a bit with understanding how these natives work, if you could help me a bit more, I would be very thankful :slight_smile:

Is there a possibility to create multiple KVP files?
How do I pass a specific KVP file to the KVP getter/setter natives, so it will know where to save\load from?
I need multiple files to store my settings.
Can you show me an example of usage?

KVP stands for key-value-pair. It’s not a file, really. But a variable. You set one (i.e. create or modify the variable) by putting the “key” as the name of the variable, and the value as the… value of the variable.

When you want to retreive the var data, you use the getter native to search for the “key”.

Here is how I use it in my scalePhone resource, to load and save the user’s phone theme:

1 Like

I understand now. Tried it and it worked, thank you!

2 Likes