Author Topic: Saving system  (Read 1365 times)

Does anyone have a variable saving system for when a player leaves the game. when they disconnect i want them to save certain variables like %client.ammo.bow


Wew, I thought this was about saving rights. Luckily it isn't.

Wew, I thought this was about saving rights. Luckily it isn't.
i already have a way around the saving system. also kalph. how would i nake it save even when the server closes

i already have a way around the saving system. also kalph. how would i nake it save even when the server closes

You plan on getting nakey?

Also to answer your question I do believe that you must save the variable (Which ever you want) to a log of the players Ind however much of a certain item they had that loads when you start the server/script. This then allows you to edit it as well.

I saw this somewhere I'm not sure though If I come accross it I'll send it to you.

Code: [Select]
%i=1;
while(%i<=$RPG_savecount){
   %file.writeline("DATA" SPC $RPG_save[%i] SPC %client.rpg_v[$RPG_save[%i]]);
   %i++;
}

Code: [Select]
function RPG_addvalue(%what){
   $RPG_savecount++;
   $RPG_save[$RPG_savecount]=%what;
}

Code: [Select]
while(!%file.isEOF()){
%curline=%file.readline();
switch$(firstWord(%curline)){
case "DATA": %t=restWords(%curline); %client.rpg_v[getword(%t,0)]=getword(%t,1);
}
}

Code: [Select]
RPG_addvalue("Bow_ammo");

Code: [Select]
%ammo=%client.rpg_v["Bow_ammo"];
if(%ammo <= 0){
    return;//no ammo
}
%client.rpg_v["Bow_ammo"]--;

Code: [Select]
package RPG_autosave
{
   function GameConnection::onClientEnterGame(%this){
      Parent::onClientEnterGame(%this);
      servercmdLoadRPG(%this);
   }
   function GameConnection::OnClientLeaveGame(%this){//This tends to exclude the host, however.
      serverCmdSaveRPG(%this);
      Parent::onClientLeaveGame(%this);
   }
};
« Last Edit: January 21, 2010, 04:57:45 PM by rkynick »


Is that a whole working save script or just pieces?
Pieces, but it's most of it.

Here's the RPGKIT save command
Code: [Select]
function servercmdSaveRPGKIT(%client,%slot){
if(%slot < 1 || %slot > 3){messageclient(%client,'',"Invalid slot! Valid slots ar 1,2, or 3.");}
if(!%client.isloaded){return;}
%file = new FileObject();
%file.openForWrite($RPGKIT_SAVELOCATION @ %slot @ "/" @ "R" @ %client.BL_ID @ ".txt");
announce($RPGKIT_SAVELOCATION @ %slot @ "/" @ %client.BL_ID @ ".txt");
%file.writeline("BLID" SPC %client.BL_ID);
%i=0;
while(%i<=$resourcecount){
if($resource[$resourcesave[%i],0]){
%file.writeline("RESOURCE" SPC $resourcesave[%i] SPC %client.resource[$resourcesave[%i]]);
}
%i++;
}

%i=0;
while(%i<=$abilitycount){
if($ability[$abilitysave[%i],0]){
%file.writeline("ABILITY" SPC $abilitysave[%i] SPC %client.ability[$abilitysave[%i]]);
}
%i++;
}

%i=0;
while(%i<=$classcount){
if($class[$classsave[%i],0]){
%file.writeline("CLASS" SPC $classsave[%i] SPC %client.class[$classsave[%i]]);
}
%i++;
}

%i=0;
while(%i<=%client.inventorycount){
if(%client.SRPGINV_item[%i]!$=""){
%file.writeline("INV" SPC %client.SRPGINV_item[%i] SPC %client.SRPGINV_quantity[%i] SPC %client.SRPGINV_specific[%i]);
}
%i++;
}

%i=1;
while(%i<=12){
if(%client.SkillSet[%i]!$=""){
%file.writeline("SKILLSET" SPC %i SPC %client.skillset[%i]);
}
%i++;
}

%i=0;
while(%i<=$questcount){
if(%client.quest[%i]){
%file.writeline("QUEST" SPC $questsave[%i] SPC %client.quest[%i]);
}
%i++;
}

%file.writeline("EQUIP" SPC "weapon" SPC %client.equipped["weapon"]);
%file.writeline("EQUIP" SPC "weapon_specific" SPC %client.equipped["weapon_specific"]);
%file.writeline("EQUIP" SPC "shirt" SPC %client.equipped["shirt"]);
%file.writeline("EQUIP" SPC "boots" SPC %client.equipped["boots"]);
%file.writeline("EQUIP" SPC "gloves" SPC %client.equipped["gloves"]);
%file.writeline("EQUIP" SPC "pants" SPC %client.equipped["pants"]);
%file.writeline("EQUIP" SPC "hat" SPC %client.equipped["hat"]);
%file.writeline("EQUIP" SPC "armor" SPC %client.equipped["armor"]);
%file.writeline("EQUIP" SPC "cape" SPC %client.equipped["cape"]);


//%file.writeline("Tool0" SPC %client.player.tool[0]);
//%file.writeline("Tool1" SPC %client.player.tool[1]);
//%file.writeline("Tool2" SPC %client.player.tool[2]);
//%file.writeline("Tool3" SPC %client.player.tool[3]);
//%file.writeline("Tool4" SPC %client.player.tool[4]);
//%file.writeline("Transform" SPC %client.player.gettransform());
%file.close();
%file.delete();
messageclient(%client,'',"Saved Rpg!");
}

And load
Code: [Select]
function servercmdLoadRPGKIT(%client,%slot){
if(%client.isloaded){announce(%client.name SPC "has loaded");}
if(%slot < 1 || %slot > 3){messageclient(%client,'',"Invalid slot! Valid slots ar 1,2, or 3.");}
if(%client.isloaded){
servercmdsaverpg(%client);
SRPGINV_removeall(%client);
clearallability();
clearallresource();
clearallclass();
}
%client.isloaded=1;
%client.currentrpgslot=%slot;
initresource(%client);//give defaults for each resource, then load over.
initclass(%client);//see above
initability(%client);//see above.
initquest(%client);
%file = new FileObject();
%file.openForRead($RPGKIT_SAVELOCATION @ %slot @ "/" @ "R" @ %client.BL_ID @ ".txt");
while(!%file.isEOF()){
%curline=%file.readline();
switch$(firstWord(%curline)){
case "RESOURCE": %t=restWords(%curline); %client.resource[getword(%t,0)]=getword(%t,1);
case "ABILITY": %t=restWords(%curline); %client.ability[getword(%t,0)]=getword(%t,1);
case "CLASS": %t=restWords(%curline); %client.class[getword(%t,0)]=getword(%t,1);
case "INV": %t=restWords(%curline); SRPGINV_additem_new(%client,getword(%t,0),getword(%t,1),getword(%t,2));
case "EQUIP": %t=restWords(%curline); %client.equipped[getword(%t,0)]=getword(%t,1);
case "SKILLSET": %t=restWords(%curline); %client.Skillset[getword(%t,0)]=getword(%t,1);
case "QUEST": %t=restWords(%curline); %client.quest[getword(%t,0)]=getword(%t,1);
case "Tool0": %client.tool[0]=restwords(%curline);
case "Tool1": %client.tool[1]=restwords(%curline);
case "Tool2": %client.tool[2]=restwords(%curline);
case "Tool3": %client.tool[3]=restwords(%curline);
case "Tool4": %client.tool[4]=restwords(%curline);
case "Transform": %client.ntrans=restwords(%curline);
}
}
%file.close();
%file.delete();
if(isobject(%client.player)){
%client.player.kill();
}
}


Most of that is older(v8?) coding so excuse the lack of indentation. ( I was going through my "complex is better" phase)

Hope it helps you piece together the real thing.
« Last Edit: January 21, 2010, 05:07:52 PM by rkynick »

I found a full working one.
http://www.mediafire.com/?izqowgnjgln
It is too big to post. What do I do to save the variables? This is also used in the hat mod.

You'll need a global variable, for one. Not a local.

Code: [Select]
$GlobalVariableAmmo[%client.blid] = %client.player.ammo;
Then make code to save it to a txt so when you restart the server, it'll stay.



You'll need a global variable, for one. Not a local.
Lies.

My method works 100%.
He's too lazy to piece it together.

Kalph, does yours create lag with all those things being set as server vars?

Kalph, does yours create lag with all those things being set as server vars?
An average save may contain 50 bytes.

Unless you have 10737418+ clients(512MB of RAM), I wouldn't worry.