REDUX HL2 Style Multiple Weapons to 1 KeyBind
by Steve Acaster · in Torque 3D Professional · 11/23/2009 (8:04 pm) · 4 replies
Shampoo and conditioner?
Take 2 bottles into the shower?
0-9 not enough keys to bind all of your weapons to?
Now wash and go!
HalfLife2 style switching between weapons that are bound to the same key.
=============================================================================
Scroll down to comment 3 for the new and hoepfully multiplayer friendly code.
edited 2022GMT 26Nov09
=============================================================================
Now the important word is probably "switch", which is initially what I attempted to use ... but just ended up confusing myself ... again. So I came up with this more idiot proof version of the function instead.
And to prevent confusion, the 2 weapons that the below script is using are called tap and smg.
The final echo reports which weapon is being held and then what it is being changed to ... so if they're the same one it will report the name twice.
And don't forget to update config.cs with the new keybind.
Tested it plenty and it works fine, however if anyone has a better way, feel free to add it.
Take 2 bottles into the shower?
0-9 not enough keys to bind all of your weapons to?
Now wash and go!
HalfLife2 style switching between weapons that are bound to the same key.
=============================================================================
Scroll down to comment 3 for the new and hoepfully multiplayer friendly code.
edited 2022GMT 26Nov09
=============================================================================
Now the important word is probably "switch", which is initially what I attempted to use ... but just ended up confusing myself ... again. So I came up with this more idiot proof version of the function instead.
And to prevent confusion, the 2 weapons that the below script is using are called tap and smg.
The final echo reports which weapon is being held and then what it is being changed to ... so if they're the same one it will report the name twice.
function closequarterweapons(%val)
{
%player = LocalClientConnection.getControlObject();
%curWeapon = %player.getMountedImage($WeaponSlot);
%weaponName = %curWeapon.item.getName();
if(%player.getinventory(tap) ==0 && %player.getinventory(smg) ==0)
{
echo("Don't have either weapon");
return;
}
else
{
if(%val)
{
if(%player.getinventory(tap) !=0 && %player.getinventory(smg) ==0)
commandToServer('use',"tap");
break;
if(%weaponName !$="smg" && %player.getinventory(smg) !=0)
commandToServer('use',"smg");
break;
if(%weaponName $="smg" && %player.getinventory(tap) !=0)
commandToServer('use',"tap");
break;
}
echo("Selected Weapon is " @ %weaponName);
}
}
moveMap.bind(keyboard, "2", closequarterweapons);And don't forget to update config.cs with the new keybind.
Tested it plenty and it works fine, however if anyone has a better way, feel free to add it.
About the author
One Bloke ... In His Bedroom ... Making Indie Games ...
#2
11/25/2009 (5:07 pm)
Thanks for the pointers Davide, you are correct on all counts.
#3
11/26/2009 (4:17 pm)
Code redux - should be multiplayer friendly now.function closequarterweapons(%val)
{
if(%val)
{
commandToServer('ToggleCQW');
}
}
moveMap.bind(keyboard, "3", closequarterweapons);
function serverCmdToggleCQW(%client)
{
if(%client.player.getState() $= "Dead")
return;
if(%client.player.getinventory(smg) ==0 && %client.player.getinventory(tap) ==0)
return;
%curWeapon = %client.player.getMountedImage($WeaponSlot);
%weaponName = %curWeapon.item.getName();
if(%weaponName !$="smg" && %client.player.getinventory(smg) !=0)
commandToClient(%client,'ToggleCQW1',%client);
if(%weaponName $="smg" && %client.player.getinventory(tap) !=0)
commandToClient(%client,'ToggleCQW2',%client);
}
function clientcmdToggleCQW1(%client)
{
commandToServer('use',"smg");
}
function clientcmdToggleCQW2(%client)
{
commandToServer('use',"tap");
}
#4
Steve posted this also as a resource:
http://www.garagegames.com/community/blogs/view/20789
01/26/2011 (9:50 am)
FYI:Steve posted this also as a resource:
http://www.garagegames.com/community/blogs/view/20789
Torque Owner Davide Archetti
Default Studio Name
Perhaps I'm wrong, but LocalClientConnection isn't defined client side, unless you are the host.
Also the inventory isn't defined client side.
I think you have to move all the function server side.
The break statement has no meaning to be there. (unless there is something about torque script that I don't know)
But, really I haven't understood what it should do, because indipendently of the current active weapon, if you have a tap in inventory you use the tap, at least, this is the intention, but the break statement doesn't interrupt the execution of the code.
So it goes down, and if you were mounting a tap and you have un smg, you use an smg, otherwise ... well it is going to be too complicated to write everything, but if the result you have is what you designed, well, it's ok :)
Just check if it works when you are not the host.