Solved - Pickup weapon with a keybind

There are no stupid questions, just stupid answers.
  • 1
  • 2
15 posts Page 2 of 2
Posts: 55
Joined: Tue Apr 14, 2015 5:02 am
by SqHd » Sun Nov 29, 2015 8:10 pm
Thanks for the reminder! Def lots of great stuff on the wiki!
Posts: 55
Joined: Tue Apr 14, 2015 5:02 am
by SqHd » Thu Mar 24, 2016 9:30 pm
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!
Site Admin
Posts: 37
Joined: Tue Feb 03, 2015 8:55 pm
by TRON » Fri Mar 25, 2016 1:49 am
Edit script file game/scripts/server/inventory.cs and find
function serverCmdUse(%client, %data)
add this function below it
function 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");
Next edit file game/scripts/client/default.bind.cs and find
moveMap.bindCmd(keyboard, "r", "commandToServer('reloadWeapon');", "");
add this line below it
moveMap.bindCmd(keyboard, "e", "commandToServer('PickupFacing');", "");
Do the same above procedure for preferences file game/scripts/client/config.cs

Now 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.
Posts: 55
Joined: Tue Apr 14, 2015 5:02 am
by SqHd » Fri Mar 25, 2016 2:32 am
@ 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.)
Jason Campbell
Posts: 362
Joined: Fri Feb 13, 2015 2:51 am
by Jason Campbell » Fri Mar 25, 2016 5:10 pm
That is awesome. I was trying to do this in my last project. I couldnt figure out how to apply to weapons either. Awesome.
  • 1
  • 2
15 posts Page 2 of 2

Who is online

Users browsing this forum: No registered users and 10 guests