Author Topic: Player Can Take Critical Hits Problem  (Read 436 times)

I have a problem with the event when the player can take critical hits when the CriticalHit is checked. The event executed, but nothing happens. Can anyone help?

Code: [Select]
package CTC
{
function fxDTSBrick::CriticalHits(%obj, %this, %ya)
{
  if(isObject(%this))
  {
   %obj.CanTakeCriticals = %ya;
   PCTC();
  }
}
};
activatepackage(CTC);

package CriticalEvents
{
function PCTC()
{
   if(%obj.CanTakeCriticals == 1)
   {
   CriticalHit();
   }
   else
   {
%client.chatmessage("<color:FF0000>ERROR<color:FFFFFF>: You can not take criticals!");
   }
}

function CriticalHit(%this,%obj,%damage)
{
if(%obj.CanTakeCriticals == 1)
{
%colScale = getWord(%col.getScale(), 2);
if(isObject(%col))
{
%damage = %this.directDamage * 10 - %this.directDamage;
%damageType = $DamageType::Direct;
if(%this.directDamageType)
{
%damageType = %this.directDamageType;
%col.spawnExplosion(critProjectile,%colScale);
%col.client.play2d(critRecieveSound);
serverplay3d( critRecieveSound ,%pos);
}
%col.damage(%obj,%pos,%damage,%damageType);
}
}
}
};
activatepackage(CriticalEvents);

registerOutputEvent(fxDTSBrick, "CriticalHits", bool, 0);

Listing off any problem I see, from minor to major:

- Don't use acronyms for identifiers unless it's extremely obvious what it means. I have no idea what CTC and PCTC mean.
- %ya isn't a very good name
- You're calling the PCTC function every time the event is called. If the code worked correctly I believe you would take critical damage every time you set the player as being able or unable to take crits. You want to package Armor::onDamage (or is it Player::onDamage?) instead, so that critical hits are calculated when the player actually takes damage
- I think this event will end up setting the brick as critable rather than the player
- Many variables used within the PCTC (%obj) and CriticalHit (%this, %obj, %col, %pos) are never defined. Many of these are due to not passing arguments to the function
- CriticalHit function: use the name %this for methods (functions in the format ClassName::FunctionName)
- The %damage argument in the function CriticalHit (if it was being passed) is never used, rather it's defined later on inside the function
- The package name in the activatePackage function call is different than the package you defined
« Last Edit: December 19, 2012, 08:41:50 PM by Headcrab Zombie »

- The package name in the activatePackage function call is different than the package you defined
He has two packages, CTC and CriticalEvents. They're both activated seperately, and correctly as far as I can see.

He has two packages, CTC and CriticalEvents. They're both activated seperately, and correctly as far as I can see.
Oh I see that now.
I think not indenting everything in the package being indented through me off.

CTC means CanTakeCriticals and PCTC is PlayerCanTakeCriticals