Jump to content
Sign in to follow this  
wozzsta

How to save player stats

Recommended Posts

Hi guys, 

 

I'm trying to figure out how to save my users money variable so when they connect/disconnect it will remember their cash amount. I don't care about position, health, load-out etc.... just the money variable. 

 

Also don't care if it is stored locally or on the server, server is obviously preferable but it doesn't matter really. 

 

Any ideas?

 

Thanks, 

Share this post


Link to post
Share on other sites

I'm trying to figure out how to save my users money variable so when they connect/disconnect it will remember their cash amount.

Hi wozzsta, try this to save the amount of cash

profileNamespace setVariable ["cash", _cash]

retrieve cash with getVariable like this

private _cash = profileNamespace getVariable ["cash", 0]

I hope this helps,

Nikander

Share this post


Link to post
Share on other sites

Hi wozzsta, try this to save the amount of cash

profileNamespace setVariable ["cash", _cash]

retrieve cash with getVariable like this

private _cash = profileNamespace getVariable ["cash", 0]

I hope this helps,

Nikander

 

Thanks Nikander,  

 

Where would i add that code? 

 

In the Init.sqf?

Share this post


Link to post
Share on other sites

Where would i add that code?

Maybe you should try and add it in the script that you use to handle all the other cash transactions ?

 

Just a suggestion,

Nikander

Share this post


Link to post
Share on other sites

put this in your initPlayerLocal.sqf , its a simple method saving variable using profilenamespace, and check this out

https://forums.bistudio.com/topic/141462-inidb-save-and-load-data-to-the-server-or-your-local-computer-without-databases/

private ["_player"];

_player =_this select 0;


waitUntil {!isNull _player}; 

if (isNil {profileNamespace getVariable "char_money"}) then { // if profilenamespace doesn't find your variable it creates as 0
	profileNamespace setVariable ["char_money", 0];
};

_profile = (profileNamespace getVariable "char_money"); // Gets your save

_player setVariable ["char_money", _profile]; // loads it

// make a loop to save your profilenamespace or from a addaction like this.
_player addAction ["Save Money",{
	_player =_this select 0; 
	_money = (_player getVariable "char_money");
	profileNamespace setVariable ["char_money", _money];
}];
  • Thanks 1

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
Sign in to follow this  

×