Author Topic: Script Request/Consult  (Read 819 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Script Request/Consult
« on: August 17, 2012, 05:03:23 pm »


               I was wondering if anyone might have some input on this


The idea I have, is being able to store patterns of objects in one area

Eg - A group of placeables arranged for example in a Pentagram-esq position.


A waypoint in the middle


A script runs on the waypoint, and then stores the location data associated with the placeables around it - in relation to its own fixed location.


Then.

Another script fires, and can recall this data
Positioning newly created placeables, in the same stored pattern


I know there is a library out there that draws geometric shapes, but I was hoping to have this system setup so I can build complex shapes via toolset in an inaccessible area, and then just copy the pattern as needed- eg - for ritual magic, drawing demon sigils etc on the ground etc.


The way I imagine it working would be getting the
GetPosition of the waypoint in the middle
and then getting the difference between the each placeables 'GetPosition' vector, and the waypoints vector
And then when Re-Creating the pattern, I need to add the target locations 'Vector' to the stored vectors - to generate a relative location for each placeable.

Does this sound like im on the right track?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script Request/Consult
« Reply #1 on: August 17, 2012, 05:26:29 pm »


               Yes, Sounds like the right Idea,   If you do not have something working before I get home. (  4PM EST).  I can wip it up pretty quickly
.  

Information:  

For the stored information per object You need only two Things,  
1) a vector from the wayPoint, Reltive to the facing.  
2) The facing of the object reltive from the facing.

You can store both into a single Local Location on the WayPoint.    
Have to get back to work.   Will check back later.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Script Request/Consult
« Reply #2 on: August 17, 2012, 07:22:51 pm »


               There is this:
http://nwvault.ign.c....Detail&id=2604
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script Request/Consult
« Reply #3 on: August 17, 2012, 11:04:05 pm »


               Ok, Here are two functions, One to create the relative position to be stored and the other to the location to recreate the object at.  

location GetRelativePosBetweenObjects( object oTo,object oFrom =OBJECT_SELF )
{
  return Location
         (
           GetArea(oFrom),
           GetPosition(oTo)-GetPosition(oFrom),
           GetFacing(oTo) - GetFacing(oFrom)
         );
}

location GetRelativePosFromObject( location lRelativeLoc, object oCenter = OBJECT_SELF)
{
   return Location
          (
             GetArea(oCenter),
             GetPosition(oCenter)+ GetPositionFromLocation(lRelativeLoc),
             GetFacing(oCenter)+ GetFacingFromLocation(lRelativeLoc)
          );
}




You may just want to use the code from the functions stright in you code.  It is after all only one line.  I am currently working on a Demo to test everything out.  hopefully everything goes as planned.


EDIT: I forgot to add in the  relative to the objects facing part.  Longe day at work.  Let me grab a cup of coffiee and Ill rewrite it. 
               
               

               


                     Modifié par Lightfoot8, 17 août 2012 - 10:35 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script Request/Consult
« Reply #4 on: August 18, 2012, 12:59:52 am »


               Ok, New working and tested functions, Demo on the way.

location GetRelativePosBetweenObjects( object oTo,object oFrom =OBJECT_SELF )
{

         float fFacingoFrom = GetFacing( oFrom);
         vector vRelativePos =  GetPosition(oTo)-GetPosition(oFrom);
         float  fDist = VectorMagnitude(vRelativePos);
         vRelativePos = AngleToVector
                        (
                           VectorToAngle(vRelativePos)
                           - fFacingoFrom
                        )* fDist;
 
  return Location
         (
           GetArea(oFrom),
           vRelativePos,
           GetFacing(oTo) - fFacingoFrom
         );
}
 

location GetRelativePosFromObject( location lRelativeLoc, object oCenter = OBJECT_SELF)
{

   float fFacingoCenter = GetFacing(oCenter);
   vector vRelativePos = GetPositionFromLocation(lRelativeLoc);
   float  fDist = VectorMagnitude(vRelativePos);
   vRelativePos = AngleToVector(VectorToAngle(vRelativePos)+ fFacingoCenter)* fDist;

   return Location
          (
             GetArea(oCenter),
             GetPosition(oCenter) + vRelativePos,
             GetFacing(oCenter)+ GetFacingFromLocation(lRelativeLoc)
          );
}
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script Request/Consult
« Reply #5 on: August 18, 2012, 02:27:46 am »


               A video of the test is uploading at
(It My Take awhile...    ...Well that upload turned out bad.  Oh weel it is there for what it is worth. )

The Code using the two functions was:


   /*
      HB script on a chest.
      Finds the reltive position of 10 statues around it.
      First time the function runs it stores the relative locations.
      Every HB it:
       - turns the chest.
       - destroys the statues
       - And redraws thenm to there relative positions in relation to the chest.
   */
 
location GetRelativePosBetweenObjects( object oTo,object oFrom =OBJECT_SELF );
location GetRelativePosFromObject( location lRelativeLoc, object oCenter = OBJECT_SELF);

void SaveRelativePositions();
void DestroyStatues();
void RedrawStatues();
void main()
{

   if(!GetLocalInt(OBJECT_SELF,"DoOnce"))
   {
       SaveRelativePositions();
       SetLocalInt( OBJECT_SELF,"DoOnce",TRUE);
   }
   SetFacing(GetFacing(OBJECT_SELF) + Random(20)+ 10.0 );
   DestroyStatues();
   RedrawStatues();
}
 
void SaveRelativePositions()
{
   int x;
   string LocVarName;
   object oStatue;
   for ( x=1;x<11;x++)
   {
      LocVarName = "Statue" + IntToString(x);
      oStatue = GetNearestObjectByTag("Statue",OBJECT_SELF,x);

      SetLocalLocation
      (
         OBJECT_SELF,
         LocVarName,
         GetRelativePosBetweenObjects( oStatue )
       );
   }
}

void DestroyStatues()
{
   int x;
   object oStatue;
   for ( x=1;x<11;x++)
   {
      oStatue = GetNearestObjectByTag("Statue",OBJECT_SELF,x);
      DestroyObject(oStatue);
   }
}

void RedrawStatues()
{
   int x;
   string LocVarName;
   location lRetativeLoc;
   for ( x=1;x<11;x++)
   {
      LocVarName = "Statue" + IntToString(x);
      lRetativeLoc = GetLocalLocation(OBJECT_SELF,LocVarName);
      CreateObject
      (
        OBJECT_TYPE_PLACEABLE,
        "statuetest",
        GetRelativePosFromObject(lRetativeLoc),
        FALSE,
        "Statue"
       );
    }
}
 
location GetRelativePosBetweenObjects( object oTo,object oFrom =OBJECT_SELF )
{

         float fFacingoFrom = GetFacing( oFrom);
         vector vRelativePos =  GetPosition(oTo)-GetPosition(oFrom);
         float  fDist = VectorMagnitude(vRelativePos);
         vRelativePos = AngleToVector
                        (
                           VectorToAngle(vRelativePos)
                           - fFacingoFrom
                        )* fDist;
 
  return Location
         (
           GetArea(oFrom),
           vRelativePos,
           GetFacing(oTo) - fFacingoFrom
         );
}
 
location GetRelativePosFromObject( location lRelativeLoc, object oCenter = OBJECT_SELF)
{

   float fFacingoCenter = GetFacing(oCenter);
   vector vRelativePos = GetPositionFromLocation(lRelativeLoc);
   float  fDist = VectorMagnitude(vRelativePos);
   vRelativePos = AngleToVector(VectorToAngle(vRelativePos)+ fFacingoCenter)* fDist;

   return Location
          (
             GetArea(oCenter),
             GetPosition(oCenter) + vRelativePos,
             GetFacing(oCenter)+ GetFacingFromLocation(lRelativeLoc)
          );
}
               
               

               


                     Modifié par Lightfoot8, 18 août 2012 - 03:27 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Script Request/Consult
« Reply #6 on: August 18, 2012, 06:50:54 am »


               Nice work.  Cool video, too.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script Request/Consult
« Reply #7 on: August 21, 2012, 03:08:06 am »


               Hope you don't mind me playing around with your Idea a little more Baaleos.
 
Once I put out the original functions,  I seen room for expansion.  So I reworked the functions a little bit.

I named the function set :  Relative Oriented Location or ROL for the short. 

  
- Added a function to store an ROL's into an array on an object. 
- Added a function to Raise/rotate a location.
- Added a Function to Scale a ROL
-Added a function to Draw a ROL Array  and scale it.   With Option to change the Tag of the objects drawn.
 
Here Are the functions.   I named it  inc_rol

//Gets the Relative Oriented Location (ROL) from a anchor location to an object.
location GetROLToObject( object oObject,location lAnchor );
location GetROLToObject( object oObject,location lAnchor )
{

         float fAnchorFacing = GetFacingFromLocation( lAnchor);
         vector vRelativePos =  GetPosition(oObject)
                                -GetPositionFromLocation(lAnchor);

         float  fDist = VectorMagnitude(vRelativePos);
         vRelativePos = AngleToVector
                        (
                           VectorToAngle(vRelativePos)
                           - fAnchorFacing
                        )* fDist;
 
  return Location
         (
           GetArea(oObject),
           vRelativePos,
           GetFacing(oObject) - fAnchorFacing
         );
}

// Gets the location that is lROL(Relative Oriented Location) From the Anchor location.
location GetROLFromAnchor( location lROL, location lAnchor);
location GetROLFromAnchor( location lROL, location lAnchor)
{

   float fAnchorFacing = GetFacingFromLocation(lAnchor);
   vector vRelativePos = GetPositionFromLocation(lROL);
   float  fDist = VectorMagnitude(vRelativePos);
   vRelativePos = AngleToVector(VectorToAngle(vRelativePos)+ fAnchorFacing)* fDist;

   return Location
          (
             GetAreaFromLocation(lAnchor),
             GetPositionFromLocation(lAnchor) + vRelativePos,
             fAnchorFacing + GetFacingFromLocation(lROL)
          );
}

// Scales a Relative Oriented Location.
// - 1.0 would be normal scale.
// - 0.5 half distance.
// - 2.0 100% distance increase.
location ScaleROL(location lROL, float fScale= 1.0);
location ScaleROL(location lROL, float fScale= 1.0)
{
   return Location
         (
            GetAreaFromLocation(lROL),
            GetPositionFromLocation(lROL)*fScale,
            GetFacingFromLocation(lROL)
         );
}

//Adds oObject to an ROL array on oArrayObject.
//currently an object can only have one array on it.
void AddObjectToROLArray(object oObject,location lAnchor,object oArrayObject=OBJECT_SELF);
void AddObjectToROLArray(object oObject,location lAnchor,object oArrayObject=OBJECT_SELF)
{
   int nArraySize = GetLocalInt(oArrayObject,"ROL_ARRAY_SIZE");
   string sArraySize = IntToString (nArraySize);
   SetLocalLocation
  (
     oArrayObject,
     "ROL" + sArraySize,
     GetROLToObject(oObject,lAnchor)
  );
  SetLocalString
  (
     oArrayObject,
     "ROL_RESREF"+sArraySize,
     GetResRef(oObject)
  );
  SetLocalInt
  (
     oArrayObject,
     "ROL_TYPE"+sArraySize,
     GetObjectType(oObject)
  );
  SetLocalInt
  (
     oArrayObject,
     "ROL_ARRAY_SIZE",
     ++nArraySize
  );
}

void DrawROLObjectArray(location lAnchor,float fScale,object oArrayObject = OBJECT_SELF, string sTags= "");
void DrawROLObjectArray(location lAnchor,float fScale,object oArrayObject = OBJECT_SELF, string sTags= "")
{
  int nIndex,nType;location lLoc; string sResRef, sIndex;
  int nArraySize = GetLocalInt(oArrayObject,"ROL_ARRAY_SIZE");

  while (nIndex<nArraySize)
  {
     sIndex = IntToString(nIndex);
     lLoc=ScaleROL
         (
           GetLocalLocation(oArrayObject,"ROL"+sIndex ),
           fScale
         );
     lLoc = GetROLFromAnchor(lLoc,lAnchor);
     sResRef = GetLocalString(oArrayObject, "ROL_RESREF"+sIndex );
     nType = GetLocalInt(oArrayObject,"ROL_TYPE"+ sIndex);
     CreateObject(nType,sResRef,lLoc,FALSE,sTags);
     nIndex++;
  }
}

location RotateRaiseLocation(location lLoc,float fRotation,float fRaise=0.0);
location RotateRaiseLocation(location lLoc,float fRotation,float fRaise=0.0)
{
  vector vPos =GetPositionFromLocation(lLoc) ;
  vPos.z += fRaise;
  return Location
         (
           GetAreaFromLocation(lLoc),
           vPos,
           GetFacingFromLocation(lLoc)+ fRotation
         );
}

For anyone interested I will post some pic's from my testing in a few.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script Request/Consult
« Reply #8 on: August 21, 2012, 03:54:50 am »


               For testing the functions I took 4 benchs with a waypoint in the center of them.  

'Posted

NOTE: All Scripts where ran by a OnClick event on a flag object near the test  waypoints.  


I then Stored the ROL's to the benches along with there ResRef's to the WayPoint. by clicking on the flag, I ran the following code.  

#include "inc_rol"
void main()
{
   object oArrayObject = GetWaypointByTag("ObjectArray");
   location lAnchor  = GetLocation(oArrayObject);
   int x=1;
   object oObj=GetNearestObjectByTag("TestObj",oArrayObject,x);
   while (GetIsObjectValid(oObj))
   {
     AddObjectToROLArray(oObj,lAnchor,oArrayObject);
     x++;
     oObj = GetNearestObjectByTag("TestObj",oArrayObject,x);
   }

}

The next flag Had the following code.   

 #include "inc_rol"
void main()
{
   object oArrayObject = GetWaypointByTag("ObjectArray");
   location lAnchor  = GetLocation(GetWaypointByTag("Test_1"));
   DrawROLObjectArray( lAnchor,1.0,oArrayObject);
}

It  placed the objects around the waypoint just like they where around the first.  So i will not bother to post that pic.  


in the Next Test I drew the Array 6 times Rotating and raising it each time.   

 
'Posted

Code on the flag was:
 #include "inc_rol"
const float BENCH_HIGHT = 0.40;
void main()
{
   object oArrayObject = GetWaypointByTag("ObjectArray");
   location lAnchor  = GetLocation(GetWaypointByTag("Test_2"));
   int x;
   for (x=0;x<6;x++)
   {
     DrawROLObjectArray( lAnchor,1.0,oArrayObject);
     lAnchor = RotateRaiseLocation(lAnchor,45.0,BENCH_HIGHT);
   }
}

 I also have no Idea why it leaned a bit. 

the Next flag scaled the locations out while it rotated. ( my scaling was off for what I was shooting for in the next two test But Oh well. This is just a demo )  

'Posted     

 Code:
 #include "inc_rol"
const float BENCH_HIGHT = 0.40;

void main()
{
   object oArrayObject = GetWaypointByTag("ObjectArray");
   location lAnchor  = GetLocation(GetWaypointByTag("Test_3"));
   int x;
   for (x=0;x<6;x++)
   {
     DrawROLObjectArray( lAnchor,1.25*x,oArrayObject);
     lAnchor = RotateRaiseLocation(lAnchor,45.0,BENCH_HIGHT);
   }
}

The last test scaled inwards doing the same thin and ended up looking just about the same. ( Due to my Over scaling again.)
'Posted

Code:
#include "inc_rol"
const float BENCH_HIGHT = 0.40;

void main()
{
   object oArrayObject = GetWaypointByTag("ObjectArray");
   location lAnchor  = GetLocation(GetWaypointByTag("Test_4"));
   int x;
   for (x=0;x<6;x++)
   {
     DrawROLObjectArray( lAnchor,0.75*x,oArrayObject);
     lAnchor = RotateRaiseLocation(lAnchor,45.0,BENCH_HIGHT);
   }
}


Hope you have fun with them.
L8
               
               

               


                     Modifié par Lightfoot8, 21 août 2012 - 02:55 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Script Request/Consult
« Reply #9 on: August 21, 2012, 05:15:49 pm »


               Thanks guys,
I like the looks of this

I plan to try and adapt this to create complex symbols out of vfx placeables, and then have it so that players have to stand within circles drawn by the placeables.

The system as seen above, looks like it is what I need to duplicate the complex structures

2 Players stand in the circles here, and then the ritual is complete, and BAEL the big bad boss appears!!
'Posted

Or make it some sort of pet summon ritual
Summon the symbol (draw it)
Then stand in the circles
Then the uber summon appears.