Author Topic: location vector  (Read 319 times)

Legacy_Sydious

  • Full Member
  • ***
  • Posts: 116
  • Karma: +0/-0
location vector
« on: July 12, 2011, 07:09:21 pm »


               Im trying to have ceatures spawn at a random spot near a waypoint. I can't seem to figure out how to set the vector I need. Can anyone help?

This is my spawn script. Right now on a switch. Will be placing it in the onEnter of the area I think.

#include "x0_i0_position"
void main()
{

    object oSpawn;
    object oSpawnPoint;
    oSpawnPoint = GetWaypointByTag("SP_COMMONER_01");
    int iCrowd_Size = GetLocalInt(oSpawnPoint, "crowd_size");
    //Locate the area we are in
    object oArea = GetArea(OBJECT_SELF);
    //Locate where in the are we are
    vector vPosition = GetPosition(oSpawnPoint);
    //Identify the direction we are facing
    float fOrientation = GetFacing(oSpawnPoint);
    //Create a new location with this information
    location myLocation = Location( oArea, vPosition, fOrientation);
    //Create Crowd
    int i;
    for (i = 0; i < iCrowd_Size; i++)
    {
        int iGender = d2(1);
        CreateObject(OBJECT_TYPE_CREATURE, "commoner00" + IntToString(iGender), myLocation, FALSE, "commoner_" + IntToString(i));
    }
}
               
               

               
            

Legacy_Axe_Murderer

  • Full Member
  • ***
  • Posts: 199
  • Karma: +0/-0
location vector
« Reply #1 on: July 12, 2011, 07:28:02 pm »


               [nwscript]
#include "nw_i0_spells"  // defines the GetRandomDelay function.

void main()
{
...
float fMaxDistance = 5.0; // max dist from waypoint where random loc will end up.
float fDistance = GetRandomDelay( 0.0, fMaxDistance ); // random distance from waypoint
vector vRandom = VectorNormalize( AngleToVector( GetRandomDelay( 0.0, 360.0 ))); // random dir from waypoint
vRandom *= fDistance;
vRandom += GetPosition( oSpawnPoint );
location myLocation = Location( oArea, vRandom, GetFacing( oSpawnPoint ));
...
}
[/nwscript]
               
               

               


                     Modifié par Axe_Murderer, 12 juillet 2011 - 06:35 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
location vector
« Reply #2 on: July 12, 2011, 07:29:16 pm »


               Look for the position script amongst nwn's generic scripts. Just search for "position" amongst all scripts in a module. You will find it.

It has a function that generates random locations. You can modify this to find a random location within a certain distance of another object. I have done something very similar to what you are trying recently. If you can't figure it out, I'll dig up my scripts and post a snippet for you.
               
               

               
            

Legacy_Sydious

  • Full Member
  • ***
  • Posts: 116
  • Karma: +0/-0
location vector
« Reply #3 on: July 12, 2011, 07:38:53 pm »


               Perfect.

Thanks for your help all.