Game Development Community

Weapon Switching

by arda · in Torque Game Engine · 05/03/2005 (3:15 pm) · 5 replies

Hi,

I implemented the code below to switch between weapons,
started with rocketlauncer mounted at mountpoint 0, and it works well.

Then I switch to crossbow, then it also works fine, but it happens when I switch to rocketlauncher.
It does not fire a rocketammo.

Am I doing something wrong.

Cheers


function serverCmdChangeWeapon(%client, %weapon_num)
{
	echo("Change Weapon");
	// get the player object
	%player = %client.player;
	
	if (%weapon_num == 1)
	{
		%player.setInventory(Rocket, 1);
		%player.setInventory(RocketAmmo, 10);
		%player.mountImage(RocketLauncherImage, 0);
	}
	else if (%weapon_num == 2)
	{
		%player.setInventory(Crossbow,1);
		%player.setInventory(CrossbowAmmo,10);
		%player.mountImage(CrossBowImage, 0);
	}
	else
	{
		messageAll('MsgClientKilled','Weapon Slot %1 is empty',%weapon_num);
	}
}

#1
05/03/2005 (3:19 pm)
Not enough information post you datablocks please
#2
05/03/2005 (4:34 pm)
Hi Anthony,

If you ask for CrossBowImage, and RocketLauncher datablocks, here they are

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

datablock ShapeBaseImageData(CrossbowImage)
{
   // Basic Item properties
   shapeFile = "~/data/shapes/crossbow/weapon.dts";
   emap = true;

   // 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 = Crossbow;
   ammo = CrossbowAmmo;
   projectile = CrossbowProjectile;
   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";

...
};

RocketLauncherImage datablock
datablock ShapeBaseImageData( RocketLauncherImage )
{
	shapeFile = "~/data/shapes/rocket_launcher/rocket_launcher.dts";

   // Projectile && Ammo.
   item = Crossbow;
   ammo = CrossbowAmmo;	
   projectile = RocketProjectile;
   projectileType = Projectile;
   fireTimeout = 0;
	emap = true;

    // 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;

	// Specify mountPoint & offset for 3rd person, and eyeOffset for first 
    // person rendering.
	mountPoint = 0;
    offset = "0.0 0.0 0.0";
    eyeOffset = "0.0 0.0 0.0";

......
};
#3
05/03/2005 (4:37 pm)
That would be bacause you have ammo defined as CrossbowAmmo
#4
05/03/2005 (4:43 pm)
Erm? Why is all this nessacary for just changing weapons? For weapon switching I've just always had my multiple weapons, and in config.cs under starter.fps/client added

moveMap.bindCmd(keyboard, "1", "commandToServer(\'use\',\"Crossbow\");

moveMap.bindCmd(keyboard, "2", "commandToServer(\'use\',\"RocketLauncher\");


Also, dreamer beat me to it, but your rocket launcher has the same sort of ammo " ammo = CrossbowAmmo; " under the RockerLauncherImage datablock needs to have it's own ammo class...

Max
#5
05/04/2005 (10:24 am)
Thanks for the answers dreamer and max.

@max
I'll try that later. I tried weapon switching resource but it did not worked for me. So I tried this way.