Aller au contenu

Photo

get random location inside a trigger


  • Veuillez vous connecter pour répondre
7 réponses à ce sujet

#1
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
Does anyone have a good function to choose a random location inside of a trigger? 

#2
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
Paint down some waypoints and randomly choose one.

#3
Failed.Bard

Failed.Bard
  • Members
  • 774 messages
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.

Modifié par Failed.Bard, 22 septembre 2011 - 01:36 .


#4
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
thanks guys, this is two good options I will tinker with.

#5
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
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
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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.   

#7
kalbaern

kalbaern
  • Members
  • 824 messages

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 ... :) ... its "how" you've drawn the triggers partly. When a script fires from a trigger and has to Find the nearest "X", it measures from the point where you first clicked and started drawing the trigger.

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. :D The root cause was where "GetNearest" was being measured from, which I determined was always ... wherever you first click to start drawing your triggers.

Hope this helped.

Modifié par kalbaern, 03 octobre 2011 - 06:54 .


#8
DM_Vecna

DM_Vecna
  • Members
  • 280 messages
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