Game Development Community

Reload functionality doesnt work..

by RedCore · in Torque Game Engine · 10/16/2003 (6:03 pm) · 8 replies

Here is my own reload code that i made.. i based it off of
Micha

#1
10/16/2003 (6:05 pm)
Datablock ItemData(MachineGun)
{
// Mission editor category
category = "Weapon";

// Hook into Item Weapon class hierarchy. The weapon namespace
// provides common weapon handling functions in addition to hooks
// into the inventory system.
className = "Weapon";

// Basic Item properties
shapeFile = "~/data/shapes/rifle/weapon.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;

// Dynamic properties defined by the scripts
pickUpName = "a Machine Gun";
image = MachineGunImage;
};


//--------------------------------------------------------------------------
// Rifle image which does all the work. Images do not normally exist in
// the world, they can only be mounted on ShapeBase objects.

datablock ShapeBaseImageData(MachineGunImage)
{
// Basic Item properties
shapeFile = "~/data/shapes/rifle/weapon.dts";
emap = true;
mountPoint = 0;
offset = "0 0 0";
eyeOffset = "0.1 0.2 -0.55";
correctMuzzleVector = false;

className = "WeaponImage";

item = MachineGun;
ammo = MachineGunClips;
ammoInClip = 30;
projectile = MachineGunProjectile;
projectileType = Projectile;
casing = MachineGunShell;

stateName[0] = "Preactivate";
stateTransitionOnLoaded[0] = "Activate";
stateTransitionOnNoAmmo[0] = "NoAmmo";

stateName[1] = "Activate";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.5;
stateSequence[1] = "Activate";

stateName[2] = "Ready";
stateTransitionOnNoAmmo[2] = "NoAmmo";
stateTransitionOnTriggerDown[2] = "Fire";

stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Ready";
stateTransitionOnNoAmmo[3] = "ReloadClip";
stateTimeoutValue[3] = 0.01;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateSound[3] = MachineGunFireSound;
stateEmitterTime[3] = 0.3;
stateEjectShell[3] = true;

stateName[4] = "Reload";
stateTransitionOnNoAmmo[4] = "ReloadClip";
stateTransitionOnTimeout[4] = "Ready";
stateTimeoutValue[4] = 0.01;
stateAllowImageChange[4] = false;
stateSequence[4] = "Reload";

stateName[5] = "NoAmmo";
stateTransitionOnAmmo[5] = "Reload";
stateSequence[5] = "NoAmmo";
stateTransitionOnTriggerDown[5] = "DryFire";

stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";

stateName[7] = "ReloadClip";
stateScript[7] = "ReloadClip";
stateTransitionOnAmmo[7] = "Reload";
stateSound[7] = CrossbowReloadSound;
};


//-----------------------------------------------------------------------------
#2
10/16/2003 (6:05 pm)
Function MachineGunImage::onFire(%this, %obj, %slot)
{

if( %this.ammoInClip > 0 )
{
%this.ammoInClip = %this.ammoInClip - 1;

if( %this.ammoInClip == 0 )
{
%obj.setImageAmmo( %slot, false );
}
}
else
{

%obj.setImageAmmo(%slot,false);

return 0;
}
%projectile = %this.projectile;

%vector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%vector1 = VectorScale(%vector, %projectile.muzzleVelocity);
%vector2 = VectorScale(%objectVelocity, %projectile.velInheritFactor);
%velocity = VectorAdd(%vector1,%vector2);
%x = (getRandom() - 0.5) * 2 * 3.1415926 * 0.005;
%y = (getRandom() - 0.5) * 2 * 3.1415926 * 0.005;
%z = (getRandom() - 0.5) * 2 * 3.1415926 * 0.005;
%mat = MatrixCreateFromEuler(%x @ " " @ %y @ " " @ %z);

// Alter our projectile vector with our spread matrix
%velocity = MatrixMulVector(%mat, %velocity);


// Create our projectile
%p = new (%this.projectileType)()
{
dataBlock = %projectile;
initialVelocity = %velocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
};
MissionCleanup.add(%p);


return %p;
}

function MachineGunImage::ReloadClip(%this, %obj, %slot)
{
%clips = %this.ammo;
if (%clips > 0)
{
%this.ammoInClip += 30;
}

}
#3
10/16/2003 (6:25 pm)
Time for you to debug.
#4
10/17/2003 (6:36 pm)
It lets me pick up ammo now.. I'm still not sure what was causing it.. but now the actual reloading of the clip doesnt work.. hem..
#5
10/17/2003 (7:02 pm)
Bogus post ... thought I noticed something odd, but it was legit
#6
10/17/2003 (10:19 pm)
@Redcore: debug it dude, stop creating threads with the code you bust.
#7
10/18/2003 (3:15 am)
Yeah its pretty hard for others to understand your logic and then have to find the mistakes in that logic.

Also it would be a better idea to post a link to the .cs file(s). So people can plug it in and test it, not have to muck around with cuting and pasting.
#8
10/18/2003 (4:11 am)
Put in some echo(); in your functions to make sure that they are being called with the right info etc..