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));
}
}
location vector
Débuté par
Sydious
, juil. 12 2011 06:09
#1
Posté 12 juillet 2011 - 06:09
#2
Posté 12 juillet 2011 - 06:28
[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]
#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 .
#3
Posté 12 juillet 2011 - 06:29
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.
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.
#4
Posté 12 juillet 2011 - 06:38
Perfect.
Thanks for your help all.
Thanks for your help all.





Retour en haut






