Author Topic: Help Cleaning up code *solved*  (Read 540 times)

exec("./Support_SpecialKills.cs");

addSpecialDamageMsg("Burned","%2%3%1","%4 Burned %5%1");

datablock ParticleData(BurningParticle)
{
textureName            = "base/data/particles/cloud";
dragCoefficient         = 0.0;
gravityCoefficient      = -1.0;
inheritedVelFactor      = 0.0;
windCoefficient         = 0;
constantAcceleration   = 3.0;
lifetimeMS            = 1200;
lifetimeVarianceMS      = 100;
spinSpeed            = 0;
spinRandomMin         = -90.0;
spinRandomMax         =  90.0;
useInvAlpha            = false;
      
colors[0]   = "1.0 1.0 0.3 0.0";
colors[1]   = "1.0 1.0 0.3 1.0";
colors[2]   = "0.6 0.0 0.0 0.0";
      
sizes[0]   = 0.0;
sizes[1]   = 2.0;
sizes[2]   = 1.0;
      
times[0]   = 0.0;
times[1]   = 0.2;
times[2]   = 0.9;
};


datablock ParticleEmitterData(BurningEmitter)
{
ejectionPeriodMS   = 5;
periodVarianceMS   = 4;
ejectionVelocity   = 0;
ejectionOffset      = 1.00;
velocityVariance   = 0.0;
thetaMin         = 30;
thetaMax         = 90;
phiReferenceVel      = 0;
phiVariance         = 360;
overrideAdvance      = false;
      
particles = BurningParticle;  
};
datablock ShapeBaseImageData(PlayerNapalmBurnImage)
{
shapeFile = "base/data/shapes/empty.dts";
emap = false;

mountPoint = $HeadSlot;
offset = "0 -0.5 -1";

stateName[0]            = "Ready";
stateTimeoutValue[0]      = 0.01;
stateTransitionOnTimeout[0]   = "FireA";

stateName[1]            = "FireA";
stateEmitter[1]            = BurningEmitter;
stateEmitterTime[1]         = 0.9;
stateTimeoutValue[1]      = 0.9;
stateTransitionOnTimeout[1]   = "Done";
stateWaitForTimeout[1]      = true;

stateName[2]            = "Done";
stateTimeoutValue[2]      = 0.01;
stateTransitionOnTimeout[2]   = "FireA";
};

function BurnPlayer(%Obj,%BurnLoops,%Attacker)
{
   if(!isObject(%Obj))
   return;
   if(!%BurnLoops)
   return;
%BurnLoops--;
%Obj.mountImage(PlayerNapalmBurnImage,1);
%HealthSap = getRandom(2,10);

if(%obj.lastAttacker != %Attacker)
   {
   %obj.lastAssistAttacker = %obj.lastAttacker;
   %obj.lastAttacker = %Attacker;
   }

%Obj.AddHealth(%HealthSap/-1);
   if(%BurnLoops > 0)
   schedule(800, 0, BurnPlayer, %Obj, %BurnLoops);
   else
   %Obj.unmountImage(1);
}

package BurnExplosions
{
      function player::damage(%obj, %sourceObject, %pos, %amount, %type)
      {
   %Attacker = %sourceObject.client;
   
         if($damage::direct[%type] == 0)
         {
      %a = getRandom(2,2);
         if(!%Obj.BurnLoops && %a == 2 && %amount < %obj.getDatablock().maxDamage && %amount > 1)
         {
         %obj.lastAssistDamageType = %damageType;
         %obj.lastAssistDamageTime = getSimTime();

         %Obj.BurnLoops = getRandom(2,10);
         BurnPlayer(%Obj,%Obj.BurnLoops,%Attacker);
         }
      }
    
      parent::Damage(%obj, %sourceObject, %pos, %amount, %type);
      }
};
activatePackage(BurnExplosions);
 
function isSpecialKill_Burned(%this,%sourceObject,%sourceClient,%mini)
{
   %obj = %this.player;
   if(isObject(%obj.lastAssistAttacker) && %obj.lastAssistAttacker != %sourceClient && (getSimTime() - %obj.lastAssistDamageTime) < 10000)
   {
      %obj.lastAssistAttacker.incScore(%mini.Points_KillPlayer);
      
      if(%obj.lastAssistAttacker.isSpaceBotAI)
         %name = %obj.lastAssistAttacker.getBotName();
      else
         %name = %obj.lastAssistAttacker.getPlayerName();
      
      if(%name $= "")
         return 0;
      if(!isObject(%sourceObject.client) || %sourceObject.client == %this)
      {
         %msg = getTaggedString($DeathMessage_Murder[%obj.lastAssistDamageType]);
         %msg = strReplace(%msg,"%2 ","");
         %msg = strReplace(%msg,"%2 ","");
         
         %pos1 = strPos(%msg,"%1");
         %ciString = getSubStr(%msg,0,%pos1);
         
         return 2 TAB %name TAB %cistring;
      }
      
      if(%obj.lastAssistAttacker != %obj.lastAttacker)
         return 2 TAB %name;

   }
   return 0;
}



The main problem is I don't know how to use special kills
I get messages saying this every time the "Burned" Special kill occurs

getSubStr(...): error, starting position and desired length must be >= 0: ("",0, -1)
BackTrace: ->BurnPlayer->Player::AddHealth->[BurnExplosions]Player::Damage->ShapeBase::Damage->armor::Damage->[SpecialKills]GameConnection::onDeath->isSpecialKill_Burned
« Last Edit: February 12, 2012, 12:12:45 AM by swollow »

For future reference, please post code in the code tags unless it's a few lines. It honestly does make it easier to read.

         %pos1 = strPos(%msg,"%1");
         %ciString = getSubStr(%msg,0,%pos1);

This is the area that's causing an issue. I would recommend something like:
Code: [Select]
        %pos1 = strPos(%msg,"%1");
         if(%pos1 >= 0)
                  %ciString = getSubStr(%msg,0,%pos1);
This does appear to damage the functionality of the function though. It's there for a reason, and this is just circumventing the error. Something tells me it's not used.