Author Topic: Weapon won't fire anything  (Read 1564 times)

Someone tell me if posting this many help threads is against the rules or something. As far as I can tell, it isn't...

Soo... now I'm trying to get this weapon to work. It's an invisible weapon meant to work with the Ghast playertype located here: https://forum.blockland.us/index.php?topic=289735
But it doesn't fire anything. The Ghast usually animates properly- its face changes when it's supposed to fire, though sometimes it gets stuck in armAttack and doesn't go back to Root. Even spawning the Ghast Fireball projectile with events works properly- the particles are right, it flies right, and it explodes right.
But no matter how I change it, I can't seem to get it to fire. I have a feeling it's got something to do with the "Charge" state, which is meant to provide a delay before firing to replicate the Minecraft Ghast's chargeup time and give it time to make the sound before firing. But as far as I can tell, it's correct.
Code: [Select]
//GhastFireball.cs

//audio
datablock AudioProfile(GhastFireSound)
{
   filename    = "./ghastfire.wav";
   description = AudioClose3d;
   preload = true;
};

datablock AudioProfile(GhastExplodeSound)
{
   filename    = "./ghastexplode.wav";
   description = AudioDefault3d;
   preload = true;
};
datablock AudioProfile(GhastChargeSound)
{
   filename    = "./ghastcharge.wav";
   description = AudioClose3d;
   preload = true;
};

datablock ParticleData(GhastTrailParticle)
{
dragCoefficient      = 2.5;
gravityCoefficient   = -0.17;
inheritedVelFactor   = 0.8;
constantAcceleration = 0;
lifetimeMS           = 850;
lifetimeVarianceMS   = 500;
textureName          = "base/data/particles/cloud";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0] = "0.2 0.2 0.2 1";
colors[1] = "1 0.5 0 0.5";
colors[2] = "1 0.25 0 0.25";
colors[3] = "1 0 0 0";
sizes[0] = 1.15;
sizes[1] = 1.0;
sizes[2] = 1.2;
sizes[3] = 1.5;
times[0] = 0;
times[1] = 0.1;
times[2] = 0.8;
times[3] = 1;

useInvAlpha = false;
};

datablock ParticleEmitterData(GhastTrailEmitter)
{
   ejectionPeriodMS = 5; //2
   periodVarianceMS = 0;
   ejectionVelocity = 15;
   velocityVariance = 5;
   ejectionOffset   = 0;
   thetaMin         = 0;
   thetaMax         = 5;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "GhastTrailParticle";

   uiName = "Ghast Fireball Trail";
};

datablock ParticleData(GhastExplosionParticle)
{
dragCoefficient      = 3;
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]     = "0.9 0.9 0.6 0.9";
colors[1]     = "0.9 0.5 0.6 0.0";
sizes[0]      = 10.0;
sizes[1]      = 15.0;

useInvAlpha = true;
};
datablock ParticleEmitterData(GhastExplosionEmitter)
{
   ejectionPeriodMS = 3;
   periodVarianceMS = 0;
   ejectionVelocity = 10;
   velocityVariance = 1.0;
   ejectionOffset   = 3.0;
   thetaMin         = 89;
   thetaMax         = 90;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "GhastExplosionParticle";

   uiName = "Ghast Explosion Smoke";
   emitterNode = TenthEmitterNode;
};


datablock ParticleData(GhastExplosionRingParticle)
{
dragCoefficient      = 8;
gravityCoefficient   = -0.5;
inheritedVelFactor   = 0.2;
constantAcceleration = 0.0;
lifetimeMS           = 40;
lifetimeVarianceMS   = 10;
textureName          = "base/data/particles/star1";
spinSpeed = 10.0;
spinRandomMin = -500.0;
spinRandomMax = 500.0;
colors[0]     = "1 0.5 0.2 0.5";
colors[1]     = "0.9 0.0 0.0 0.0";
sizes[0]      = 8;
sizes[1]      = 13;

useInvAlpha = false;
};
datablock ParticleEmitterData(GhastExplosionRingEmitter)
{
lifeTimeMS = 50;

   ejectionPeriodMS = 1;
   periodVarianceMS = 0;
   ejectionVelocity = 5;
   velocityVariance = 0.0;
   ejectionOffset   = 3.0;
   thetaMin         = 0;
   thetaMax         = 180;
   phiReferenceVel  = 0;
   phiVariance      = 360;
   overrideAdvance = false;
   particles = "GhastExplosionRingParticle";

   uiName = "Ghast Explosion Flash";
};

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

   lifeTimeMS = 350;

   particleEmitter = GhastExplosionEmitter;
   particleDensity = 10;
   particleRadius = 0.2;

   emitter[0] = GhastExplosionRingEmitter;

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

   shakeCamera = true;
   camShakeFreq = "10.0 11.0 10.0";
   camShakeAmp = "3.0 10.0 3.0";
   camShakeDuration = 0.5;
   camShakeRadius = 20.0;

   // Dynamic light
   lightStartRadius = 10;
   lightEndRadius = 25;
   lightStartColor = "1 1 1 1";
   lightEndColor = "0 0 0 1";

   damageRadius = 4.5;
   radiusDamage = 125;

   impulseRadius = 6;
   impulseForce = 4000;
};


AddDamageType("Ghast");
datablock ProjectileData(GhastFireballProjectile)
{
   projectileShapeName = "base/data/shapes/empty.dts";
   directDamage        = 75;
   directDamageType = $DamageType::Ghast;
   radiusDamageType = $DamageType::Ghast;
   impactImpulse    = 500;
   verticalImpulse    = 500;
   explosion           = GhastExplosion;
   particleEmitter     = GhastTrailEmitter;

   brickExplosionRadius = 3;
   brickExplosionImpact = false;          //destroy a brick if we hit it directly?
   brickExplosionForce  = 30;             
   brickExplosionMaxVolume = 30;          //max volume of bricks that we can destroy
   brickExplosionMaxVolumeFloating = 60;  //max volume of bricks that we can destroy if they aren't connected to the ground (should always be >= brickExplosionMaxVolume)

   muzzleVelocity      = 65;
   velInheritFactor    = 1.0;

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

   hasLight    = true;
   lightRadius = 8.0;
   lightColor  = "1 0.5 0.0";

   uiName = "Ghast Fireball";
};

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

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

//gui stuff
uiName = "Ghast Fireball";
iconName = "./icon_GhastFireball";
doColorShift = false;
colorShiftColor = "1 1 1 1.000";

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

////////////////
//weapon image//
////////////////
datablock ShapeBaseImageData(GhastFireballImage)
{
   // Basic Item properties
   shapeFile = "base/data/shapes/empty.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 = false;

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

   // Projectile && Ammo.
   item = GhastFireballItem;
   ammo = " ";
   projectile = GhastFireballProjectile;
   projectileType = Projectile;

//casing = GhastFireballShellDebris;
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 = true;
   //raise your arm up or not
   armReady = false;
   
   doColorShift = false;
   colorShiftColor = GhastFireballItem.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]             = 1;
stateTransitionOnTimeout[0]       = "Ready";
// stateSound[0] = weaponSwitchSound;

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

stateName[2]                     = "Charge";
stateTransitionOnTimeout[2]  = "Fire";
stateTimeoutValue[2]             = 0.6;
stateAllowImageChange[2]         = false;
stateSound[2] = GhastChargeSound;
stateSequence[2] = "Ready";

stateName[3]                    = "Fire";
stateTransitionOnTimeout[3]     = "CoolDown";
stateTimeoutValue[3]            = 0.1;
stateFire[3]                    = true;
stateAllowImageChange[3]        = false;
stateSequence[3]                = "Fire";
stateScript[3]                  = "onFire";
stateWaitForTimeout[3] = true;
stateSound[3] = GhastFireSound;
    stateSequence[3]                = "Fire";
//stateEjectShell[2]       = true;

    stateName[4] = "CoolDown";
    stateTimeoutValue[4]            = 0.3;
    stateTransitionOnTimeout[4]     = "Reload";
    stateSequence[4]                = "TrigDown";
   
    stateName[5] = "Reload";
stateTransitionOnTriggerUp[5]     = "Ready";
stateScript[5]                  = "onReload";
stateSequence[5] = "TrigDown";

};

function GhastFireballImage::onFire(%this, %obj, %slot)
{
%obj.playthread(2, armAttack);
}

function GhastFireballImage::onReload(%this, %obj, %slot)
{
%obj.playthread(2, root);
}

Because firing a projectile is supposed to happen in the ::onFire function. You're overriding it and not calling a parent or writing your own projectile spawning code.
It should work if you just add Parent::onFire(%this,%obj,%slot); to it.

Because firing a projectile is supposed to happen in the ::onFire function. You're overriding it and not calling a parent or writing your own projectile spawning code.
It should work if you just add Parent::onFire(%this,%obj,%slot); to it.
I'm... not quite sure where to add that. Sorry if this is obvious stuff.
Scratch that. Saw exactly what you're talking about somewhere else. Thanks!
Edit: So if I don't parent the onFire function, then it completely overrides the default onFire function, but if I add Parent::onFire(%this,%obj,%slot); , it instead adds my code to the existing function? Am I understanding this correctly?
« Last Edit: October 27, 2017, 02:14:19 PM by Brixmon »

Yes, when the function executes it does your stuff, then parent:: stuff tells it to do the old function stuff, then it goes back to your code

Ie

Code: [Select]
function thing::onFire()
{
echo("a");
}

function blub::onFire()
{
echo("b");
parent::onFire();
echo("c");
}
(blub extends stuff)

Would print b, a, c

Also there's nothing wrong with making more topics if they are useful for the discussion of things

Yes, when the function executes it does your stuff, then parent:: stuff tells it to do the old function stuff, then it goes back to your code

Ie

Code: [Select]
function thing::onFire()
{
echo("a");
}

function blub::onFire()
{
echo("b");
parent::onFire();
echo("c");
}
(blub extends stuff)

Would print b, a, c

Also there's nothing wrong with making more topics if they are useful for the discussion of things
Alright, thanks!

Yes, when the function executes it does your stuff, then parent:: stuff tells it to do the old function stuff, then it goes back to your code
A better explanation is that there's a class hierarchy involved.

Parent Class > More parent classes > etc > specific object name

GhastFireballImage::onFire
WeaponImage::onFire
ShapeBaseImageData::onFire
and then I forget the rest of the parent classes

And then packages will be added on top of whatever it's packaging.

GhastFireballImage::onFire
[Package2]WeaponImage::onFire
[Package1]WeaponImage::onFire
WeaponImage::onFire
ShapeBaseImageData::onFire

The game will check for these in this order.
If the top one doesn't exist, check the next one down.
If it calls parent, call the next one down as well.
If it doesn't call parent, then we're all done, stop going down the list.