Author Topic: Score saver help  (Read 1245 times)

So I just made a score saver script. I tried using Destiny's (Server_SavedScore) and Script_Player_Persistence but none of them worked. I tried enabling them seperately and then together, and that still didn't work. So i made my own. Note that this does not save scores to a file but to a variable instead. I tested this script and it has no syntax errors, and it runs. But it doesn't work. Can somebody please fix this?

package ss
{
   function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
   {
      Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);   
      %client.savScore(%client);
      if (%client.score < 150)
         %client.delete("You have been kicked for excessive freekilling.");
   }
   
   function savScore(%client)
   {
      %id = %client.bl_id;
      $ss::client[%id] = %client.score; //example: $ss::client30621 = 10
   }
   
   function GameConnection::onPlayerSpawn(%client)
   {
      Parent::onPlayerSpawn(%client);
      %client.loadScore(%client);
   }
   function loadScore(%client)
   {
      %id = %client.bl_id;
      %client.score = $ss::client[%id];
   }
   function GameConnection::onClientLeaveGame(%client)
   {
      Parent::onClientLeaveGame(%client);
      %client.savScore(%client);
   }
};
activatePackage(ss);




   function savScore(%client)
   {
      %id = %client.bl_id;
      $ss::client[%id] = %client.score; //example: $ss::client30621 = 10
   }

   function loadScore(%client)
   {
      %id = %client.bl_id;
      %client.score = $ss::client[%id];
   }
For one function savScore(%client) should be function gameConnection::savScore(%client)

and function loadScore(%client) should be function gameConnection::loadScore(%client)
« Last Edit: August 08, 2012, 01:17:23 PM by jes00 »

For one function savScore(%client) should be function gameConnection::savScore(%client)

and function loadScore(%client) should be function gameConnection::loadScore(%client)

thanks ill modify it

First, you should probably check %killer's score on death that way they're kicked for freekilling, not freekilling then dying.

As for your actual problem,
Code: [Select]
function GameConnection::onClientLeaveGame(%client)
{
   Parent::onClientLeaveGame(%client);
   %client.savScore(%client);
}
You're basically saying "Leave the game, then save their score." which, if you think about it, doesn't make any sense. The client will be gone by the time it saves their score. Switch the order of the two calls inside there and it should work.

You should also use %client.setScore($ss::client[%id]); in the gameConnection::loadScore function.
« Last Edit: August 08, 2012, 01:42:54 PM by TripNick »

First, you should probably check %killer's score on death that way they're kicked for freekilling, not freekilling then dying.

As for your actual problem,
Code: [Select]
function GameConnection::onClientLeaveGame(%client)
{
   Parent::onClientLeaveGame(%client);
   %client.savScore(%client);
}
You're basically saying "Leave the game, then save their score." which, if you think about it, doesn't make any sense. The client will be gone by the time it saves their score. Switch the order of the two calls inside there and it should work.

You should also use %client.setScore($ss::client[%id]); in the gameConnection::loadScore function.

I used your suggestions now. This is what it looks like:
It still doesn't work.

package ss
{
   function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
   {
      %client.GameConnection::savScore(%client);
      Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);   
      if (%killer.score < -100)
         %killer.delete("You have been kicked because of excessive freekilling.");
                if (%client.score < -100)
                        %client.delete("You have been kicked because of excessive freekilling.");
   }
   
   function GameConnection::savScore(%client)
   {
      %id = %client.bl_id;
      $ss::client[%id] = %client.score; //example: $ss::client30621 = 10
   }
   
   function GameConnection::onPlayerSpawn(%client)
   {
      Parent::onPlayerSpawn(%client);
      %client.GameConnection::loadScore(%client);
   }
   function Gameconnection::loadScore(%client)
   {
      %id = %client.bl_id;
      %client.setScore($ss::client[%id]);
   }
   function GameConnection::onClientLeaveGame(%client)
   {
      Parent::onClientLeaveGame(%client);
      %client.GameConnection::savScore(%client);
   }
};
activatePackage(ss);
   
« Last Edit: August 08, 2012, 02:53:56 PM by hammereditor² »

I used your suggestions now. This is what it looks like:
It still doesn't work.
function GameConnection::onClientLeaveGame(%client)
{
   Parent::onClientLeaveGame(%client);
   %client.GameConnection::savScore(%client);
}

Make this
Code: [Select]
function GameConnection::onClientLeaveGame(%client)
{
%client.savScore(%client);
Parent::onClientLeaveGame(%client);
}
Like I said in my first post. Also, by gameConnection::savScore that means call it using %client.savScore(). gameConnection is just the class, you don't include that in your script besides when declaring a function.

Now that was why I had so many syntax errors after applying the gameconnection thing!
Thank you for your help a lot. If there is another problem, I'll tell you. The code now is:


package ss
{
   function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
   {
      %client.saveScore(%client);
      Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);
      
      if (%killer.score < -100)
         messageAll('',"Client " @ %client.name @ " has been kicked because of excessive freekilling.");
         %killer.delete("You have been kicked because of excessive freekilling.");   
      if (%client.score < -100)
         messageAll('',"Client " @ %client.name @ " has been kicked because of excessive freekilling.");
         %client.delete("You have been kicked because of excessive freekilling.");

   }
   
   function GameConnection::saveScore(%client)
   {
      %id = %client.bl_id;
      $ss::client[%id] = %client.score; //example: $ss::client30621 = 10
   }
   
   function GameConnection::onPlayerSpawn(%client)
   {
      Parent::onPlayerSpawn(%client);
      %client.loadScore(%client);
   }
   function GameConnection::loadScore(%client)
   {
      %id = %client.bl_id;
      %client.setScore($ss::client[%id]);
   }
   function GameConnection::onClientLeaveGame(%client)
   {
      %client.saveScore(%client);
      Parent::onClientLeaveGame(%client);
   }
};
activatePackage(ss);

It had no syntax errors but it still didn't work, so I echoed the score for my ID, and it was 0. So now this is the code:

package ss
{
   function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
   {
      %id = %client.bl_id;
      $ss::client[%id] = %client.score;
      Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);
      if(%killer.target != %client.name && %client.target != %killer.name)
         messageClient('',"Your killer, " @ %killer.name @ " , has freekilled you and lost 10 points.");
      
      if (%killer.score < -100)
         messageAll('',"Client " @ %client.name @ " has been kicked because of excessive freekilling.");
         %killer.delete("You have been kicked because of excessive freekilling.");   
      if (%client.score < -100)
         messageAll('',"Client " @ %client.name @ " has been kicked because of excessive freekilling.");
         %client.delete("You have been kicked because of excessive freekilling.");

   }
   
   function GameConnection::onPlayerSpawn(%client)
   {
      Parent::onPlayerSpawn(%client);
      %id = %client.bl_id;
      %client.setScore($ss::client[%id]);
   }
   
   function GameConnection::onClientLeaveGame(%client)
   {
      %id = %client.bl_id;
      $ss::client[%id] = %client.score;
      Parent::onClientLeaveGame(%client);
   }
};
activatePackage(ss);

You can put your code inbetween [code][/code] tags to conserve pagespace and get a cool grey box around it

You can put your code inbetween [code][/code] tags to conserve pagespace and get a cool grey box around it

Ok but that doesn't solve my problem.

Ok but that doesn't solve my problem.
But it does solve our problem of reading your code.

Just saying, you shouldn't waste your time on this. Danny Boy has a Score-Saving script in the RTB Holding Tank right now, I use it on my server and it works fine. There's also a command to reset all scores, if you're too lazy to go into config and reset it yourself. Keep looking for it, it's been in the Holding Tank a while...it should pop up sometime soon.

Just saying, you shouldn't waste your time on this. Danny Boy has a Score-Saving script in the RTB Holding Tank right now, I use it on my server and it works fine. There's also a command to reset all scores, if you're too lazy to go into config and reset it yourself. Keep looking for it, it's been in the Holding Tank a while...it should pop up sometime soon.

ok thx for telling me

   function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
   {
      %id = %client.bl_id;
      $ss::client[%id] = %client.score;
      Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);
      if(%killer.target != %client.name && %client.target != %killer.name)
         messageClient('',"Your killer, " @ %killer.name @ " , has freekilled you and lost 10 points.");
      
      if (%killer.score < -100)
         messageAll('',"Client " @ %client.name @ " has been kicked because of excessive freekilling.");
         %killer.delete("You have been kicked because of excessive freekilling.");   
      if (%client.score < -100)
         messageAll('',"Client " @ %client.name @ " has been kicked because of excessive freekilling.");
         %client.delete("You have been kicked because of excessive freekilling.");

   }
so when somebody is killed, the killer and the killed are checked if they have less than -100 points, if they do the server does the message then the person is kicked regardless of the points?
seems like it should only do the message and kicking if they have more than 100 points

its supposed to both save scores and manage freekilling