Dannu

saving.cs

Jul 21st, 2015
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. //By Dannu, WIP, just a reference
  2.  
  3. if($savePath $= "")
  4. $savePath = "config/server/BLD/";
  5.  
  6. function GameConnection::associateData(%client)
  7. {
  8. %b = %client.getBLID();
  9.  
  10. for(%i = 0; %i < DataSS.getCount(); %i++)
  11. {
  12. %client.data[%i] = $Data[%b,%i];
  13. }
  14. deleteVariables("$data[%b, *]"); //testing
  15. }
  16.  
  17. function GameConnection::saveData(%client)
  18. {
  19. %fileObject = new fileObject();
  20. %fileObject.openForWrite($savePath @ %client.getBLID() @ ".cs");
  21. for(%i=0; %i < DataSS.getCount(); %i++)
  22. {
  23. %value = DataSS.getObject(%i).value;
  24. %fileObject.writeLine("$Data[" @ %client.getBLID() @ "," @ %i @ "] = \"" @ %client.data[%i] @ "\";");
  25. }
  26. %fileObject.close();
  27. %fileObject.delete();
  28. }
  29.  
  30. function GameConnection::createBlankData(%client)
  31. {
  32. %fileObject = new fileObject();
  33. %fileObject.openForWrite($savePath @ %client.getBLID() @ ".cs");
  34. for(%i=0; %i < DataSS.getCount(); %i++)
  35. {
  36. %value = DataSS.getObject(%i).value;
  37. %fileObject.writeLine("$Data[" @ %client.getBLID() @ "," @ %i @ "] = \"" @ $defaultData[%i] @ "\";");
  38. }
  39. %fileObject.close();
  40. %fileObject.delete();
  41. }
  42.  
  43. function GDNFR(%ref)
  44. {
  45. return getDataNumFromRef(%ref);
  46. }
  47.  
  48. function getDataNumFromRef(%ref)
  49. {
  50. for(%i = 0; $dataRef[%i] !$= ""; %i++)
  51. {
  52. if($dataRef[%i] $= %ref)
  53. return %i;
  54. }
  55. return 0;
  56. }
  57.  
  58. function getDataRefFromNum(%num)
  59. {
  60. return $dataRef[%num];
  61. }
  62.  
  63. function populateData()
  64. {
  65. if(!isObject(DataSS))
  66. {
  67. new simSet(DataSS);
  68. }
  69. else
  70. {
  71. DataSS.delete();
  72. populateData();
  73. return;
  74. }
  75. %fileObject = new fileObject();
  76. %fileObject.openForRead("Add-Ons/Gamemode_BaseLooters/data.txt"); //Supports custom data and default values, each line gives you a new data to store, the first word in the line is data RefName, the second is the default value it is assigned.
  77. for(%i = 0; !%fileObject.isEOF(); %i++)
  78. {
  79. %line = %fileObject.readLine();
  80. %dataInfo = new scriptObject()
  81. {
  82. value = getWord(%line, 0); //Improve this to store more data here and cut back on variable use
  83. };
  84. $DataRef[%i] = %data[%i];
  85. $defaultData[%i] = getWord(%line, 1);
  86.  
  87. DataSS.add(%dataInfo);
  88. }
  89. %fileObject.close();
  90. %fileObject.delete();
  91. }
  92.  
  93. function initData()
  94. {
  95. if(isObject(DataSS) && !$confirmInit)
  96. {
  97. echo("Using this function during playtime is not advised.");
  98. echo("Please confirm within 10 seconds by running function again.");
  99. $confirmInit = true;
  100. $initResetSched = schedule(10000, 0, 'resetInitConfirm');
  101. return;
  102. }
  103. else if($confirmInit)
  104. {
  105. $confirmInit = false;
  106. cancel($initResetSched);
  107. }
  108. populateData();
  109. }
  110.  
  111. function resetInitConfirm()
  112. {
  113. $confirmInit = false;
  114. }
  115.  
  116. populateData();
  117.  
  118. function GameConnection::loadData(%client)
  119. {
  120. %path = $savePath @ %client.getBLID() @ ".cs";
  121. if(!isFile(%path))
  122. {
  123. return 404;
  124. }
  125. exec(%path);
  126. %client.associateData();
  127. }
  128.  
  129. function saveAllData()
  130. {
  131. for(%i = 0; %i < clientGroup.getCount(); %i++)
  132. {
  133. %client = clientGroup.getObject(%i);
  134. %client.saveInventory();
  135. %client.saveData();
  136. }
  137. }
  138. return; //remake
  139. function GameConnection::LoadInventory(%client)
  140. {
  141. for(%i = 0; %i < 5; %i++)
  142. {
  143. if(%client.data[GDNFR("slot" @ %i)] != 0)
  144. {
  145. %index = GDNFR("slot" @ %i);
  146. %data = %client.data[%index];
  147. %dataID = %data.getId();
  148. %client.forceEquip(%i, %dataID);
  149. %client.data[%index] = 0;
  150. }
  151. }
  152. }
  153.  
  154. function GameConnection::saveInventory(%client)
  155. {
  156. for(%i = 0; %i < 5; %i++)
  157. {
  158. %idata = %client.tool[%i];
  159.  
  160. %idata = %data.getName();
  161. %client.data[GDNFR("slot" @ %i)] = %idata;
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment