Author Topic: Return and Else Scripts  (Read 1336 times)

Hey, I was working on something for my City RPG and this problem came along. It seems as if I'm doing the else part wrong.
Code: [Select]
function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
{
Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);

if (!%client.isAdmin)
return;
// Message about Stats
messageClient('', "<color:ffffff>Your stats have been preserved because you are admin.");
%client.RPData.value["tools"] = "";
else;##
                ##
// Lose tools and Clear Stats
if (isObject(%client) && %client.isInRP())
return;
%client.RPData.value["tools"] = "";
%client.RPData.clear();
}
Obviously the ## is where the problem starts and ends. Thanks for reading!

Code: [Select]
function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
{
Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);

if (!%client.isAdmin)
return;
// Message about Stats
messageClient('', "<color:ffffff>Your stats have been preserved because you are admin.");
%client.RPData.value["tools"] = "";
// Lose tools and Clear Stats
if (isObject(%client) && %client.isInRP())
return;
%client.RPData.value["tools"] = "";
%client.RPData.clear();
}
Fixed, now tell me what I changed.

Oh no, not another cityrpg! Lol..

Actually I've had this City RPG. Also, thanks for the code fix!

Code: [Select]
function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
{
Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);

if (!%client.isAdmin)
return;
// Message about Stats
messageClient('', "<color:ffffff>Your stats have been preserved because you are admin.");
%client.RPData.value["tools"] = "";
// Lose tools and Clear Stats
if (isObject(%client) && %client.isInRP())
return;
%client.RPData.value["tools"] = "";
%client.RPData.clear();
}
Fixed, now tell me what I changed.

Well see, I want the if(isObject) part to be non admin. So if you fixed that, thanks. But we are working on preventing admins from clearing their stats when they die.

Why did you have a random else in the middle of your code with no IF block before it?

Oh no, not another cityrpg! Lol..
I know rite? Learning how to script is so horrible.

function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
   {
      Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);
      
      if (!%client.isAdmin)
      return;

      // Message about Stats
      messageClient('', "<color:ffffff>Your stats have been preserved because you are admin.");
      %client.RPData.value["tools"] = "";
      else;##
                ##
      // Lose tools and Clear Stats
      if (isObject(%client) && %client.isInRP())
      return;
      %client.RPData.value["tools"] = "";
      %client.RPData.clear();
   }

I wanted the bold parts to tie together. Like ifTrue and ifFalse

You should put a brace after the if, then put in the admin messageclient, then the return, then close the brace. You won't need an else, because it's redundant in this case.

Code: [Select]
function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
   {
      Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);
     
      if (%client.isAdmin)
      {
             // Message about Stats
             messageClient('', "<color:ffffff>Your stats have been preserved because you are admin.");
             %client.RPData.value["tools"] = "";
             return;
      }
      // Lose tools and Clear Stats
      if (isObject(%client) && %client.isInRP())
      return;
      %client.RPData.value["tools"] = "";
      %client.RPData.clear();
   }
done

Turn that last statement into !blah || !stuff and it will be good to go I think.

The if admin statement?

No, the isObject one.

Due to my fail scripting skills, can't tell if serious... or sarcastic...

Thanks for all your help lugnut and ipquarx!

Edit 1: Credit has been given and it is functioning perfectly, thanks so much!
« Last Edit: June 09, 2012, 11:37:11 PM by Gordo12699 »

New Problem; Even if they aren't admin, they don't lose their stats. There is nothing wrong with the clearing script, it's something with the admin part. I'm aiming for admins not to lose stats, but non-admins do. Heres the code I have:

Code: [Select]
// When the players gets killed
function GameConnection::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc)
   {
      Parent::onDeath(%client, %killerPlayer, %killer, %damageType, %damageLoc);
     
      if (%client.isAdmin)
      {
             // Message about Stats
             messageClient('', "<color:ffffff>Your stats have been preserved because you are admin.");
             %client.RPData.value["tools"] = "";
             return;
      }
      // Lose tools and Clear Stats
      if (isObject(%client) && %client.isInRP())
      return;
      %client.RPData.value["tools"] = "";
      %client.RPData.clear();
   }

There is no Syntax.