Jump to content
redburn

How to make persistent scripts?

Recommended Posts

Hello everyone, I would like to know if someone explains to me, how can I do persistent scripts? that although a player to disconnect and reconnect the information continue to be provided since the server started?

Example:

A counter that is shown to the player, but when it is disconnected and reconnected can return to see the time, the same with the current time since it started?

I have a counting clock, but my problem is that when someone disconnects and reconnects they can not see it anymore and if I do a JIP when the player reconnects the time starts again when the mission is not over yet.

Does someone tell me how to solve it?

Share this post


Link to post
Share on other sites

One possible solution: (run on the client):

profileNamespace setVariable ["some_varName",value];

saveProfileNamespace;

Do not do this in a loop as saveProfileNamespace is a heavy file operation.  Also don't use this if you're storing anything sensitive as it's saved on the players PC and anyone with a bit of SQF knowledge will be able to alter this.

 

Another solution:

Create an array on the server and put the players information in there when the player DCs and fetch it when he connects.

 

Another solution:

Implement a database

  • Like 3

Share this post


Link to post
Share on other sites
16 minutes ago, stanhope said:

One possible solution: (run on the client):

profileNamespace setVariable ["some_varName",value];

saveProfileNamespace;

Do not do this in a loop as saveProfileNamespace is a heavy file operation.  Also don't use this if you're storing anything sensitive as it's saved on the players PC and anyone with a bit of SQF knowledge will be able to alter this.

 

Another solution:

Create an array on the server and put the players information in there when the player DCs and fetch it when he connects.

 

Another solution:

Implement a database

Thanks, I'll be seeing how the profileNamespace and saveProfileNamespace

Share this post


Link to post
Share on other sites
8 hours ago, stanhope said:

One possible solution: (run on the client):

profileNamespace setVariable ["some_varName",value];

saveProfileNamespace;

 

Totally agree with @stanhope  My question is secondary:

 

What is the added value of saveProfileNamespace?  As soon as you setvariable, your data are stored in the profileNameSpace (variable is updated). I'm using this process for my addon, saving my own HUD choice. Never used saveProfileNameSpace and all is fine from Arma sessions to sessions. No problem to start with the previous choice.

Share this post


Link to post
Share on other sites

That's a very good question I don't know the answer to.  I just do it because it says in the wiki that it makes a persistent save.

Share this post


Link to post
Share on other sites
7 hours ago, stanhope said:

That's a very good question I don't know the answer to.  I just do it because it says in the wiki that it makes a persistent save.

 

I can do this?

 

profileNamespace setVariable ["[7200] execVM 'time.sqf'"]; OR profileNamespace setVariable ["'time.sqf",7200]; 

 

I'm doing it wrong? or I need to do something else to save the script so that it is persistent no matter if there is involuntary disconnection and when reconnecting you see the persistent time (shows current time)

Share this post


Link to post
Share on other sites

It's rather something like:

 

profileNameSpace setVariable ["RED_Sqf", 7200];

 

Then in your mission script

_time = profileNameSPace getVariable ["RED_sqf",0];   // 0 by default or at start when nothing already saved

[_time] execVM "time.sqf";

 

 

General NOTE:

Your profileNameSpace is made for variables. The less the better. Many addons are saving your choices here. So, the aim is to save data which can be translated in an sqf.

For example:

You can have figures instead of loadouts. Say you have 5 loadouts saved by BIS_fnc_saveInventory. It's awful to save all the stuff of each loadout if you can specify them by 0 to 4

Sure you need to script for that, but you save/load just a figure instead of arrays of arrays. The mission scripts should translate the figure in a corresponding array.

Keep the profileNameSpace cleanest as possible.

  • Like 1

Share this post


Link to post
Share on other sites

Another general note:

profileNameSpace in unsafe to store sensitive information.  Anyone with a bit of knowledge of SQF can list all the variables in there and change their values.  So only store information in there that won't give the player an edge over others if changed.  (Like personal preferences)

  • Like 2

Share this post


Link to post
Share on other sites
On 19/09/2018 at 5:40 AM, redburn said:

I would like to know if someone explains to me, how can I do persistent scripts? that although a player to disconnect and reconnect the information continue to be provided since the server started?

As others have said profileNamespace is a good place to store persistent information without having to rely on addon databases .

 

On 19/09/2018 at 5:40 AM, redburn said:

A counter that is shown to the player, but when it is disconnected and reconnected can return to see the time, the same with the current time since it started?

I have a counting clock, but my problem is that when someone disconnects and reconnects they can not see it anymore and if I do a JIP when the player reconnects the time starts again when the mission is not over yet.

There is little sense storing information about a  timer in a users vars( profileNamspace ) for a currently running MP mission unless it is something related specifically to that client.

For this, as kilo says you would be better off looking at serverTime and possibly estimatedEndServerTime and estimatedTimeLeft as you mention mission over.

If it is not for mission end time ( where you can use the two commands mentioned above ) all you need to do is store the end time in a PV variable, then every client that joins automatically can workout the rest against the current serverTime  (Take note of the warning about serverTime and its sync for a freshly restarted server on the serverTime wiki page, this is apparently fixed in the next update,  finally, but can always be forced to update via estimatedTimeLeft)

  • Like 2

Share this post


Link to post
Share on other sites

You can also use saveProfileNamespace on the server, ideal for sensitive information you wish to not be tampered with. Note that it saves to that specific server profile which means nothing will load (restore) without that specific .vars file.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×