Author Topic: PC drops items  (Read 421 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
PC drops items
« on: June 10, 2011, 03:22:03 pm »


               How do you script a PC to drop an item somewhere within 2 meters? I know about the put down item function, but I don't want to animate the pc. I am trying to simulate the PC dropping an item accidentally as if it was knocked from their hand and fell to the floor. 
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
PC drops items
« Reply #1 on: June 10, 2011, 04:29:12 pm »


               The best way i can think of would be to  copy the item to the ground then destroy the original item.   To use any of the action functions to keep the original item would mean that the action que would have to be cleared in order to move the item.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
PC drops items
« Reply #2 on: June 10, 2011, 05:11:30 pm »


                 I would do it the same way, copy the item to a location, and destroy the original.

  In case you don't hve something for it, this ugly script is my random location generator:

// (5/14/2011) - FB
//// returns a random location fDistance from lTarget
location FB_GetRandomLocation (location lTarget, float fDistance)
{
 int nTemp = FloatToInt (fDistance * 20.0);
 int nRandomX = (Random (nTemp) + 1) - (nTemp / 2);
 int nRandomY = (Random (nTemp) + 1) - (nTemp / 2);
 float ModX = IntToFloat (nRandomX) / 10.0;
 float ModY = IntToFloat (nRandomY) / 10.0;
 vector vPos  = GetPositionFromLocation (lTarget);
 float  fPosX = vPos.x;
 float  fPosY = vPos.y;
 float  fPosZ = vPos.z;
 vPos    = Vector (fPosX + ModX, fPosY + ModY, fPosZ);
 lTarget = Location (GetAreaFromLocation (lTarget), vPos, 0.0);
 return lTarget;
}

Likely there are more efficient ones about on the vault or this site, but it's worked well so far for me.
               
               

               


                     Modifié par Failed.Bard, 10 juin 2011 - 04:14 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
PC drops items
« Reply #3 on: June 10, 2011, 05:31:55 pm »


               Thanks. I'll see how much of the object gets copied. I tend to customize names, descriptions and set local variables on items via scripts during play. I'll double check that everything gets copied, and if not I suppose I'll have to write my own customized version of copy object.

Its silly that one can't simply jump items to locations in the same way that creatures are.

Regarding position: that randomizing position could be fun. Given your interest in this sort of thing however you should check out the functions in "x0_i0_position". Its a handy include. I'll likely be using some functions from that include to calculate location a little to the left, right, and away from the pc depending on which slot the items were equipped in.
               
               

               


                     Modifié par henesua, 10 juin 2011 - 04:33 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
PC drops items
« Reply #4 on: June 12, 2011, 06:06:59 pm »


               There should be no trouble with copying the object.  Everything that you customized should be copied over with the item.  The one thing that may not copy over would be local vars on the item.   I know that you can set CopyItem to copy the vars, unfortunatly it has to copy the item to an objects inventory.  

When You first posted the thread I got an itch to write this function.   I finally found the time.

//Gets a random location around an object.
// - oObject : The object to get the random location around
// - fMaxDist: The maximum distance from oObject.
// - fMinDist: The mininum distance from oObject, Defaults to 0.
// - nAngle  : The angle offset from the orintation of oObject. defaults to 0.
//             0 would be the direction that oObject is facing.
// -  nAngleSpread: defines the size of the arc that the location fall into.
//             The spread is on both sides of nAngle.Defaults to 180 that would
//             be the full 360 deg around oObject
// - examples: If nAngle is 0 and nAngleSpread is 15. the location returned will
//             be in the 30deg arc in front of the object. 15deg to the right
//             and left.
//             If nAngle is 90 and  nAngleSpread is 90 the location returned will
//             be Anywhere to the left of oObject. Angel 0 - 180 from objects orintation.
location GetRndLocRoundObject( object oObject, float fMaxDist, float fMinDist=0.0, int nAngle=0,int nAngleSpread=180);
location GetRndLocRoundObject( object oObject, float fMaxDist, float fMinDist=0.0, int nAngle=0,int nAngleSpread=180)
{

   vector   vDir;
   // Set fMaxDist to random distance in range. Prescion 2 decimal places.
   fMaxDist =(fMaxDist - fMinDist)*100;
   fMaxDist = Random(FloatToInt(fMaxDist)) / 100.0 + fMinDist;

   // Set nAngle to a random angle offest.
   nAngle = Random(nAngleSpread*2)-nAngle;

   // Get the direction our random location is in from oObject.
   vDir = AngleToVector(GetFacing( oObject) + nAngle);

   // Adjust the magnitude to the correct distance.
   vDir.x *= fMaxDist;
   vDir.y *= fMaxDist;

   //construct and return our location.
   return Location(GetArea(oObject), GetPosition(oObject)+vDir, VectorToAngle(vDir)+180);
}

 
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
PC drops items
« Reply #5 on: June 14, 2011, 11:01:55 pm »


               Lightfoot, thanks for the code. I am impressed by the number of scripts that you give back to the community.

Copy Item is working well for me.

For the placement of objects I am using functions from "x0_i0_position" Its a useful include. I use it often.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
PC drops items
« Reply #6 on: June 22, 2011, 07:44:11 pm »


               I wanted to add that after testing the items created by CopyObject, I have determined that Name, Description and local variables are all copied to the new item.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
PC drops items
« Reply #7 on: June 22, 2011, 08:22:55 pm »


               

henesua wrote...

I wanted to add that after testing the items created by CopyObject, I have determined that Name, Description and local variables are all copied to the new item.


Did you check dynamic vs. static variables?    (created in toolset vs. created by script)
If so, Cool.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
PC drops items
« Reply #8 on: June 23, 2011, 02:06:10 am »


               these were dynamic - created by script.