Author Topic: Burning / Damage over time  (Read 1727 times)

I am trying to make a damage over time script, here is what I have so far... It doesn't work so  if you have any suggestions please tell me them, Thanks in advance.

Code: [Select]
Function FireCurseImage::onCollision(%this, %obj, %col, %fade, %pos, %normal, %client)
{
%col.client.player.schedule(1000, "burn");
%col.client.player.schedule(2000, "burn");
%col.client.player.schedule(3000, "burn");
%col.client.player.schedule(4000, "burn");
%col.client.player.schedule(5000, "burn");
Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal, %client)
}

function Burn(%client)
{
if(%client.player.getDamageLevel() <= 85)
{
%client.player.applyDamage(10);
}
}


Console:
« Last Edit: April 26, 2008, 12:09:31 PM by Dr Bling »

I am trying to make a damage over time script, here is what I have so far... It doesn't work so  if you have any suggestions please tell me them, Thanks in advance.

Code: [Select]
Function FireCurseImage::onCollision(%this, %obj, %col, %fade, %pos, %normal, %client)
{
%col.client.player.schedule(1000, "burn");
%col.client.player.schedule(2000, "burn");
%col.client.player.schedule(3000, "burn");
%col.client.player.schedule(4000, "burn");
%col.client.player.schedule(5000, "burn");
Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal, %client)
}

function Burn(%client)
{
if(%client.player.getDamageLevel() <= 85)
{
%client.player.applyDamage(10);
}
}
Several problems: You are calling [object].burn, which calls Player::burn for a fire effect instead of the damage function.
Function 'burn' is a very generic name and could be used by other Add-Ons and overwritten...
The function is using a client (%client) but you are sending it a player object. (%col.client.player)
Lots of schedules at once are bad... Try a constant server-wide schedule like SpaceTick?

This should fix most problems but there still may be lag if several people use them at once. It also makes the player emit smoke.

Code: [Select]
Function FireCurseImage::onCollision(%this, %obj, %col, %fade, %pos, %normal, %client)
{
        cancel(%this.fireBurn);
%col.fireBurn(85,0,1);
Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal, %client)
}

function Player::fireBurn(%this,%max,%num,%burnFX)
{
        if(!isObject(%this))
         return;
if(%num <= %max)
{
%this.applyDamage(1);
         %this.fireBurn = %this.schedule(100,0,fireBurn,%max,%num+1,0);
         if(%burnFX){%this.burn(%num*100);}
}
}

Thanks for the better code :). But, it still shows the line 307 error which seems unrelated to either of our codes?

missing a semicolon after
Parent::onCollision([...]);

Also, "Function" is capitalised in both FireCurseImage::onCollision functions, which may cause a problem. If changing both of those doesn't fix it, I might need to see the code to do with the state system part above that.

I did both of those, so far no errors, just waiting for someone to come to my server and test.

Still doesn't work Heres the whole weapon

Code: [Select]
//FireCurse.cs

//audio
datablock AudioProfile(FireCurseHitSound)
{
   filename    = "./sound/FireCurse.wav";
   description = AudioClose3d;
   preload = true;
};

//muzzle flash effects
datablock ParticleData(FireCurseFlashParticle)
{
dragCoefficient      = 3;
gravityCoefficient   = -0.5;
inheritedVelFactor   = 0.2;
constantAcceleration = 0.0;
lifetimeMS           = 25;
lifetimeVarianceMS   = 15;
textureName          = "base/data/particles/star1";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0]     = "1.0 0.5 0.0 0.5";
colors[1]     = "1.0 1.0 1.0 0.5";
sizes[0]      = 0.5;
sizes[1]      = 1.0;

useInvAlpha = false;
};
datablock ParticleEmitterData(FireCurseFlashEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 1.0;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "FireCurseFlashParticle";
};

//Fire Curse trail effects
datablock ParticleData(FireCurseTrailParticle)
{
dragCoefficient      = 3;
gravityCoefficient   = -0.0;
inheritedVelFactor   = 1.0;
constantAcceleration = 0.0;
lifetimeMS           = 250;
lifetimeVarianceMS   = 55;
textureName          = "base/data/particles/fire";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0]     = "1.0 0.5 0.0 0.5";
colors[1]     = "1.0 1.0 1.0 0.5";
sizes[0]      = 1.00;
sizes[1]      = 0.50;

useInvAlpha = false;
};


datablock ParticleEmitterData(FireCurseTrailEmitter)
{
   ejectionPeriodMS = 5;
   periodVarianceMS = 0;
   ejectionVelocity = 0.0;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "FireCurseTrailParticle";
};


datablock ParticleData(FireCurseExplosionParticle)
{
dragCoefficient      = 8;
gravityCoefficient   = -0.5;
inheritedVelFactor   = 0.2;
constantAcceleration = 0.0;
lifetimeMS           = 700;
lifetimeVarianceMS   = 400;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -50.0;
spinRandomMax = 50.0;
colors[0]     = "1.0 1.0 1.0 0.5";
colors[1]     = "1.0 0.5 0.0 0.5";
sizes[0]      = 2.5;
sizes[1]      = 5.0;
useInvAlpha = true;
};
datablock ParticleEmitterData(FireCurseExplosionEmitter)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 1.0;
   ejectionOffset   = 0.0;
   thetaMin         = 89;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "FireCurseExplosionParticle";
};

datablock ExplosionData(FireCurseExplosion)
{
   //explosionShape = "";
soundProfile = FireCurseHitSound;

   lifeTimeMS = 150;

   particleEmitter = FireCurseExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   emitter[0] = FireCurseExplosionRingEmitter;

   faceViewer     = true;
   explosionScale = "1 1 1";

   shakeCamera = false;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "1.0 1.0 1.0";
   camShakeDuration = 0.5;
   camShakeRadius = 10.0;

   // Dynamic light
   lightStartRadius = 0;
   lightEndRadius = 2;
   lightStartColor = "1.0 0.5 0.0";
   lightEndColor = "0 0 0";

};


AddDamageType("FireCurse",   '<bitmap:add-ons/ci/FireCurse> %1',    '%2 <bitmap:add-ons/ci/FireCurse> %1',0.5,1);
datablock ProjectileData(FireCurseProjectile)
{
   projectileShapeName = "./shapes/empty.dts";
   directDamage        = 5;
   directDamageType    = $DamageType::FireCurse;
   radiusDamageType    = $DamageType::FireCurse;

   brickExplosionRadius = 0;
   brickExplosionImpact = true;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 10;
   brickExplosionMaxVolume = 1;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 2;  //max volume of bricks that we can destroy if they aren't connected to the ground

   impactImpulse   = 0;
   verticalImpulse   = 0;
   explosion           = FireCurseExplosion;
   particleEmitter     = FireCurseTrailEmitter;

   muzzleVelocity      = 90;
   velInheritFactor    = 1;

   armingDelay         = 00;
   lifetime            = 4000;
   fadeDelay           = 3500;
   bounceElasticity    = 0.5;
   bounceFriction      = 0.20;
   isBallistic         = false;
   gravityMod = 0.0;

   hasLight    = true;
   lightRadius = 3.0;
   lightColor  = "1.0 0.5 0.0";

};

//////////
// item //
//////////
datablock ItemData(FireCurseItem)
{
category = "Weapon";  // Mission editor category
className = "Weapon"; // For inventory system

// Basic Item Properties
shapeFile = "base/data/shapes/wand.dts";
rotate = false;
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;

//gui stuff
uiName = "Fire Curse";
iconName = "base/client/ui/ItemIcons/wand";
doColorShift = true;
colorShiftColor = "1.0 0.5 0.0 1.000";

// Dynamic properties defined by the scripts
image = FireCurseImage;
canDrop = true;
};


////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(FireCurseImage)
{
   // Basic Item properties
   shapeFile = "base/data/shapes/wand.dts";
   emap = true;

   // Specify mount point & offset for 3rd person, and eye offset
   // for first person rendering.
   mountPoint = 0;
   offset = "0 0 0";
   eyeOffset = 0; //"0.7 1.2 -0.5";
   rotation = eulerToMatrix( "0 0 0" );

   // When firing from a point offset from the eye, muzzle correction
   // will adjust the muzzle vector to point to the eye LOS point.
   // Since this weapon doesn't actually fire from the muzzle point,
   // we need to turn this off. 
   correctMuzzleVector = true;

   // Add the WeaponImage namespace as a parent, WeaponImage namespace
   // provides some hooks into the inventory system.
   className = "WeaponImage";

   // Projectile && Ammo.
   item = BowItem;
   ammo = " ";
   projectile = FireCurseProjectile;
   projectileType = Projectile;

casing = FireCurseShellDebris;
shellExitDir        = "1.0 -1.3 1.0";
shellExitOffset     = "0 0 0";
shellExitVariance   = 15.0;
shellVelocity       = 7.0;

   //melee particles shoot from eye node for consistancy
   melee = false;
   //raise your arm up or not
   armReady = true;

   doColorShift = true;
   colorShiftColor = FireCurseItem.colorShiftColor;//"0.400 0.196 0 1.000";

   //casing = " ";

   // Images have a state system which controls how the animations
   // are run, which sounds are played, script callbacks, etc. This
   // state system is downloaded to the client so that clients can
   // predict state changes and animate accordingly.  The following
   // system supports basic ready->fire->reload transitions as
   // well as a no-ammo->dryfire idle state.

   // Initial start up state
stateName[0]                     = "Activate";
stateTimeoutValue[0]             = 0.15;
stateTransitionOnTimeout[0]       = "Ready";
stateSound[0] = weaponSwitchSound;

stateName[1]                     = "Ready";
stateTransitionOnTriggerDown[1]  = "Fire";
stateAllowImageChange[1]         = true;
stateSequence[1] = "Ready";

stateName[2]                    = "Fire";
stateTransitionOnTimeout[2]     = "Smoke";
stateTimeoutValue[2]            = 0.14;
stateFire[2]                    = true;
stateAllowImageChange[2]        = false;
stateSequence[2]                = "Fire";
stateScript[2]                  = "onFire";
stateWaitForTimeout[2] = true;
stateEmitter[2] = FireCurseFlashEmitter;
stateEmitterTime[2] = 0.05;
stateEmitterNode[2] = "muzzleNode";
stateSound[2] = FireCurseSound;
stateEjectShell[2]       = true;

stateName[3] = "Smoke";
stateEmitter[3] = FireCurseSmokeEmitter;
stateEmitterTime[3] = 0.05;
stateEmitterNode[3] = "muzzleNode";
stateTimeoutValue[3]            = 0.01;
stateTransitionOnTimeout[3]     = "Reload";

stateName[4] = "Reload";
stateSequence[4]                = "Reload";
stateTransitionOnTriggerUp[4]     = "Ready";
stateSequence[4] = "Ready";

};

function FireCurseImage::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{
        cancel(%this.fireBurn);
%col.fireBurn(85,0,1);
Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal);
}

function Player::fireBurn(%this,%max,%num,%burnFX)
{
        if(!isObject(%this))
         return;
if(%num <= %max)
{
%this.applyDamage(1);
          %this.fireBurn = %this.schedule(100,0,fireBurn,%max,%num+1,0);
          if(%burnFX){%this.burn(%num*100);}
}
}

function FireCurseImage::onFire(%this,%obj,%slot)
{
%obj.playthread(2, armattack);
%obj.playThread(2, shiftAway);
%nrg = %obj.getEnergyLevel();
if(50 <= %nrg) {
%obj.setEnergyLevel(%nrg - 50);
commandtoClient(%obj.client,'bottomprint',"<just:center> \c6 Energy:[" @ mFloor(%obj.getEnergyLevel()) @ "/" @ %obj.getDataBlock().maxenergy @ "]",2);
}
else {
commandtoClient(%obj.client,'bottomprint',"<just:center> \c6 Not Enough Energy:[" @ mFloor(%nrg) @"/"@ %obj.getDataBlock().maxenergy @"]",2);
return;
}
Parent::onFire(%this, %obj, %slot);
}


These are the syntax errors i see...

Make sure you're not using undefined stuff in your code.
I see problems here:
Code: [Select]
datablock ExplosionData(FireCurseExplosion)
{
   ...
   emitter[0] = FireCurseExplosionRingEmitter; // Should be: FireCurseExplosionEmitter
   ...
};

And here:
Code: [Select]
datablock ShapeBaseImageData(FireCurseImage)
{
   ...
   casing = FireCurseShellDebris; // This does not exist...
   ...
   stateEmitter[3] = FireCurseSmokeEmitter; // This does not exist...
   ...
};

Make sure AudioClose3d exists:
Code: [Select]
datablock AudioProfile(FireCurseHitSound)
{
   ...
   description = AudioClose3d; // I don't have this audio description
   ...
};

Make sure empty.dts exists:
Code: [Select]
datablock ProjectileData(FireCurseProjectile)
{
   ...
   projectileShapeName = "./shapes/empty.dts"; // I don't have empty.dts
   ...
};
« Last Edit: April 26, 2008, 03:19:28 PM by exidyne »

...

function FireCurseProjectile::onCollision(%this, %obj, %col, %fade, %pos, %normal)
{
        if(!isObject(%col) || (%col.getclassname() !$= "Player" && %col.getclassname() !$= "AIPlayer"))
         return;

        cancel(%col.fireBurn);
   %col.fireBurn(10,85,0,1);
   Parent::onCollision(%this, %obj, %col, %fade, %pos, %normal);
}

function Player::fireBurn(%this,%dps,%max,%num,%burnFX)
{
        if(!isObject(%this))   
         return;
   if(%num <= %max)
   {
      %this.applyDamage((%dps/10));
            %this.fireBurn = %this.schedule(100,0,fireBurn,%max,%num+(%dps/10),0);
            if(%burnFX){%this.burn(%num*100);}
   }
}

...

Fixed. Replace the two functions with that. (Leave the rest of the file)
Bold = changed.

The function:
Player::fireBurn(Damage Per Second,Total Damage,[Leave This As 0, Counter Variable],Burn Effect On Player);

So:
%col.fireBurn(10,85,0,1);
damages you for 8.5 seconds, causing 85 damage, and "burns" you.

Warning - while you were typing a new reply has been posted. You may wish to review your post.

... Also fix what exidyne said.
« Last Edit: April 26, 2008, 03:37:41 PM by Space Guy »

...
function Player::fireBurn(%this,%dps,%max,%num,,%burnFX)
...
Typo
« Last Edit: April 26, 2008, 03:21:20 PM by exidyne »


Quote
function Player::fireBurn(%this,%dps,%max,%num,%burnFX)
{
        if(!isObject(%this))   
         return;
   if(%num <= %max)
   {
      %this.applyDamage((%dps/10));
            %this.fireBurn = %this.schedule(100,0,fireBurn,%max,%num+(%dps/10),0);
            if(%burnFX){%this.burn(%num*100);}
   }
}

That line should be:
Code: [Select]
%this.fireBurn = %this.schedule(100, fireBurn, %max, %num + (%dps/10), 0);