Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //By Dannu, WIP, just a reference
- if($savePath $= "")
- $savePath = "config/server/BLD/";
- function GameConnection::associateData(%client)
- {
- %b = %client.getBLID();
- for(%i = 0; %i < DataSS.getCount(); %i++)
- {
- %client.data[%i] = $Data[%b,%i];
- }
- deleteVariables("$data[%b, *]"); //testing
- }
- function GameConnection::saveData(%client)
- {
- %fileObject = new fileObject();
- %fileObject.openForWrite($savePath @ %client.getBLID() @ ".cs");
- for(%i=0; %i < DataSS.getCount(); %i++)
- {
- %value = DataSS.getObject(%i).value;
- %fileObject.writeLine("$Data[" @ %client.getBLID() @ "," @ %i @ "] = \"" @ %client.data[%i] @ "\";");
- }
- %fileObject.close();
- %fileObject.delete();
- }
- function GameConnection::createBlankData(%client)
- {
- %fileObject = new fileObject();
- %fileObject.openForWrite($savePath @ %client.getBLID() @ ".cs");
- for(%i=0; %i < DataSS.getCount(); %i++)
- {
- %value = DataSS.getObject(%i).value;
- %fileObject.writeLine("$Data[" @ %client.getBLID() @ "," @ %i @ "] = \"" @ $defaultData[%i] @ "\";");
- }
- %fileObject.close();
- %fileObject.delete();
- }
- function GDNFR(%ref)
- {
- return getDataNumFromRef(%ref);
- }
- function getDataNumFromRef(%ref)
- {
- for(%i = 0; $dataRef[%i] !$= ""; %i++)
- {
- if($dataRef[%i] $= %ref)
- return %i;
- }
- return 0;
- }
- function getDataRefFromNum(%num)
- {
- return $dataRef[%num];
- }
- function populateData()
- {
- if(!isObject(DataSS))
- {
- new simSet(DataSS);
- }
- else
- {
- DataSS.delete();
- populateData();
- return;
- }
- %fileObject = new fileObject();
- %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.
- for(%i = 0; !%fileObject.isEOF(); %i++)
- {
- %line = %fileObject.readLine();
- %dataInfo = new scriptObject()
- {
- value = getWord(%line, 0); //Improve this to store more data here and cut back on variable use
- };
- $DataRef[%i] = %data[%i];
- $defaultData[%i] = getWord(%line, 1);
- DataSS.add(%dataInfo);
- }
- %fileObject.close();
- %fileObject.delete();
- }
- function initData()
- {
- if(isObject(DataSS) && !$confirmInit)
- {
- echo("Using this function during playtime is not advised.");
- echo("Please confirm within 10 seconds by running function again.");
- $confirmInit = true;
- $initResetSched = schedule(10000, 0, 'resetInitConfirm');
- return;
- }
- else if($confirmInit)
- {
- $confirmInit = false;
- cancel($initResetSched);
- }
- populateData();
- }
- function resetInitConfirm()
- {
- $confirmInit = false;
- }
- populateData();
- function GameConnection::loadData(%client)
- {
- %path = $savePath @ %client.getBLID() @ ".cs";
- if(!isFile(%path))
- {
- return 404;
- }
- exec(%path);
- %client.associateData();
- }
- function saveAllData()
- {
- for(%i = 0; %i < clientGroup.getCount(); %i++)
- {
- %client = clientGroup.getObject(%i);
- %client.saveInventory();
- %client.saveData();
- }
- }
- return; //remake
- function GameConnection::LoadInventory(%client)
- {
- for(%i = 0; %i < 5; %i++)
- {
- if(%client.data[GDNFR("slot" @ %i)] != 0)
- {
- %index = GDNFR("slot" @ %i);
- %data = %client.data[%index];
- %dataID = %data.getId();
- %client.forceEquip(%i, %dataID);
- %client.data[%index] = 0;
- }
- }
- }
- function GameConnection::saveInventory(%client)
- {
- for(%i = 0; %i < 5; %i++)
- {
- %idata = %client.tool[%i];
- %idata = %data.getName();
- %client.data[GDNFR("slot" @ %i)] = %idata;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment