Author Topic: Set Damage or Damage Percentile?  (Read 1060 times)

I need to find out what I need to put in my script as a function to change the percent of damage the projectile does.
I'm trying to get it so if it winds up in a different state, it does different damage.
Can someone possible make me a simple function to set the damage percent?
« Last Edit: August 10, 2009, 12:55:08 AM by Azerath »

Just use stateScripts for the states to set a state variable on the player, then on fire, use a stateScript to spawn the projectile then put a variable on the projectile. Then mess with projectileDatablock::Damage(%this, %obj, %col, %fade, %pos, %normal) to get the desired effect, keeping in mind that %obj is the projectile.

Truthfully, I have no idea how to script that. I really only know how to mess with values, change the states, and others things, but the functions and such are very confusing.

I'm trying just to make a function at the end of the script so it can be used in the state to change the percentile, but I have no idea how to.

function yourWeaponImage::onFire(%this, %obj, %slot)
{
   %vector = %obj.getMuzzleVector(%slot);
   %objectVelocity = %obj.getVelocity();
   %vector1 = VectorScale(%vector, %this.projectile.muzzleVelocity);
   %vector2 = VectorScale(%objectVelocity, %this.projectile.velInheritFactor);
   %velocity = VectorAdd(%vector1,%vector2);
   %mat = MatrixCreateFromEuler(0 SPC 0 SPC 0);
   %velocity = MatrixMulVector(%mat, %velocity);
   %p = new Projectile()
   {
      dataBlock = %this.projectile.getDatablock();
      initialVelocity = %velocity;
      initialPosition = %obj.getMuzzlePoint(%slot);
      sourceObject = %obj;
      state = %obj.yourVariableHere;
      client = %obj.client;
      sourceSlot = %slot;
   };
}

function yourProjectile::damage(%this, %obj, %col, %fade, %pos, %normal)
{
   if(strPos(%col.getClassName(), "Player") != -1)
   {
      %var = %obj.yourVariableHere;
      %amt = 100; //Do math stuff. %amt is the amount of damage that will be done
      %col.damage(%obj.sourceObject, %pos, %amt, $DamageType::YourDamageType);
   }
}


EDIT: Removed an extra semicolon after the closing bracket for projectile::damage
« Last Edit: August 10, 2009, 12:09:03 AM by Amade »

Variable, as in...?
And the state, I would just put the state name? Because I was thinking of just having the state say
Code: [Select]
stateScript =  onFireThen I would have a different state for a different percentile that would use onFire2 or something like that. Is that how this was made?
Maybe the function could just set the damage?

For some reason I can't understand that last post, but basically use stateScripts to set a variable on the player.

stateScript[5] = "script5";

Which would cause this:

function yourWeaponImage::script5(%this, %obj, %slot)
{
   //%this is the image, %obj is the player, %slot you don't need to worry about
   %obj.variable = number;
}


Then in the onFire stuff

switch(%obj.variable)
{
   case NUMBER: %amt = OTHER NUMBER;
   case ANOTHER NUMBER: %amt = YET ANOTHER NUMBER;
   default: %amt = NUMBER IF NONE OF THE CASES MATCH;
}
%p = new Projectile()
{
   ...
   var = %amt;
};

function yourWeaponImage::script5(%this, %obj, %slot)
{
   //%this is the image, %obj is the player, %slot you don't need to worry about
   %obj.variable = number;
}

So this will just set what the projectile's damage is?

Edit what's in red, pay close attention to what's in blue.

function YourWeaponImage::someRandomScriptName(%this, %obj, %slot)
{
   %obj.damageModifier = AMOUNT;
}

function YourWeaponImage::onFire(%this, %obj, %slot)
{
   %vector = %obj.getMuzzleVector(%slot);
   %objectVelocity = %obj.getVelocity();
   %vector1 = VectorScale(%vector, %this.projectile.muzzleVelocity);
   %vector2 = VectorScale(%objectVelocity, %this.projectile.velInheritFactor);
   %velocity = VectorAdd(%vector1,%vector2);
   %mat = MatrixCreateFromEuler(0 SPC 0 SPC 0);
   %velocity = MatrixMulVector(%mat, %velocity);

   %p = new Projectile()
   {
      dataBlock = %this.projectile.getDatablock();
      initialVelocity = %velocity;
      initialPosition = %obj.getMuzzlePoint(%slot);
      sourceObject = %obj;
      modifier = %obj.damageModifier;
      client = %obj.client;
      sourceSlot = %slot;
   };
}

function YourProjectile::Damage(%this, %obj, %col, %fade, %pos, %normal)
{
   if(strPos(%col.getClassName(), "Player") != -1)
   {
      %amount = %this.directDamage * %obj.modifier;
      %col.damage(%obj.sourceObject, %pos, %amount, $DamageType::YourDamageType);
   }
}


Ok, I'm not sure what the damage modifier would be, so I'm assuming I need to add it's own name which I did. I'm also guessing the amount is the percent of the damage already done. I input that stuff and now it just doesn't seem to do damage at all.
This is what I have put in.

I put the OnFire1, 2, 3 ,4 scripts on certain states, but it's not exactly working. I do believe I have made a slight error.
Quote
function Huntsman::OnFire1(%this, %obj, %slot)
{
   %obj.DamageAmmountHuntsman = 100;
}


function Huntsman::OnFire2(%this, %obj, %slot)
{
   %obj.DamageAmmountHuntsman = 200;
}


function Huntsman::OnFire3(%this, %obj, %slot)
{
   %obj.DamageAmmountHuntsman = 300;
}


function Huntsman::OnFire4(%this, %obj, %slot)
{
   %obj.DamageAmmountHuntsman = 400;
}

function Huntsman::onFire(%this, %obj, %slot)
{
   %vector = %obj.getMuzzleVector(%slot);
   %objectVelocity = %obj.getVelocity();
   %vector1 = VectorScale(%vector, %this.projectile.muzzleVelocity);
   %vector2 = VectorScale(%objectVelocity, %this.projectile.velInheritFactor);
   %velocity = VectorAdd(%vector1,%vector2);
   %mat = MatrixCreateFromEuler(0 SPC 0 SPC 0);
   %velocity = MatrixMulVector(%mat, %velocity);

   %p = new Projectile()
   {
      dataBlock = %this.projectile.getDatablock();
      initialVelocity = %velocity;
      initialPosition = %obj.getMuzzlePoint(%slot);
      sourceObject = %obj;
      modifier = %obj.DamageAmmountHuntsman;
      client = %obj.client;
      sourceSlot = %slot;
   };
}

function HuntsmanProjectile::Damage(%this, %obj, %col, %fade, %pos, %normal)
{
   if(strPos(%col.getClassName(), "Player") != -1)
   {
      %amount = %this.directDamage * %obj.modifier;
      %col.damage(%obj.sourceObject, %pos, %amount, $DamageType::HuntsmanDirect);
   }
}

You forgot to change this line
%amount = %this.directDamage * %obj.modifier;
to
%amount = %this.directDamage * %obj.damageAmountHuntsman;

Ok, I did that, but it still seems to be doing little damage.
So wait, if the function Onfire1, 2, 3, or 4 is used, it will just SET the damage amount until changed? or do I have to use it on the fire state?

Just post the entire script.

Quote
//Huntsman.cs
//bow and arrow weapon stuff

datablock AudioProfile(HuntsmanHitSound)
{
   filename    = "./arrowHit.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(HuntsmanFireSound)
{
   filename    = "./bowFire.wav";
   description = AudioClosest3d;
   preload = true;
};

datablock AudioProfile(HuntsmanPullSound)
{
   filename    = "./bowPull.wav";
   description = AudioClosest3d;
   preload = true;
};



//arrow trail
datablock ParticleData(HuntsmanTrailParticle)
{
   dragCoefficient      = 3.0;
   windCoefficient      = 0.0;
   gravityCoefficient   = 0.0;
   inheritedVelFactor   = 0.0;
   constantAcceleration   = 0.0;
   lifetimeMS      = 200;
   lifetimeVarianceMS   = 0;
   spinSpeed      = 10.0;
   spinRandomMin      = -50.0;
   spinRandomMax      = 50.0;
   useInvAlpha      = false;
   animateTexture      = false;
   //framesPerSec      = 1;

   textureName      = "base/data/particles/dot";
   //animTexName      = "~/data/particles/dot";

   // Interpolation variables
   colors[0]   = "0.7 0 0 0.4";
   colors[1]   = "0.7 0 0 0.0";
   sizes[0]   = 0.2;
   sizes[1]   = 0.01;
   times[0]   = 0.0;
   times[1]   = 1.0;
};

datablock ParticleEmitterData(HuntsmanTrailEmitter)
{
   ejectionPeriodMS = 2;
   periodVarianceMS = 0;

   ejectionVelocity = 0; //0.25;
   velocityVariance = 0; //0.10;

   ejectionOffset = 0;

   thetaMin         = 0.0;
   thetaMax         = 90.0; 

   particles = HuntsmanTrailParticle;

   useEmitterColors = true;
   uiName = "Huntsman Trail";
};

//effects
datablock ParticleData(HuntsmanStickExplosionParticl e)
{
   dragCoefficient      = 5;
   gravityCoefficient   = 0.1;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS           = 500;
   lifetimeVarianceMS   = 300;
   textureName          = "base/data/particles/chunk";
   spinSpeed      = 10.0;
   spinRandomMin      = -50.0;
   spinRandomMax      = 50.0;
   colors[0]     = "0.9 0.9 0.6 0.9";
   colors[1]     = "0.9 0.5 0.6 0.0";
   sizes[0]      = 0.25;
   sizes[1]      = 0.0;
};
datablock ParticleEmitterData(HuntsmanStickExplosionEmitter)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 80;
   thetaMax         = 80;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "HuntsmanStickExplosionParticl e";

   useEmitterColors = true;
   uiName = "Huntsman Stick";
};
datablock ExplosionData(HuntsmanStickExplosion)
{
   //explosionShape = "";
   soundProfile = HuntsmanHitSound;

   lifeTimeMS = 150;

   particleEmitter = HuntsmanStickExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   emitter[0] = "";

   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 = 1;
   lightStartColor = "0.3 0.6 0.7";
   lightEndColor = "0 0 0";
};



datablock ParticleData(HuntsmanExplosionParticle)
{
   dragCoefficient      = 8;
   gravityCoefficient   = -0.3;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS           = 500;
   lifetimeVarianceMS   = 300;
   textureName          = "base/data/particles/cloud";
   spinSpeed      = 10.0;
   spinRandomMin      = -50.0;
   spinRandomMax      = 50.0;
   colors[0]     = "0.5 0.5 0.5 0.9";
   colors[1]     = "0.5 0.5 0.5 0.0";
   sizes[0]      = 0.45;
   sizes[1]      = 0.0;

   useInvAlpha = true;
};
datablock ParticleEmitterData(HuntsmanExplosionEmitter)
{
   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 3;
   velocityVariance = 0.0;
   ejectionOffset   = 0.0;
   thetaMin         = 0;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "HuntsmanExplosionParticle";

   useEmitterColors = true;
   uiName = "Huntsman Vanish";
};
datablock ExplosionData(HuntsmanExplosion)
{
   //explosionShape = "";
   soundProfile = "";

   lifeTimeMS = 50;

   emitter[0] = HuntsmanExplosionEmitter;

   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 = 1;
   lightStartColor = "0.3 0.6 0.7";
   lightEndColor = "0 0 0";
};


//projectile
AddDamageType("HuntsmanDirect",   '<bitmap:add-ons/Weapon_Huntsman/CI_Huntsman> %1',    '%2 <bitmap:add-ons/Weapon_Huntsman/CI_Huntsman> %1',0.5,1);

datablock ProjectileData(HuntsmanProjectile)
{
   projectileShapeName = "./arrow.dts";

   directDamage        = 100;
   directDamageType    = $DamageType::HuntsmanDirect;

   radiusDamage        = 0;
   damageRadius        = 0;
   radiusDamageType    = $DamageType::HuntsmanDirect;

   explosion             = HuntsmanExplosion;
   stickExplosion        = HuntsmanStickExplosion;
   bloodExplosion        = HuntsmanStickExplosion;
   particleEmitter       = HuntsmanTrailEmitter;
   explodeOnPlayerImpact = true;
   explodeOnDeath        = true; 

   armingDelay         = 4000;
   lifetime            = 4000;
   fadeDelay           = 4000;

   isBallistic         = true;
   bounceAngle         = 170; //stick almost all the time
   minStickVelocity    = 10;
   bounceElasticity    = 0.2;
   bounceFriction      = 0.01;   
   gravityMod = 0.25;

   hasLight    = false;
   lightRadius = 3.0;
   lightColor  = "0 0 0.5";

   muzzleVelocity      = 50;
   velInheritFactor    = 1;

   uiName = "Huntsman Arrow";
};


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

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

   //gui stuff
   uiName = "Huntsman";
   iconName = "./icon_Huntsman";
   doColorShift = true;
   colorShiftColor = "0.400 0.196 0 1.000";

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

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(HuntsmanImage)
{
   // Basic Item properties
   shapeFile = "./Huntsman.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 10" );

   // 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 = HuntsmanItem;
   ammo = " ";
   projectile = HuntsmanProjectile;
   projectileType = Projectile;

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

   doColorShift = true;
   colorShiftColor = HuntsmanItem.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.5;
   stateTransitionOnTimeout[0]       = "Ready";
   stateSound[0]               = weaponSwitchSound;

   stateName[1]                     = "Ready";
   stateTransitionOnTriggerDown[1]  = "Pullback";
   stateAllowImageChange[1]         = true;

   stateName[2]         = "Pullback";
   stateScript[2]                  = "onFire1";
   stateSequence[2]      = "Pullback";
   stateSound[2]         = HuntsmanPullSound;
   stateTransitionOnTimeout[2]     = "Pullback2";
   stateTimeoutValue[2]            = 0.27;
   stateTransitionOnTriggerUp[2]   = "Fire";
   stateAllowImageChange[2]         = false;


   stateName[3]         = "Pullback2";
   stateScript[3]                  = "onFire2";
   stateTransitionOnTimeout[3]     = "Pullback3";
   stateTimeoutValue[3]            = 0.3;
   stateTransitionOnTriggerUp[3]   = "Fire";
   stateAllowImageChange[3]         = false;


   stateName[4]         = "Pullback3";
   stateScript[4]                  = "onFire3";
   stateTransitionOnTimeout[4]     = "Pullback4";
   stateTimeoutValue[4]            = 0.3;
   stateTransitionOnTriggerUp[4]   = "Fire";
   stateAllowImageChange[4]         = false;


   stateName[5]         = "Pullback4";
   stateScript[5]                  = "onFire4";
   stateTransitionOnTriggerUp[5]   = "Fire";
   stateAllowImageChange[5]         = false;

   stateName[6]                    = "Fire";
   stateTransitionOnTimeout[6]     = "Reload";
   stateTimeoutValue[6]            = 0.03;
   stateFire[6]                    = true;
   stateAllowImageChange[6]        = false;
   stateSequence[6]                = "Fire";
   stateScript[6]                  = "onFire";
   stateWaitForTimeout[6]         = true;
   stateSound[6]               = HuntsmanFireSound;

   stateName[7]         = "Reload";
   stateSequence[7]                = "Reload";
   stateAllowImageChange[7]        = false;
   stateTimeoutValue[7]            = 0.5;
   stateWaitForTimeout[7]      = true;
   stateTransitionOnTimeout[7]     = "Check";

   stateName[8]         = "Check";
   stateTransitionOnTriggerUp[8]   = "StopFire";

   stateName[9]                    = "StopFire";
   stateTransitionOnTimeout[9]     = "Ready";
   stateTransitionOnTriggerDown[9] = "Ready";
   stateTimeoutValue[9]            = 0.2;
   stateAllowImageChange[9]        = false;
   stateWaitForTimeout[9]      = true;
   //stateSequence[9]                = "Reload";
   stateScript[9]                  = "onStopFire";


};

function Huntsman::OnFire1(%this, %obj, %slot)
{
   %obj.DamageAmmountHuntsman = 25;
}


function Huntsman::OnFire2(%this, %obj, %slot)
{
   %obj.DamageAmmountHuntsman = 50;
}


function Huntsman::OnFire3(%this, %obj, %slot)
{
   %obj.DamageAmmountHuntsman = 75;
}


function Huntsman::OnFire4(%this, %obj, %slot)
{
   %obj.DamageAmmountHuntsman = 100;
}

function Huntsman::onFire(%this, %obj, %slot)
{
   %vector = %obj.getMuzzleVector(%slot);
   %objectVelocity = %obj.getVelocity();
   %vector1 = VectorScale(%vector, %this.projectile.muzzleVelocity);
   %vector2 = VectorScale(%objectVelocity, %this.projectile.velInheritFactor);
   %velocity = VectorAdd(%vector1,%vector2);
   %mat = MatrixCreateFromEuler(0 SPC 0 SPC 0);
   %velocity = MatrixMulVector(%mat, %velocity);

   %p = new Projectile()
   {
      dataBlock = %this.projectile.getDatablock();
      initialVelocity = %velocity;
      initialPosition = %obj.getMuzzlePoint(%slot);
      sourceObject = %obj;
      modifier = %obj.DamageAmmountHuntsman;
      client = %obj.client;
      sourceSlot = %slot;
   };
}

function HuntsmanProjectile::Damage(%this, %obj, %col, %fade, %pos, %normal)
{
   if(strPos(%col.getClassName(), "Player") != -1)
   {
      %amount = %this.directDamage * %obj.DamageAmmountHuntsman;
      %col.damage(%obj.sourceObject, %pos, %amount, $DamageType::HuntsmanDirect);
   }
}
I am not finished with it, so don't nag at me about some of the emitters being the same as the bow.

I made that TF2 bow based on a proper variable charge thing instead of lots and lots of image states. If you want I'll give you the script, it'll work better.