### Solved - Pickup weapon with a keybind

There are no stupid questions, just stupid answers.
• 1
• 2

#### Solved - Pickup weapon with a keybind

SqHd
Posts: 55
Joined: Tue Apr 14, 2015 5:02 am
Is there an easy way to pick up a weapon or ammo with a keybind instead of on collision?
Currently, when walking over a weapon, it's added to inventory. Also, you can throw the weapon (alt + w) or ammo (alt + a).
Thanks!
Last edited by SqHd on Fri Mar 25, 2016 2:34 am, edited 1 time in total.

#### Re: Pickup weapon with a keybind?

Nils
Posts: 213
Joined: Thu Feb 05, 2015 3:32 am
There's a script example in the "Torque 3D Game Development Cookbook" on page 154 -> Google books

The are also some resources about it on http://www.garagegames.com/community/resources, a bit old but should be working.

#### Re: Pickup weapon with a keybind?

SqHd
Posts: 55
Joined: Tue Apr 14, 2015 5:02 am
Thanks the Cookbook script worked great.
Now I just need to figure out how to apply it to weapons and mounting the image in the characters hands.

#### Re: Pickup weapon with a keybind?

Dwarf King
Posts: 185
Joined: Thu Feb 05, 2015 7:20 pm
Thanks the Cookbook script worked great.
Now I just need to figure out how to apply it to weapons and mounting the image in the characters hands.

Code: Select all

%player.setInventory(RocketLauncher, 1); %player.setInventory(RocketLauncherAmmo, %player.maxInventory(RocketLauncherAmmo)); %player.mountImage(RocketLauncherImage, 0); 
As a simple example

#### Re: Pickup weapon with a keybind?

SqHd
Posts: 55
Joined: Tue Apr 14, 2015 5:02 am
Thanks. But I'm not sure where to put that code.
Should it be in the serverCmdPickupObject function somewhere?
(Trying to be able to pick up weapons with a keybind instead of collision)

#### Re: Pickup weapon with a keybind?

Dwarf King
Posts: 185
Joined: Thu Feb 05, 2015 7:20 pm
Thanks. But I'm not sure where to put that code.
Should it be in the serverCmdPickupObject function somewhere?
(Trying to be able to pick up weapons with a keybind instead of collision)
It could be put almost anywhere. If you collided with the weapon you could throw the code in as a callback somehow or as a trigger or upon spawn. It all depends on your needs. The code example above is from an example where the code is executed during a spawn.

Se here:
http://www.garagegames.com/community/re ... view/21002

The scripting system is as such very flexible.

I guess you could make some serverCmdFunctionName in commands.cs and call it from the default.bind.cs file upon keystroke hit

#### Re: Pickup weapon with a keybind?

SqHd
Posts: 55
Joined: Tue Apr 14, 2015 5:02 am
I'll give it a shot. (Scripting newb here!)

#### Re: Pickup weapon with a keybind?

Dwarf King
Posts: 185
Joined: Thu Feb 05, 2015 7:20 pm
I'll give it a shot. (Scripting newb here!)
Steve Acaster made some real good tutorials:
http://www.garagegames.com/community/re ... D/101767/3

The simple fps tutorial takes you through all the basic step by step and in no time you get the hang of it

#### Re: Pickup weapon with a keybind?

SqHd
Posts: 55
Joined: Tue Apr 14, 2015 5:02 am
Thanks for the link. It may be time to learn TorqueScript!
And I've heard of the great Steve Acaster...

LukasPJ