Author Topic: Adding On Connect?  (Read 1317 times)

Ok well I made some code that save's all the junk for my rpg but is what happen's is you don't get 1 of a material and you spawn it will load the save file as =; which causes a syntax therefore crashing after 3 people spawn if they have been there before. So I made some code to try to add 1 on connect but it doesn't add any and no syntax's

Code: [Select]
package Add
{
 function GameConnection::onconnect(%client,%a,%b,%c,%d,%e,%f){
  if(%client.minigame)
  %obj.client.quantity["Copperore"] += 1;
    %obj.client.quantity["Goldore"] += 1;
     %obj.client.quantity["Silverore"] += 1;
    %obj.client.quantity["Pinewood"] += 1;
  %obj.client.quantity["Oakwood"] += 1;
  %obj.client.quantity["Maplewood"] += 1;
         Parent::onconnect(%client,%a,%b,%c,%d,%e,%f);
      }
};
ActivatePackage(Add);

Saving

Code: [Select]
package Savzorz
{
function GameConnection::onClientEnterGame(%this)
{
Parent::onClientEnterGame(%this);
exec("Add-ons/RPG/Rpgbank/" @ %this.bl_id @ ".RPGData");
%this.RPG["ISSPAWNED"] = 1;
}
function SaveRPGData(%Client)
{
if(%client.RPG["ISSPAWNED"] == 0)
return;
%file = new FileObject();
%file.openforwrite("Add-ons/RPG/Rpgbank/" @ %client.bl_id @ ".RPGData");
%file.writeline("findclientbybl_id(" @  %client.bl_id @ ").quantity[\"CopperOre\"] = " @ %client.quantity["CopperOre"] @ ";");
%file.writeline("findclientbybl_id(" @  %client.bl_id @ ").quantity[\"SilverOre\"] = " @ %client.quantity["SilverOre"] @ ";");
%file.writeline("findclientbybl_id(" @  %client.bl_id @ ").quantity[\"GoldOre\"]   = " @ %client.quantity["GoldOre"] @ ";");
%file.writeline("findclientbybl_id(" @  %client.bl_id @ ").quantity[\"PineWood\"]  = " @ %client.quantity["PineWood"] @ ";");
%file.writeline("findclientbybl_id(" @  %client.bl_id @ ").quantity[\"OakWood\"]   = " @ %client.quantity["OakWood"] @ ";");
%file.writeline("findclientbybl_id(" @  %client.bl_id @ ").quantity[\"MapleWood\"] = " @ %client.quantity["MapleWood"] @ ";");
%file.writeline("findclientbybl_id(" @  %client.bl_id @ ").quantity[\"Gold\"]      = " @ %client.quantity["Gold"] @ ";");
%file.close();
%file.delete();
}
function autoSaveRPGData()
{
for(%x=0; %x < clientgroup.getcount(); %x++)
{
SaveRPGData(clientgroup.getobject(%x));
}
schedule(120000,0,autoSaveRPGData);
}
};
activatePackage("Savzorz");
schedule(120000,0,autoSaveRPGData);
« Last Edit: June 18, 2008, 04:00:34 PM by Kunit_Yo »

Your post split my brain in half with all the grammatical errors. It took me 10 minutes to figure out what the hell you were saying.

There really is no need to do all this. What you should do is save your data is variables like:
Code: [Select]
$badGrammar::Client[%Client.BL_ID]::CopperOre = %var;That way, you don't even need to load it. Just use that variable in place of %client.badGrammar["CopperOre"] in every transaction and export the $badGrammar variables to a file.


In your first onconnect method, you need to add braces under the minigame check, and under the Maplewood+=1;

Since currently it only gives the player 1 Copperore, and the others stay as "".

« Last Edit: June 20, 2008, 06:30:37 PM by Kunit_Yo »

Code: [Select]
package Add
{
function GameConnection::onconnect(%client,%a,%b,%c,%d,%e,%f)
{
%obj.client.quantity["Copperore"] += 1;
  %obj.client.quantity["Goldore"] += 1;
    %obj.client.quantity["Silverore"] += 1;
  %obj.client.quantity["Pinewood"] += 1;
%obj.client.quantity["Oakwood"] += 1;
%obj.client.quantity["Maplewood"] += 1;
        Parent::onconnect(%client,%a,%b,%c,%d,%e,%f);
}
};     
ActivatePackage(Add);

You had an extra closing bracket between the materials and the parent.

Doesn't give anything but no syntax's.

Ok, first, what the hell is the point of findClientByBl_ID(%client.bl_id); ? You already have the client.

And, to fix your problem.
I'm too lazy to write something for each variable, so just copy something like this for each one.
Code: [Select]
if(%client.quantity["CopperOre"] $= ""
    %client.quantity["CopperOre"] = 0;
%file.writeline("findclientbybl_id(" @  %client.bl_id @ ").quantity[\"CopperOre\"] = " @ %client.quantity["CopperOre"] @ ";");
« Last Edit: June 21, 2008, 02:25:43 AM by Headcrab Zombie »