[SOLVED]PickUp/Drop object/item script

Scripting questions, discussions, etc
3 posts Page 1 of 1
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
  by Bishop » Sun Aug 18, 2019 7:06 pm
Hello, I need drop mounted item...I have this script with mouse 0 button1 - dropItem and
button0 - RayCastObject
....pick up item works great but when I want to drop an item it doesn't work.
function serverCmdRayCastObject(%client,%obj)
{
   %range = 4;
   $control = %client.getControlObject();
   %eyePos = $control.getEyePoint();
   %eyeVec = $control.getEyeVector();
   %mask = $TypeMasks::StaticShapeObjectType|$TypeMasks::ItemObjectType;
   %dirScaled = VectorScale(%eyeVec, %range);
   %endPoint = VectorAdd(%eyePos, %dirScaled);
   %result = containerRayCast(%eyePos, %endPoint, %mask, %client.getControlObject(), false);
   if (getWordCount(%result) > 0 && getWord(%result, 0) !$= "0")
   {
        %obj = getWord(%result, 0);
        if (%obj.internalName $= "Item")
        {
            ItemText.setText(%obj.name);
            ItemText.schedule(500, "setText", ""); 
         }
         if (%obj.parentGroup $= "InteractiveItems")
         {
            ItemText.setText(%obj.name SPC "PICKED UP");
            ItemText.schedule(2000, "setText", "");
            $control.mountObject (%obj, 0);
          }
          if (%obj.isMounted ())
          {
            echo("is Mounted");
            $control.unmountObject (%obj);
          }
     }
}
//-----------------------------------------------------------------------------
//.     Drop Items command 
//-----------------------------------------------------------------------------
function serverCmddropItem (%client, %obj)
{
   ItemText.setText("ITEM DROPED");
   ItemText.schedule(1000, "setText", "");
}
//------------------------------------------------------------------------------
....so unmount works this way but I need Drop an item only when I press the mouse button.
Last edited by Bishop on Fri Aug 23, 2019 5:06 pm, edited 1 time in total.
Duion
Posts: 1369
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Tue Aug 20, 2019 6:57 pm
There is a hotkey to throw the weapon you are holding, just press it. You can modify the throw function and reduce the force and maybe remove the throw sound and it should be pretty good.
Bishop
Posts: 74
Joined: Wed Dec 09, 2015 2:30 am
by Bishop » Fri Aug 23, 2019 4:33 pm
@ Duion Thanks,....I only use Empty project template for my projects so I'm putting together from the ground simple game mechanics scripts everything as needed by the project.....slowly and step by step....while looking in the documentation and net.
......after a short pause, i finally put it together and a script for a pick up and drop objects / items works great....serverCmdRayCastObject(%client, %obj) function takes care of mounting item to mount node and serverCmddropItem(%client, %obj) takes care of drop(unmount) item....This..
%control = %client.getControlObject();
%mountedItem = %control.getMountedObject(0);
if (%mountedItem.isMounted())
{
   %mountedItem.unmount();
}
.....it was crucial that drop / unmount work.

Image
3 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests