Game Development Community

Player dies immediately from onEnterLiquid / setDamageDt script

by Mark Owen · in Torque Game Engine · 02/06/2004 (11:17 am) · 1 replies

I noticed that onEnterLiquid doesn't correctly call setDamageDt with the result being that if your player enters one of its known types of liquids you die immediately. Chasing it down I determined that the problem was that in ~/server/scripts/player.cs the function onEnterLiquid is passing one too many parameters to setDamageDt (which does not take four paramters). In addition the ShapeBase::setDamageDt function was attempting to use an uninitialized local named %obj to call things, when it should have been using %this.

To remedey these problems:

in ~/server/scripts/player.cs Armor::onEnterLiquid change the calls of %obj.setDamageDt(%this, ...) to %obj.setDamageDt(...).

the result should look like:
function Armor::onEnterLiquid(%this, %obj, %coverage, %type)
{
   switch(%type)   {
      case 0: //Water
      case 1: //Ocean Water
      case 2: //River Water
      case 3: //Stagnant Water
      case 4: //Lava
         %obj.setDamageDt($DamageLava, "Lava");
      case 5: //Hot Lava
         %obj.setDamageDt($DamageHotLava, "Lava");
      case 6: //Crusty Lava
         %obj.setDamageDt($DamageCrustyLava, "Lava");
      case 7: //Quick Sand
   }
}
in ~/server/scripts/ShapeBase.cs ShapeBase::setDamageDt and ShapeBase::clearDamageDt
replace all occurances of %obj with %this.

the result should look like:

function ShapeBase::setDamageDt(%this, %damageAmount, %damageType)
{
   // This function is used to apply damage over time.  The damage
   // is applied at a fixed rate (50 ms).  Damage could be applied
   // over time using the built in ShapBase C++ repair functions
   // (using a neg. repair), but this has the advantage of going
   // through the normal script channels.
   if( %this.getState() !$= "Dead" ) {
      %this.damage(0, "0 0 0", %damageAmount, %damageType);
      %this.damageSchedule = %this.schedule(50, "setDamageDt", %damageAmount, %damageType);
   }
   else
      %this.damageSchedule = "";
}

function ShapeBase::clearDamageDt(%this)
{
   if( %this.damageSchedule !$= "" ) {
      cancel(%this.damageSchedule);
      %this.damageSchedule = "";
   }
}

After these changes are made, if your player enters one of the liquid areas defined damage will be accumulated over time correctly.