Jump to content

Solved - Pickup weapon with a keybind


Recommended Posts

Posted (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 by SqHd
Posted

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.

Posted

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)

  • 3 months later...
Posted

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!

Posted

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.

Posted

@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.)

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...