Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Arma 3 remote variable saving and loading
- // variable name to save in server profileNamespace is prefixed with player uuid, thus on server, variable for each player has unique name
- // variables have to be global, that is without the prefix _underscore
- // saves variable remotely on server into variable
- ["Player_MONEY"] call SAVE_ON_SERVER;
- // loads from server variable Player_MONEY and locally assings loaded value, the 0 is default value if variable was not found on server
- ["Player_MONEY", "0"] call LOAD_FROM_SERVER;
- SAVE_ON_SERVER = {
- private ["_variableName"];
- _variableName = _this;
- _variableNamePlayerSpecific = format["%1_%2", getplayerUID player, _variableName]
- [
- [_variableNamePlayerSpecific, call compile format["_variableName"]],
- "SAVE_ON_SERVER_REMOTE",
- false
- ] call BIS_fnc_MP;
- };
- SAVE_ON_SERVER_REMOTE = {
- profileNamespace setVariable [
- _this select 0,
- _this select 1
- ];
- saveProfileNamespace;
- };
- LOAD_FROM_SERVER = {
- [
- [player, _this],
- "LOAD_FROM_SERVER_REMOTE",
- false
- ] call BIS_fnc_MP;
- };
- LOAD_FROM_SERVER_REMOTE = {
- private ["_variableName", "_variableNamePlayerSpecific", "_variableContents", "_calledFromMachine", "_data", "_defaultValue"];
- _calledFromMachine = _this select 0;
- _data = _this select 1;
- _variableName = _data select 0;
- _variableNamePlayerSpecific = format["%1_%2", getplayerUID _calledFromMachine, _variableName]
- _defaultValue = _data select 1;
- _variableContents = profileNamespace getVariable [
- _variableNamePlayerSpecific,
- _defaultValue
- ];
- [
- [_variableName, _variableContents],
- "LOAD_FROM_REMOTE_CALLBACK",
- _calledFromMachine
- ] call BIS_fnc_MP;
- };
- LOAD_FROM_REMOTE_CALLBACK = {
- private ["_variableName", "_variableContents"];
- _variableName = _this select 0;
- _variableContents = _this select 1;
- _variableContents call compile format["%1 = _this;", _variableName];
- };
Advertisement
Add Comment
Please, Sign In to add comment