Jump to content

Solved - Pickup weapon with a keybind


SqHd

Recommended Posts

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 by SqHd
Link to comment
Share on other sites

  • 3 months later...

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!

Link to comment
Share on other sites

Edit script file game/scripts/server/inventory.cs and find

function serverCmdUse(%client, %data)
{
   %client.getControlObject().use(%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");
      %player.pickup(%result);
   }
}

 

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...