Does anyone have a good function to choose a random location inside of a trigger?
get random location inside a trigger
Débuté par
DM_Vecna
, sept. 21 2011 09:13
#1
Posté 21 septembre 2011 - 09:13
#2
Posté 22 septembre 2011 - 01:02
Paint down some waypoints and randomly choose one.
#3
Posté 22 septembre 2011 - 01:35
If your trigger is roughly rectangular, and rinning mostly in line N/S or E/W, you could store the triggers starting X and Y positions on it as floats, as well as the size in each direction. Those could then be used to create the X and Y portions needed for the random location to be created.
Going that way, you'd use something like this:
// Returns a random float in 10ths, from 0 to fNumber.
float GetRandomFloat (float fNumber)
{
int nNumber = FloatToInt (fNumber + 0.1) * 10;
int nRandom = Random (nNumber);
float fNumber = IntToFloat (nRandom) / 10.0;
return fNumber;
}
// returns a random location inside a trigger or other specified area,
// based on stored floats on the object.
// "X_BASE", "Y_BASE" --=> Starting points
// "X_MOD", "Y_MOD" --=> Maximum X and Y variances.
location GetRandomLocationInsideTrigger (object oTrigger = OBJECT_SELF)
{
location lBase = GetLocation (oTrigger);
vector vBase = GetPositionFromLocation (lBase);
float fX = GetLocalFloat (oTrigger, "X_BASE");
float fY = GetLocalFloat (oTrigger, "Y_BASE");
float fXMod = GetLocalFloat (oTrigger, "X_MOD");
float fYMod = GetLocalFloat (oTrigger, "Y_MOD");
vector vNew = Vector (fX += GetRandomFloat (fXMod), fY += GetRandomFloat (fYMod), vBase.z);
location lNew = Location (GetAreaFromLocation (lBase), vNew, GetRandomFloat (360.0) );
return lNew;
}
Admittedly, I just slapped that together, and test compiled it moreso than actually tested it, but it should work. Simply moving the mouse around over the trigger should give you the X and Y information you need for it.
Going that way, you'd use something like this:
// Returns a random float in 10ths, from 0 to fNumber.
float GetRandomFloat (float fNumber)
{
int nNumber = FloatToInt (fNumber + 0.1) * 10;
int nRandom = Random (nNumber);
float fNumber = IntToFloat (nRandom) / 10.0;
return fNumber;
}
// returns a random location inside a trigger or other specified area,
// based on stored floats on the object.
// "X_BASE", "Y_BASE" --=> Starting points
// "X_MOD", "Y_MOD" --=> Maximum X and Y variances.
location GetRandomLocationInsideTrigger (object oTrigger = OBJECT_SELF)
{
location lBase = GetLocation (oTrigger);
vector vBase = GetPositionFromLocation (lBase);
float fX = GetLocalFloat (oTrigger, "X_BASE");
float fY = GetLocalFloat (oTrigger, "Y_BASE");
float fXMod = GetLocalFloat (oTrigger, "X_MOD");
float fYMod = GetLocalFloat (oTrigger, "Y_MOD");
vector vNew = Vector (fX += GetRandomFloat (fXMod), fY += GetRandomFloat (fYMod), vBase.z);
location lNew = Location (GetAreaFromLocation (lBase), vNew, GetRandomFloat (360.0) );
return lNew;
}
Admittedly, I just slapped that together, and test compiled it moreso than actually tested it, but it should work. Simply moving the mouse around over the trigger should give you the X and Y information you need for it.
Modifié par Failed.Bard, 22 septembre 2011 - 01:36 .
#4
Posté 22 septembre 2011 - 01:47
thanks guys, this is two good options I will tinker with.
#5
Posté 02 octobre 2011 - 09:54
I am using axes version of this to choose from a number of waypoints (the total number is stored on the area as a variable) but some of my spawns are way off course. Does anyone have a good script for this that I could check mine against?
#6
Posté 02 octobre 2011 - 11:42
There are a lot of this type of script on the boards here. All of them seem to have there own unique method. the most recent one was in thread Lagy death script
another less recent is in the thread Need help with a script....
For an alternat method you may find the threads here of interest.
Get Random Location By Tag
There are more but I can not seem to find them at the moment.
another less recent is in the thread Need help with a script....
For an alternat method you may find the threads here of interest.
Get Random Location By Tag
There are more but I can not seem to find them at the moment.
#7
Posté 03 octobre 2011 - 06:50
DM_Vecna wrote...
I am using axes version of this to choose from a number of waypoints (the total number is stored on the area as a variable) but some of my spawns are way off course. Does anyone have a good script for this that I could check mine against?
I use the random waypoint option for my own "semi-random" trap system as well as a few wandering monster triggers in areas.
By "way off course", do you mean that at times creatures from one trigger are actually appearing at a waypoint inside another trigger? If so ...
My own trap spawning triggers look for a waypoint on a d4. They first "roll" to see if they even make a trap, if so, they'll roll a die to see which of the four waypoints it appears at. So I set my four tagged waypoints in a general vicinity. Then I draw my trigger starting at a point nearest to the center of all 4 of them. This often requires me to draw a trigger that in the end resembles a squarish shape with a wedged slice missing from it.
I initially had issues when I used all square triggers and just assumed it would find the waypoint inside of itself. When I had more than one trigger in an area, at times, traps meant to spawn inside Trigger A were appearring inside Trigger B and so forth. Sometimes even two stacked on each other.
Hope this helped.
Modifié par kalbaern, 03 octobre 2011 - 06:54 .
#8
Posté 04 octobre 2011 - 04:44
Thanks you two I have gotten it figured out. Just a bit of scripting gone afoul that is now fixed and has me running well.
Thank you thank you thank you
Thank you thank you thank you





Retour en haut







