Author Topic: get random location inside a trigger  (Read 354 times)

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
get random location inside a trigger
« on: September 21, 2011, 10:13:33 pm »


               Does anyone have a good function to choose a random location inside of a trigger? 
               
               

               
            

Legacy_Axe_Murderer

  • Full Member
  • ***
  • Posts: 199
  • Karma: +0/-0
get random location inside a trigger
« Reply #1 on: September 22, 2011, 02:02:09 am »


               Paint down some waypoints and randomly choose one.
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
get random location inside a trigger
« Reply #2 on: September 22, 2011, 02:35:37 am »


               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 .
                     
                  


            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
get random location inside a trigger
« Reply #3 on: September 22, 2011, 02:47:35 am »


               thanks guys, this is two good options I will tinker with.
               
               

               
            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
get random location inside a trigger
« Reply #4 on: October 02, 2011, 10:54:35 pm »


               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?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
get random location inside a trigger
« Reply #5 on: October 03, 2011, 12:42:23 am »


               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.   
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
get random location inside a trigger
« Reply #6 on: October 03, 2011, 07:50:52 am »


               

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 ... '<img'> ... 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. '<img'> 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 .
                     
                  


            

Legacy_DM_Vecna

  • Hero Member
  • *****
  • Posts: 501
  • Karma: +0/-0
get random location inside a trigger
« Reply #7 on: October 04, 2011, 05:44:26 am »


               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