Game Development Community

Changing weapon

by Jonas · in Torque 3D Beginner · 06/04/2010 (1:23 pm) · 3 replies

Hi everyone!

Before i start i just wanna say that this thread will contain major noobness because i am quite the beginner.

On to the problem:

Ok this is the situation i learn something best by doing and finding out stuff besides tutorials so what i am trying to do is introduce weapon change into a new "Full" project by just using the FPS example coming with the program.

How would i go about locating where in the script files the change weapon command is? if it is a multi file command stretching over multiple files please just tell me which files and i will be on my way.

Again i am not asking you to help me do this just where i can locate it in the FPS example.

NOTE: i know about complications introducing new code from a completely different program but its a part of the learning for me to adapt code.

Best regards Jonas.

About the author

Freelance 3D artist at day scripter/coder on Enduring Life at night. Lover of all things TorqueScript.


#1
06/04/2010 (2:04 pm)
Change weapon usual goes on the "use" function - which is played via a keybind in scripts/client/default.bind.cs and use() function is in inventory.cs - and (scripts)weapon.cs onuse().

The actually command is %whatever_your_Player_ID_is.mountimage(weapon_name_image, weaponSlot);
eg:
%player.mountimage(rifleImage, 0);

The actual model of the weapon that the player holds is called an "image" and is referenced in eg: scripts/server/weapons/rocketlauncher.cs - rocketlauncherImage()
#2
06/04/2010 (4:29 pm)
The FPS Example and the Full Template both use the same weapon change/cycling method(s) - no need to add anything from one to the other.

The keybind per weapon method that Steve mentions (a FPS standard) is one way and is really the only change to be made on a per project basis (keybinds for each weapon that is).

The other method is through a weapon cycle function. Weapon cycling can be done through a fwd/back keybind (q/ctrl+q by default) or the mouse wheel. The client-side fwd/back (key/mousewheel) functions (nextWeapon, prevWeapon, and mouseWheelWeaponCycle) are found in scripts/client/default.bind.cs, and the server-side weapon cycling function (ShapeBase::cycleWeapon) is found in scripts/server/weapon.cs. The key for this method to work properly is to set up your weapon order. This is the order in which you cycle from one weapon to the next and is as simple as listing them in your preferred order, ie:
// Now create the Index/array by passing a name and order# for each weapon.
// NOTE:  the first weapon needs to be 0.
WeaponOrder(Fist, 0);
WeaponOrder(Sword, 1);
WeaponOrder(Flintlock, 2);
WeaponOrder(Blunderbuss, 3);
WeaponOrder(SteamCannon, 4);
WeaponOrder is a support function that handles setting up the array as needed for the cycleWeapon function.
#3
06/05/2010 (5:17 am)
Ah i see, i will have a look at it then and tell you guys the out come of it thanks!

Best regards Jonas.