Jump to content

Solved - Pickup weapon with a keybind


SqHd
 Share

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

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.

 

%player.setInventory(RocketLauncher, 1);  
%player.setInventory(RocketLauncherAmmo, 
%player.maxInventory(RocketLauncherAmmo));  
%player.mountImage(RocketLauncherImage, 0);

 

As a simple example :D

Link to comment
Share on other sites

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)

 

It could be put almost anywhere. If you collided with the weapon you could throw the code in as a callback somehow or as a trigger or upon spawn. It all depends on your needs. The code example above is from an example where the code is executed during a spawn.


Se here:

http://www.garagegames.com/community/resources/view/21002


The scripting system is as such very flexible.


I guess you could make some serverCmdFunctionName in commands.cs and call it from the default.bind.cs file upon keystroke hit :D

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.

 Share

×
×
  • Create New...