Game Development Community

Cant get the weapons to work...

by Matt Berry · in Torque Game Engine · 04/13/2006 (5:13 pm) · 6 replies

Ok, so I'm pretty much banging my head against my desk at this point.

I worked my way through the basic pistol tut over at
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9230

As far as I can tell, everything SHOULD be working. It loads and compiles all the scripts without error, but I cannot mount the pistol.

In the creator, under shapes->weapons, the crossbow is still the only weapon listed. am I missing a step somewhere? all the .dts files are in the proper locations (i can add them into the game using the static shape drop down), so I am just at a loss now


also


In the console, this error repeaditly pops up (trying to equip the AIguard with the pistol)
starter.fps/server/scripts/inventory.cs (134): Unable to find object: 'pistolAmmo' attempting to call function 'getName'

However, the datablock for the pistolAmmo is identical to the one in crossbow, except that its called pistolAmmo

I'm sure this is somewhere simple, but its driving me crazy

#1
04/13/2006 (5:26 pm)
Are you certain you are executing your script file for the pistol? The pistol item definition should show up in the world editor if everything is executing and loading properly. Can't really say anymore without seeing your code.
#2
04/13/2006 (5:37 pm)
Pistol.cs code minus the particle stuff

//-----------------------------------------------------------------------------
// Projectile Object

datablock ProjectileData(pistolProjectile)
{
projectileShapeName = "~/data/shapes/weapons/pistol/projectile.dts";
directDamage = 20;
radiusDamage = 0;
damageRadius = 1;
explosion = pistolExplosion;
particleEmitter = pistolBoltEmitter;

muzzleVelocity = 700;
velInheritFactor = 0.3;

armingDelay = 0;
lifetime = 5000;
fadeDelay = 5000;
bounceElasticity = 0;
bounceFriction = 0;
isBallistic = false;
gravityMod = 0.00;

hasLight = true;
lightRadius = 1;
lightColor = "0.5 0.5 0.25";

hasWaterLight = true;
waterLightColor = "0 0.5 0.5";
};

function pistolProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"pistolrounds");

// Radius damage is a support scripts defined in radiusDamage.cs
// Push the contact point away from the contact surface slightly
// along the contact normal to derive the explosion center. -dbs
radiusDamage
(%obj, VectorAdd(%pos, VectorScale(%normal, 0.01)),
%this.damageRadius,%this.radiusDamage,"Radius",40);
}


//-----------------------------------------------------------------------------
// Ammo Item

datablock ItemData(pistolAmmo)
{
// Mission editor category
category = "Ammo";

// Add the Ammo namespace as a parent. The ammo namespace provides
// common ammo related functions and hooks into the inventory system.
className = "Ammo";

// Basic Item properties
shapeFile = "~/data/shapes/weapons/pistol/ammo.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;

// Dynamic properties defined by the scripts
pickUpName = "Pistol Rounds";
maxInventory = 20;
};


//--------------------------------------------------------------------------
// Weapon Item. This is the item that exists in the world, i.e. when it's
// been dropped, thrown or is acting as re-spawnable item. When the weapon
// is mounted onto a shape, the pistolImage is used.

datablock ItemData(Pistol)
{
// 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/weapons/pistol/pistol.dts";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;

// Dynamic properties defined by the scripts
pickUpName = "a Pistol";
image = PistolImage;
};


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

datablock ShapeBaseImageData(PistolImage)
{
// Basic Item properties
shapeFile = "~/data/shapes/weapons/pistol/pistol.dts";
emap = false;

// Specify mount point & offset for 3rd person, and eye offset
// for first person rendering.
mountPoint = 0;
eyeOffset = "0.1 0.4 -0.6";

// 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 = pistol;
ammo = pistolAmmo;
projectile = pistolProjectile;
projectileType = Projectile;

// 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] = "Preactivate";
stateTransitionOnLoaded[0] = "Activate";
stateTransitionOnNoAmmo[0] = "NoAmmo";

// Activating the gun. Called when the weapon is first
// mounted and there is ammo.
stateName[1] = "Activate";
stateTransitionOnTimeout[1] = "Ready";
stateTimeoutValue[1] = 0.6;
stateSequence[1] = "Activate";

// Ready to fire, just waiting for the trigger
stateName[2] = "Ready";
stateTransitionOnNoAmmo[2] = "NoAmmo";
stateTransitionOnTriggerDown[2] = "Fire";

// Fire the weapon. Calls the fire script which does
// the actual work.
stateName[3] = "Fire";
stateTransitionOnTimeout[3] = "Reload";
stateTimeoutValue[3] = 0.2;
stateFire[3] = true;
stateRecoil[3] = LightRecoil;
stateAllowImageChange[3] = false;
stateSequence[3] = "Fire";
stateScript[3] = "onFire";
stateSound[3] = pistolFireSound;

// Play the reload animation, and transition into
stateName[4] = "Reload";
stateTransitionOnNoAmmo[4] = "NoAmmo";
stateTransitionOnTimeout[4] = "Ready";
stateTimeoutValue[4] = 0.8;
stateAllowImageChange[4] = false;
stateSequence[4] = "Reload";
stateEjectShell[4] = true;
//stateSound[4] = pistolReloadSound;

// No ammo in the weapon, just idle until something
// shows up. Play the dry fire sound if the trigger is
// pulled.
stateName[5] = "NoAmmo";
stateTransitionOnAmmo[5] = "Reload";
stateSequence[5] = "NoAmmo";
stateTransitionOnTriggerDown[5] = "DryFire";

// No ammo dry fire
stateName[6] = "DryFire";
stateTimeoutValue[6] = 1.0;
stateTransitionOnTimeout[6] = "NoAmmo";
stateSound[6] = pistolFireEmptySound;
};


//-----------------------------------------------------------------------------

function pistolImage::onFire(%this, %obj, %slot)
{
%projectile = %this.projectile;

// Decrement inventory ammo. The image's ammo state is update
// automatically by the ammo inventory hooks.
%obj.decInventory(%this.ammo,1);

%currentAmmo = %obj.getInventory(%this.ammo);
%obj.client.setAmmoAmountHud(%currentAmmo);

// Determin initial projectile velocity based on the
// gun's muzzle point and the object's current velocity
%muzzleVector = %obj.getMuzzleVector(%slot);
%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(
VectorScale(%muzzleVector, %projectile.muzzleVelocity),
VectorScale(%objectVelocity, %projectile.velInheritFactor));

// Create the projectile object
%p = new (%this.projectileType)() {
dataBlock = %projectile;
initialVelocity = %muzzleVelocity;
initialPosition = %obj.getMuzzlePoint(%slot);
sourceObject = %obj;
sourceSlot = %slot;
client = %obj.client;
};
MissionCleanup.add(%p);
return %p;
}
#3
04/13/2006 (5:43 pm)
Did you put that one part in player.cs?
#4
04/13/2006 (5:50 pm)
Which part specifically?

i did do the maxInv section in player.cs, yes
#5
07/29/2009 (7:09 pm)
Just adding this here incase someone else has this problem in the future.

the game.cs needs to have this line added. lets say for giggles your weapon is called pistol and the .cs file is called pistol.cs place the .cs file in the server/scripts folder. Now add this line to the game.cs.

exec("./Pistol.cs");

place it after.

exec("./crossbow.cs");

now goto the editor and in the static/weapons branch you should see it. Don't forget to add the weapon and ammo to the allowable inventory in the player.cs. Also you need to add a line of code to the config.cs to bind a key to make the weapon active.

Jetsum

#6
07/29/2009 (7:35 pm)
Better yet, don't mess with the config.cs file and just delete it. Put your keybind in default.bind.cs and when you next run the game Torque will auto-generate a new config.cs for you.