Jump to content

[SOLVED]PickUp/Drop object/item script


Recommended Posts

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.

Edited by Bishop
Link to post
Share on other sites

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


Pick-Up-Drop-05.gif

Link to post
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...