Game Development Community

Weapon switching?

by Julian Ridley · in Torque Game Engine · 06/21/2004 (5:13 pm) · 16 replies

Hey, I am trying to add another weapon to the starter.fps game. I have added it in all the proper places I think. But I can not switch to it in game. Can someone tell me how I can switch between weapons?

Another note. I looked at tutorials, and alot of them mention the rifle. However I can't find it anywhere in my torque stuff, is it supposed to be there?

#1
06/21/2004 (5:46 pm)
Rifle was replaces by the cross-bow, and they had a reasource on the forums about it fo a search.
#2
06/21/2004 (6:47 pm)
I cannot find a resource on how to switch weapons... Can someone help me out?
#3
06/21/2004 (7:26 pm)
Type moveMap.bindCmd(keyboard, "2", "commandToServer(\'use\',\"Mp5\");", ""); Into the console where 2 is the key you want and Mp5 is the name of the weapon.
#4
06/21/2004 (7:41 pm)
You can also try this handy tutorial on Game Beavers here.

Assume we'd like to add a new MP5 and we have already created our nifty MP5.cs script that specifies all the above information concerning the mp5.


game\starter.fps\client\scripts\[b]defaultbind.cs[/b] and game\starter.fps\client\[b]config.cs[/b]
...
//------------------------------------------------------------------------------
// Misc. Player stuff
//------------------------------------------------------------------------------

moveMap.bindCmd(keyboard, "ctrl w", "commandToServer('playCel',\"wave\");", "");
moveMap.bindCmd(keyboard, "ctrl s", "commandToServer('playCel',\"salute\");", "");
moveMap.bindCmd(keyboard, "ctrl k", "commandToServer('suicide');", "");
moveMap.bindCmd(keyboard, "1", "commandToServer(\'use\',\"ak47\");", "");
moveMap.bindCmd(keyboard, "2", "commandToServer(\'use\',\"shotgun\");", "");
[b]moveMap.bindCmd(keyboard, "3", "commandToServer(\'use\',\"mp5\");", "");[/b]
moveMap.bindCmd(keyboard, "4", "commandToServer(\'use\',\"grenadeLauncher\");", "");
moveMap.bindCmd(keyboard, "5", "commandToServer(\'use\',\"LaserBeam\");", "");
moveMap.bindCmd(keyboard, "6", "commandToServer(\'use\',\"flamer\");", "");
moveMap.bindCmd(keyboard, "7", "commandToServer(\'use\',\"grenadeTimer\");", "");
moveMap.bindCmd(keyboard, "8", "commandToServer(\'use\',\"missileLauncher\");", "");

...
#5
06/21/2004 (7:45 pm)
\game\starter.fps\server\scripts\[b]game.cs[/b]

...

   // Load up all datablocks, objects etc.  This function is called when
   // a server is constructed.
   exec("./audioProfiles.cs");
   exec("./voicepacks.cs");
   exec("./camera.cs");
   exec("./markers.cs"); 
   exec("./triggers.cs"); 
   exec("./inventory.cs");
   exec("./shapeBase.cs");
   exec("./item.cs");
   exec("./health.cs");
   exec("./staticShape.cs");
   exec("./explosiondata.cs");
   exec("./explosions.cs");
   exec("./weapon.cs");
   exec("./radiusDamage.cs");
   exec("./crossbow.cs");
   exec("./player.cs");
   exec("./chimneyfire.cs");
   exec("./laserbeam.cs");
   exec("./shotgun.cs");
   exec("./ak47.cs");
   [b]exec("./mp5.cs");[/b]
...

\game\starter.fps\server\scripts\[b]player.cs[/b]
...
   // Allowable Inventory Items
   maxInv[BulletAmmo] = 20;
   maxInv[HealthKit] = 1;
   maxInv[RifleAmmo] = 100;
   maxInv[CrossbowAmmo] = 50;
   maxInv[Crossbow] = 1;
   maxInv[Rifle] = 1;

   [b]maxInv[mp5] = 1;
   maxInv[mp5Ammo] = 200;[/b]

   maxInv[ak47] = 1;
   maxInv[ak47Ammo] = 150;

   maxInv[flamer] = 1;
   maxInv[flamerAmmo] = 500;

   maxInv[grenadeLauncher] = 1;
   maxInv[grenadeLauncherAmmo] = 14;
...
Then drop the mp5 pick up item in the map and have fun... should be able to pick it up and then switch to the weapon with the key bindings you set above.
#6
06/21/2004 (8:05 pm)
Ok, I got that. But how can I use like mousescroll to switch to next weapon instead of having to hit that? Its kinda annoying :P
#7
06/21/2004 (8:24 pm)
You could map the right mouse button this way to switch to the MP5 and write a routine to count each time you switch etc...

Dont know if the mousescroll is mapped in the events or not
moveMap.bind( mouse, button1, "commandToServer(\'use\',\"mp5\");", "");


I dont know but I'm guesing you could do something like this:

defaultbind.cs

function switchWeapon(%val)
{
   $mvWeaponCount1++;
   Switch $mvWeaponCount1
            {
               case 1:   "commandToServer(\'use\',\"ak47\");", "");
               case 2:   "commandToServer(\'use\',\"mp5\");", "");               
               default:  "commandToServer(\'use\',\"mp5\");", "");
            }

}

moveMap.bind( mouse, button1, switchWeapon );
#8
06/21/2004 (8:25 pm)
Ofcourse you'd need to count to a max and reset the count etc.. just a rough sketch of how it might work.
#9
06/21/2004 (8:49 pm)
Or, you can use this. http://www.garagegames.com/mg/forums/result.thread.php?qt=6979
#10
08/23/2004 (5:11 pm)
Britton, thanks for the code, you're awesome! I'm still trying to finish all my art assets before scripting. This sure helps me to swap out my weapon models and review them, instead of reloading the mission each time.
#11
01/06/2008 (7:04 am)
Thanks for the code. :-)

BTW, Game Beaver's link above is broken now. (it leads wrong site)
#12
02/03/2008 (9:02 pm)
You also need to secify inventory to fire up.

%player.setInventory(mp5,1);
   %player.setInventory(mp5Ammo,100);

There should be more than one ammo in the inventory, so you can fire up.
#13
05/22/2008 (4:37 pm)
You need to specify where to specify inventory.
#14
05/26/2008 (1:58 pm)
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=5907

This a resource in script.

It maybe what your looking for.
#15
05/26/2008 (3:57 pm)
Thanks james. I did come across this resource. I'm looking to switch via different buttons as opposed to one button. I will run through this one and see if I can figure it out.
#16
05/26/2008 (6:03 pm)
Cool I looked at the script I see

prevWeapon and nextWeapon moveMap.bind to the functions

Hmm, I haven't done much torque script, maybe

set a moveMap.bind for each weapon

moveMap.bind(keyboard, q, crossbow);

then

function crossbow (%val)
if ( %val )
{
commandToServer( 'cycleWeapon', "crossbow" );
}
and then pass it to this function !-> function ShapeBase::cycleWeapon( %this, %data )

maybe change the if, else if statements

I don't know off hand it may work and may not. Just an idea

Sorry about not using code blocks I was just brainstorming on the issue