aeroson

Arma 3 remote variable saving and loading

Sep 20th, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. // Arma 3 remote variable saving and loading
  2. // variable name to save in server profileNamespace is prefixed with player uuid, thus on server, variable for each player has unique name
  3. // variables have to be global, that is without the prefix _underscore
  4.  
  5.  
  6. // saves variable remotely on server into variable
  7. ["Player_MONEY"] call SAVE_ON_SERVER;
  8.  
  9. // loads from server variable Player_MONEY and locally assings loaded value, the 0 is default value if variable was not found on server
  10. ["Player_MONEY", "0"] call LOAD_FROM_SERVER;
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. SAVE_ON_SERVER = {
  20. private ["_variableName"];
  21. _variableName = _this;
  22. _variableNamePlayerSpecific = format["%1_%2", getplayerUID player, _variableName]
  23. [
  24. [_variableNamePlayerSpecific, call compile format["_variableName"]],
  25. "SAVE_ON_SERVER_REMOTE",
  26. false
  27. ] call BIS_fnc_MP;
  28. };
  29.  
  30.  
  31. SAVE_ON_SERVER_REMOTE = {
  32. profileNamespace setVariable [
  33. _this select 0,
  34. _this select 1
  35. ];
  36. saveProfileNamespace;
  37. };
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. LOAD_FROM_SERVER = {
  46. [
  47. [player, _this],
  48. "LOAD_FROM_SERVER_REMOTE",
  49. false
  50. ] call BIS_fnc_MP;
  51. };
  52.  
  53.  
  54. LOAD_FROM_SERVER_REMOTE = {
  55. private ["_variableName", "_variableNamePlayerSpecific", "_variableContents", "_calledFromMachine", "_data", "_defaultValue"];
  56. _calledFromMachine = _this select 0;
  57. _data = _this select 1;
  58. _variableName = _data select 0;
  59. _variableNamePlayerSpecific = format["%1_%2", getplayerUID _calledFromMachine, _variableName]
  60. _defaultValue = _data select 1;
  61. _variableContents = profileNamespace getVariable [
  62. _variableNamePlayerSpecific,
  63. _defaultValue
  64. ];
  65. [
  66. [_variableName, _variableContents],
  67. "LOAD_FROM_REMOTE_CALLBACK",
  68. _calledFromMachine
  69. ] call BIS_fnc_MP;
  70. };
  71.  
  72.  
  73. LOAD_FROM_REMOTE_CALLBACK = {
  74. private ["_variableName", "_variableContents"];
  75. _variableName = _this select 0;
  76. _variableContents = _this select 1;
  77. _variableContents call compile format["%1 = _this;", _variableName];
  78. };
Advertisement
Add Comment
Please, Sign In to add comment