Author Topic: Limited Use Arm Rocket L.  (Read 1172 times)

I'm trying to make the arm rocket have a one time usage, However I'm new when it comes to coding.

Here's the code

Quote
//Arm_Rocket.cs
//Amadé (ID 10716)

//audio
datablock AudioProfile(ArmRLexplodeSound)
{
   filename    = "Add-Ons/Weapon_Rocket_Launcher/TNTexplode.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock AudioProfile(ArmRLloopSound)
{
   filename    = "Add-Ons/Weapon_Rocket_Launcher/RocketLoop.wav";
   description = AudioDefaultLooping3d;
   preload = true;
};

//muzzle flash effects
datablock ParticleData(ArmRocketFlashParticle)
{
   dragCoefficient      = 1;
   gravityCoefficient   = -0.7;
   inheritedVelFactor   = 0.85;
   constantAcceleration = 0;
   lifetimeMS         = 500;
   lifetimeVarianceMS = 300;
   textureName = "base/data/particles/cloud";
   spinSpeed     = 15;
   spinRandomMin = -500;
   spinRandomMax = 500;
   colors[0] = "1 0.75 0 1";
   colors[1] = "1 0 0 0";
   sizes[0] = 0.4;
   sizes[1] = 0;

   useInvAlpha = false;
};
datablock ParticleEmitterData(ArmRocketFlashEmitter)
{
   ejectionPeriodMS = 2;
   periodVarianceMS = 0;
   ejectionVelocity = 1.5;
   velocityVariance = 1;
   ejectionOffset   = 0;
   thetaMin = 1;
   thetaMax = 105;
   phiReferenceVel = 0;
   phiVariance     = 360;
   overrideAdvance = false;
   particles = ArmRocketFlashParticle;

   uiName = "Arm Rocket Sparks";
};

datablock ParticleData(ArmRocketSmokeParticle)
{
   dragCoefficient      = 1;
   gravityCoefficient   = -0.3;
   inheritedVelFactor   = 1;
   constantAcceleration = 0;
   lifetimeMS         = 1250;
   lifetimeVarianceMS = 250;
   textureName = "base/data/particles/cloud";
   spinSpeed     = 10;
   spinRandomMin = -500;
   spinRandomMax = 500;

   colors[0] = "0.7 0.7 0.7 0.3";
   colors[1] = "0.6 0.6 0.6 0.5";
   colors[2] = "0.5 0.5 0.5 0";

   sizes[0] = 0.4;
   sizes[1] = 0.8;
   sizes[2] = 1.2;

   times[1] = 0.5;
   times[2] = 1;

   useInvAlpha = true;
};
datablock ParticleEmitterData(ArmRocketSmokeEmitter)
{
   ejectionPeriodMS = 7;
   periodVarianceMS = 0;
   ejectionVelocity = 1.5;
   velocityVariance = 1;
   ejectionOffset = 0;
   thetaMin = 85;
   thetaMax = 95;
   phiReferenceVel = 0;
   phiVariance     = 360;
   overrideAdvance = false;
   particles = "ArmRocketSmokeParticle";

   uiName = "Arm Rocket Launch Smoke";
};

//Trail
datablock ParticleData(ArmRocketTrailParticle)
{
   dragCoefficient      = 0.1;
   gravityCoefficient   = -0.06;
   windCoefficient      = 0.35;
   inheritedVelFactor   = 0;
   constantAcceleration = 0;
   lifetimeMS           = 3000;
   lifetimeVarianceMS   = 1000;
   textureName          = "base/data/particles/cloud";
   spinSpeed     = 10;
   spinRandomMin = -600;
   spinRandomMax = 700;
   colors[0] = "1 1 0 0.5";
   colors[1] = "1 0 0 0.3";
   colors[2] = "0.2 0.2 0.2 0.2";
   colors[3] = "0.2 0.2 0.2 0.05";

   sizes[0] = 0.6;
   sizes[1] = 0.7;
   sizes[2] = 0.8;
   sizes[3] = 0.9;

   times[0] = 0;
   times[1] = 0.1;
   times[2] = 0.15;
   times[3] = 1;

   useInvAlpha = false;
};
datablock ParticleEmitterData(ArmRocketTrailEmitter)
{
   ejectionPeriodMS = 10;
   periodVarianceMS = 0;
   ejectionVelocity = 0.3;
   velocityVariance = 0.15;
   ejectionOffset = 0.1;
   thetaMin = 135;
   thetaMax = 180;
   phiReferenceVel = 0;
   phiVariance     = 360;
   overrideAdvance = false;
   particles = "ArmRocketTrailParticle";
};


datablock ParticleData(ArmRocketExplosionParticle)
{
   dragCoefficient      = 2;
   gravityCoefficient   = -0.5;
   inheritedVelFactor   = 0.3;
   constantAcceleration = 0;
   lifetimeMS           = 1000;
   lifetimeVarianceMS   = 750;
   textureName          = "base/data/particles/cloud";
   spinSpeed          = 10;
   spinRandomMin      = -100;
   spinRandomMax      = 100;
   colors[0]     = "0.75 0.7 0.65 0.9";
   colors[1]     = "0.6 0.55 0.5 0.1";
   sizes[0]      = 10;
   sizes[1]      = 15;

   useInvAlpha = true;
};
datablock ParticleEmitterData(ArmRocketExplosionEmitter)
{
   ejectionPeriodMS = 7;
   periodVarianceMS = 2;
   ejectionVelocity = 12;
   velocityVariance = 1.2;
   ejectionOffset   = 3.0;
   thetaMin         = 89;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "ArmRocketExplosionParticle";
};

datablock ParticleData(ArmRocketExplosionRingParticl e)
{
   dragCoefficient      = 8;
   gravityCoefficient   = -0.5;
   inheritedVelFactor   = 0.2;
   constantAcceleration = 0.0;
   lifetimeMS           = 40;
   lifetimeVarianceMS   = 10;
   textureName          = "base/data/particles/dot";
   spinSpeed      = 10.0;
   spinRandomMin      = -500.0;
   spinRandomMax      = 500.0;
   colors[0]     = "1 0.5 0 0.6";
   colors[1]     = "1 0 0 0.1";
   sizes[0]      = 8;
   sizes[1]      = 15;

   useInvAlpha = false;
};
datablock ParticleEmitterData(ArmRocketExplosionRingEmitter)
{
   lifeTimeMS = 150;

   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 15;
   velocityVariance = 10;
   ejectionOffset   = 3;
   thetaMin         = 0;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance  = false;
   particles        = "ArmRocketExplosionRingParticl e";
};

datablock ExplosionData(ArmRocketExplosion)
{
   explosionShape = "Add-Ons/Weapon_Rocket_Launcher/explosionSphere1.dts";
   soundProfile   = ArmRLexplodeSound;

   lifeTimeMS = 150;

   particleEmitter = ArmRocketExplosionEmitter;
   particleDensity = 20;
   particleRadius = 0.2;

   emitter[0] = ArmRocketExplosionRingEmitter;

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

   shakeCamera = true;
   camShakeFreq = "10 11 10";
   camShakeAmp = "1.5 5 1.5";
   camShakeDuration = 0.25;
   camShakeRadius = 15;

   lightStartRadius = 5;
   lightEndRadius   = 20;
   lightStartColor  = "1 1 0 1";
   lightEndColor    = "1 1 1 1";

   damageRadius = 5;
   radiusDamage = 85;

   impulseRadius = 5;
   impulseForce  = 3000;

   uiName = "Arm Rocket Explosion";
};

AddDamageType("ArmRocketDirect", '<bitmap:add-ons/Weapon_Arm_Rocket/CI> %1', '%2 <bitmap:add-ons/Weapon_Arm_Rocket/CI> %1',1,1);
AddDamageType("ArmRocketRadius", '<bitmap:add-ons/Weapon_Arm_Rocket/CI_radius> %1', '%2 <bitmap:add-ons/Weapon_Arm_Rocket/CI_radius> %1',1,0);

datablock ProjectileData(ArmRocketProjectile)
{
   projectileShapeName = "./rocket.dts";
   directDamage     = 500;
   directDamageType = $DamageType::ArmRocketDirect;
   radiusDamageType = $DamageType::ArmRocketRadius;
   impactImpulse   = 3000;
   verticalImpulse = 1000;
   explosion       = ArmRocketExplosion;
   particleEmitter = ArmRocketTrailEmitter;

   brickExplosionRadius = 6;
   brickExplosionImpact = true;
   brickExplosionForce  = 25;             
   brickExplosionMaxVolume = 45;
   brickExplosionMaxVolumeFloati ng = 75;

   sound = ArmRLloopSound;

   muzzleVelocity   = 110;
   velInheritFactor = 0;

   armingDelay = 0;
   lifetime    = 5000;
   fadeDelay   = 5000;
   bounceElasticity = 1;
   bounceFriction   = 0;
   isBallistic = false;
   gravityMod  = 0;
   Explodeondeath = true;
   hasLight    = true;
   lightRadius = 10;
   lightColor  = "1 0.5 0";

   uiName = "Arm Rocket";
};

//item
datablock ItemData(ArmRocketItem)
{
   category = "Weapon";
   className = "Weapon";

   shapeFile = "./ArmRocketLauncher.dts";
   rotate = false;
   mass = 1;
   density = 0.2;
   elasticity = 0.2;
   friction = 0.6;
   emap = true;

   uiName = "Arm Rocket L.";
   iconName = "./icon_ArmRocket";
   doColorShift = true;
   colorShiftColor = "1 0 0 1";

   image = ArmRocketImage;
   canDrop = true;
};

//weapon image
datablock ShapeBaseImageData(ArmRocketImage)
{
   shapeFile = ArmRocketItem.shapeFile;
   emap = true;

   mountPoint = 0;
   offset = "0 0 0";
   eyeOffset = 0;
   rotation = "0 0 0";

   correctMuzzleVector = true;

   className = "WeaponImage";

   item = BowItem;
   ammo = "1";
   projectile = ArmRocketProjectile;
   projectileType = Projectile;

   melee = false;
   armReady = true;
   minShotTime = 1000;

   doColorShift = true;
   colorShiftColor = ArmRocketItem.colorShiftColor;

   stateName[0]                = "Activate";
   stateTimeoutValue[0]        = 0.1;
   stateTransitionOnTimeout[0] = "Ready";
   stateSound[0]               = weaponSwitchSound;

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

   stateName[2]                = "Fire";
   stateTransitionOnTimeout[2] = "Smoke";
   stateTimeoutValue[2]        = 0.1;
   stateFire[2]                = true;
   stateAllowImageChange[2]    = false;
   stateScript[2]              = "onFire";
   stateWaitForTimeout[2]      = true;
   stateEmitter[2]             = ArmRocketFlashEmitter;
   stateEmitterTime[2]         = 0.15;
   stateEmitterNode[2]         = muzzleNode;

   stateName[3]                = "Smoke";
   stateEmitter[3]             = ArmRocketSmokeEmitter;
   stateEmitterTime[3]         = 0.05;
   stateEmitterNode[3]         = "muzzleNode";
   stateTimeoutValue[3]        = 0.1;
   stateTransitionOnTimeout[3] = "CoolDown";

   stateName[5]                = "CoolDown";
   stateTimeoutValue[5]        = 0.9;
   stateTransitionOnTimeout[5] = "Reload";

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

function ArmRocketImage::onFire(%this, %obj, %slot)
{
   if(%obj.getDamagePercent() < 1)
   {
      %obj.playthread(2,shiftAway);
   }
   parent::onFire(%this,%obj,%slot);
}

function ArmRocketImage::onFire(%this, %obj, %slot)
{
   cancel(%obj.burnSched);
   %obj.playthread(2, spearThrow);
   %obj.chargeEnd = getSimTime();
   %obj.chargeTime = %obj.chargeEnd - %obj.chargeStart;
   Parent::OnFire(%this, %obj, %slot);

   %currSlot = %obj.lastFragSlot;
   %obj.tool[%currSlot] = 0;
   %obj.weaponCount--;
   messageClient(%obj.client,'MsgItemPickup','',%currSlot,0);
   serverCmdUnUseTool(%obj.client);
}

function ArmRocketImage::onDone(%this,%obj,%slot)
{
   %obj.unMountImage(%slot);
}


All i did basically is copy and pasted the bob-omb code and rename some stuff.
(Most likely a bad idea but whatever)

It works somewhat. its get unequipped but still remains in the player's inventory.
I need help and a little knowledge on what i could've done. Thank you

First of all, you have 2 ArmRocketImage::onFire functions, the first one gets overwritten by the 2nd one. Items don't disappear because %obj.lastFragSlot is never defined.

Keep the 2nd one, and replace the first one with ArmRocketImage::onMount(%this, %obj, %slot), make this function empty and add %obj.lastFragSlot = %obj.currTool;

First of all, you have 2 ArmRocketImage::onFire functions, the first one gets overwritten by the 2nd one. Items don't disappear because %obj.lastFragSlot is never defined.

Keep the 2nd one, and replace the first one with ArmRocketImage::onMount(%this, %obj, %slot), make this function empty and add %obj.lastFragSlot = %obj.currTool;

Thanks, this worked.