Game Development Community

Weapons

by Adam · in Torque Game Engine · 09/14/2006 (3:09 pm) · 3 replies

I have figured out how to change the players initial weapon at the start and how to put different weapons into the game. The question I have is how do I change weapons when I have more than 1 in inventory. I see there is a commandToServer to use Crossbow when 1 is pressed, but I don't see it being implemented anywhere. Could someone point me in the right direction?

Thanks in advance

Adam

#1
09/16/2006 (9:10 am)
Well each weapon model will need to have its own script, place in server/scripts. You must exec the script in game.cs ( exec("./myGun.cs"); ). Use crossbow.cs as a reference. Search for "// Starting equipment" in game.cs within the "GameConnection::createPlayer function".

Add the following lines after crossbow, this will add the gun to our inventory:
// Starting equipment
   %player.setInventory(myGun,1);
   %player.setInventory(myGun,12);
   %player.mountImage(myGun,0);

Save and close game.cs.

Open player.cs in server/scripts and Search for "// Allowable" then add the following lines to the end:
maxInv[myGunAmmo] = 120; // we add this line for how much ammo you start with.
   maxInv[myGun] = 1; // we add this line for one weapon of that type

Bind your weapons to the 'use' function inside of default.bind.cs locate in client\scripts.
Search for the following line:
moveMap.bindCmd(keyboard, "1", "commandToServer('use',\"Crossbow\");", "");

Below this line add the following, this will keybind the weapon to 2:
moveMap.bindCmd(keyboard, "2", "commandToServer('use',\"myGun\");", "");

Delete default.bind.cs.dso in client\scripts.
Delete config.cs and config.cs.dso in client. Dont worry it will recompile when you launch Torque.

Press key for which weapon you want. If you need more details just let me know. Whatever weapon you add last to the Starting equipment in game.cs will be the weapon you start with. I hope this help.
#2
09/16/2006 (3:00 pm)
Wow, that was a lot easier than I thought, I didn't realize all I had to do was bind the commandToServer and that would switch the weapons. Thanks alot, now I can add a couple more guns to my game.

I really appreciate you taking the time to help me out.

Adam
#3
09/16/2006 (3:29 pm)
You very welcome.

Happy Torquing