SqHd Posted November 22, 2015 Posted November 22, 2015 (edited) 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! Edited March 25, 2016 by SqHd Quote
Nils Posted November 23, 2015 Posted November 23, 2015 There's a script example in the "Torque 3D Game Development Cookbook" on page 154 -> Google booksThe are also some resources about it on http://www.garagegames.com/community/resources, a bit old but should be working. Quote
SqHd Posted November 23, 2015 Author Posted November 23, 2015 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. Quote
SqHd Posted November 23, 2015 Author Posted November 23, 2015 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) Quote
SqHd Posted November 24, 2015 Author Posted November 24, 2015 I'll give it a shot. (Scripting newb here!) Quote
SqHd Posted November 24, 2015 Author Posted November 24, 2015 Thanks for the link. It may be time to learn TorqueScript!And I've heard of the great Steve Acaster... 8-) Quote
LukasPJ Posted November 25, 2015 Posted November 25, 2015 If you are trying to learn TorqueScript, remember that we have a Wiki:http://wiki.torque3d.org/wiki:_scripter-startLots of great stuff there :) Quote
SqHd Posted November 29, 2015 Author Posted November 29, 2015 Thanks for the reminder! Def lots of great stuff on the wiki! Quote
SqHd Posted March 24, 2016 Author Posted March 24, 2016 Still haven't figured this out for items / weapons yet.I'm not sure how to set up the serverCmd function using the "$TypeMasks::ItemObjectType" (that will be used for the "commandToServer" keybinding.Is it possible to pick them up with a keybind instead of the standard onCollision? Thanks! Quote
TRON Posted March 25, 2016 Posted March 25, 2016 Edit script file game/scripts/server/inventory.cs and findfunction serverCmdUse(%client, %data) { %client.getControlObject().use(%data); }add this function below itfunction serverCmdPickupFacing(%client) { // get player object %player = %client.getControlObject(); // verify it is a player object if (%player.getClassName() !$= "Player") return; // abort, it is not // raycast for an item that the player is facing, and also look for types // that could be between the player and the item they're facing. %typeMask = $TypeMasks::ItemObjectType | $TypeMasks::StaticObjectType; %result = %player.doRaycast(4 /*range*/, %typeMask); // only care about object id part of the result %result = getWord(%result, 0); // pickup only if it's an item if ((%result != 0) && (%result.getClassName() $= "Item")) { echo("Picking up"); %player.pickup(%result); } } Next edit file game/scripts/client/default.bind.cs and findmoveMap.bindCmd(keyboard, "r", "commandToServer('reloadWeapon');", "");add this line below itmoveMap.bindCmd(keyboard, "e", "commandToServer('PickupFacing');", "");Do the same above procedure for preferences file game/scripts/client/config.csNow when you press E key and are within 4 units of an item that you are facing it'll be picked up.Note: There is an issue with stock Lurker and Ryder ammo clip items where they aren't seen via containerRayCast() for some odd reason. Because of this the provided script will not work with those items and there isn't a known workaround for it at this time.Have fun. Quote
SqHd Posted March 25, 2016 Author Posted March 25, 2016 @TRON Thank you so much!!! :D You're a scripting GOD! It works exactly as I was hoping!(Ammo clips probably have too small a collision mesh.) Quote
Jason Campbell Posted March 25, 2016 Posted March 25, 2016 That is awesome. I was trying to do this in my last project. I couldnt figure out how to apply to weapons either. Awesome. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.