Author Topic: Get Random Location By Tag  (Read 782 times)

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Get Random Location By Tag
« on: September 05, 2011, 03:13:01 pm »


               Anyone using this function, or it's sister random object by tag?  I thought it might be interesting to test against Gnobt and Gobt, as it relates to the discussion on the boards recently concerning the speeds of these functions.  For anyone who did not read it, it was concluded tha gobt was the fastest by far. I have started using it for things like wp's with the same tag with a distance parameter.
               
               

               


                     Modifié par ffbj, 05 septembre 2011 - 02:15 .
                     
                  


            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Get Random Location By Tag
« Reply #1 on: September 05, 2011, 04:19:14 pm »


               I been using GetObjectByTag for a long time. Never used the Gnobt that I know of.
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Get Random Location By Tag
« Reply #2 on: September 05, 2011, 04:45:05 pm »


               I would use GetObjectByTag for getting an object, uniquely named, throughout the module.

I would use Gnobt for instances where I need to get an object in a specific area, although, I would sometimes use GetFirst/NextObjectInArea for that purpose as well.

Alot of my ritual magic uses hidden placeable objects as focus points, so GetNearestObjectByTag, is good for locating already existing focus points, from another ritual.

eg- Ritual 1 makes focus point 1.
   Ritual 2 wont work, without Focus Point 1, but will create focus point 2 when completed
  Ritual 3 will complete the whole ritual, but requires both focus points etc
 We would use GetNearestObjectByTag, so we dont do a module wide search.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Get Random Location By Tag
« Reply #3 on: September 05, 2011, 06:05:17 pm »


               Thanks.  Though what I was really wondering about was these functions:

// Get a random nearby object within the specified distance with
// the specified tag.
object GetRandomObjectByTag(string sTag, float fMaxDistance)

// Get a random location in a given area based on a given object,
// the specified distance away.
// If no object is given, will use a random object in the area.
// If that is not available, will use the roughly-center point
// of the area.
// If distance is set to 0.0, a random distance will be used.
location GetRandomLocation(object oArea, object oSource=OBJECT_INVALID, float fDist=0.0)

I just started using them for various applications was wondering about them.
This is the thread I was referring too:
http://social.biowar...2/index/8147590
               
               

               


                     Modifié par ffbj, 05 septembre 2011 - 05:10 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Random Location By Tag
« Reply #4 on: September 05, 2011, 06:14:37 pm »


               It would help if you let use know where the functions come from.  Are they in one of the standard include files.  Or are they something you inported into the module?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Random Location By Tag
« Reply #5 on: September 05, 2011, 07:59:42 pm »


               Ok, I did a search of the bif's to find the functions, 

GetRandomObjectByTag is in x0_i0_anims

GetRandomLocation is in x0_i0_position 

Even though I do not like the  x0_i0_position include I went ahead a looked at the function:  GetRandomLocation
it does not look to bad unless you do not define the oSource argument in the function. If oSource is OBJECT_INVALID  the function for some reason loops through all of the objects in the area looking for the one closest to the center.   It would be a lot more efficent to just get the area size then calculate the center of the area.   even if osource is not invalid though there are more efficent way of doing it.   I would suggest that you use any of the other recient methods posted recently on the boards, by either Faild Bard, Six, Axe or myself,  any of them will work better then the one from the x0_i0_position Include.   Here are links to a couple of the threads I could not find them all.  

PC drops items

location vector

Spawn in Front

Edit:  off to look at the other function now.   Will edit it in here after I have looked.

GetRandomObjectByTag  To me does not look like it would be much use ouside of the random animantions that it looks to be used for.    The main reason is that if you have 10 waypoints in the distance you feed to the function it will only randomize the nearest 6 of them.   on the other hand if you have 2 waypoints within  distance, It will still return to you an Invalid object  two thirds of the time. even though there are two valid waypoints within the distance. 
In short it is just a wrapper around gnobt with a set random number for nTh based on the distance you are searching.   That is as long as you are using one on the DISTANCE_* constance.  if you are not useing one of the constances it always defaults to looking for 6 random objects with the tag.    
               
               

               


                     Modifié par Lightfoot8, 05 septembre 2011 - 07:31 .
                     
                  


            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Get Random Location By Tag
« Reply #6 on: September 05, 2011, 08:06:56 pm »


               <chortling...>

Luv ya, man :-)

I've *got* to start pasting these things in one of my forums so I can *search* for the bloody tutorials when I want them :-( Still can't believe this board is so awkward...

<...just to change-up from chuckling>
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Random Location By Tag
« Reply #7 on: September 05, 2011, 08:46:19 pm »


               my analysis is.   That :

GetRandomLocation,  does not compair to Object search functions.  Since it does not search Objects( Or at least should not search for objects, for some reason Bioware did  when oSource was an invalid object)

GetRandomObjectByTag  is no differeant then GetNearestObjectByTag(sTag,oTarget,d6()) making it useless for mot applications.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Get Random Location By Tag
« Reply #8 on: September 05, 2011, 08:47:16 pm »


               Thanks for the information.  I did not get them from the includes they are just standard scripting functions, with their definitions taken right out of the script editor.  I wonder how the idea of animations fits in? Maybe since there is a function do random animation. I was just using them, mainly to, have npc's walk to random wp's with the same tag, (wp-road, placed along roads) or sit in random chairs, whichever ever one is randomly within range to the npc calling the function.  Thus if I have npc's wandering around to different wp's since if they are different distances from each-other they won't all go to the same wp, likewise for the chairs.  Rarely would I have more than six objects within the short distance parameters I have been using 10-15 meters, but thanks for pointing that out.
Well I would not say it was useless.  Say if you don't want npc wandering outside of a certain range. I suppose there could be other uses for it.  Not so enamored of the get random location either, though I can think of some interesting uses for that too. Maybe for creating spawn waypoints or random traps or some such.  Not to be contrary, but apparently someone thought there was a use for it.
I read through all those other posts before.  Mainly I don't use vectors  I do the random location for spawning monsters, like this:

location lWP = GetRandomLocation(oArea,oTarget,fDistance);

Where the PC is the target and fDistance is some variable distance from the PC.  It works pretty well and perhaps that was one of the thoughts behind the creation of the function.  Not sure. but that's one thing I use it for.
               
               

               


                     Modifié par ffbj, 05 septembre 2011 - 07:59 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Random Location By Tag
« Reply #9 on: September 05, 2011, 08:53:38 pm »


               

ffbj wrote...

Thanks for the information. I did not get them from the includes they are just standard scripting functions, with their definitions taken right out of the script editor. I wonder how the idea of animations fits in? Maybe since there is a function do random animation. I was just using them, mainly to, have npc's walk to random wp's with the same tag, (wp-road, placed along roads) or sit in random chairs, whichever ever one is randomly within range to the npc calling the function. Thus if I have npc's wandering around to different wp's since if they are different distances from each-other they won't all go to the same wp, likewise for the chairs. Rarely would I have more than six objects within the short distance parameters I have been using 10-15 meters, but thanks for pointing that out.


Check again,  they are not standard functions.  They come from the includes.   I find it a habbit any time the function appeares in bold in the function list ( bold meaning that the function comes from an include) , to chase it down to see just how it is written. They often Do Not do what the name of the function leads you to believe the do.  
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Get Random Location By Tag
« Reply #10 on: September 05, 2011, 09:00:18 pm »


               Ah, now I never knew that's what the bold meant.Thanks.
I see it anims include probably came about as a way to make npc's move around randomly, which makes sense, since that is where all the other npc moving around functions are located.
               
               

               


                     Modifié par ffbj, 05 septembre 2011 - 08:17 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Get Random Location By Tag
« Reply #11 on: September 06, 2011, 12:49:19 am »


               Sorry for the delay in responce, I just noticed the edits you made to the post you made.  

ffbj wrote...   
Well I would not say it was useless.  Say if you don't want npc wandering outside of a certain range. I suppose there could be other uses for it.


True not totaly useless.   Just keep in mind that the GetRandomObject ByTag may return an invlaid object even if there are valid tags within range.   If you want the function to always return a valid object if there is one in range, Write your own function that handles the situation the way you want it to.  


 

Not so enamored of the get random location either, though I can think of some interesting uses for that too. Maybe for creating spawn waypoints or random traps or some such.  Not to be contrary, but apparently someone thought there was a use for it.
I read through all those other posts before.  Mainly I don't use vectors  I do the random location for spawning monsters, like this:

location lWP = GetRandomLocation(oArea,oTarget,fDistance);

Where the PC is the target and fDistance is some variable distance from the PC.  It works pretty well and perhaps that was one of the thoughts behind the creation of the function.  Not sure. but that's one thing I use it for.

I agree that function has many uses.  It is just not written the best way. I would still suggest either using the one Faild bard wrote or the one I wrote.   You would just need to add the function to one of your includes or a new include.  

with Faild Bards function   Link  

your line would look like
location lWP = FB_GetRandomLocation(GetLocation(oTarget),fDistance);

with My function  Link
your line would look like:

location lWP = GetRndLocRoundObject(oTarget,fDistance);

Both of our functions would end up doing the same thing the boiware function does, Jut more effeciently. My function if you look at it also gives you more controll over where the random location is at around the target if you wanted to define it futher.

//Gets a random location around an object.
// - oObject : The object to get the random location around
// - fMaxDist: The maximum distance from oObject.
// - fMinDist: The mininum distance from oObject, Defaults to 0.
// - nAngle : The angle offset from the orintation of oObject. defaults to 0.
// 0 would be the direction that oObject is facing.
// - nAngleSpread: defines the size of the arc that the location fall into.
// The spread is on both sides of nAngle.Defaults to 180 that would
// be the full 360 deg around oObject
// - examples: If nAngle is 0 and nAngleSpread is 15. the location returned will
// be in the 30deg arc in front of the object. 15deg to the right
// and left.
// If nAngle is 90 and nAngleSpread is 90 the location returned will
// be Anywhere to the left of oObject. Angel 0 - 180 from objects orintation.
location GetRndLocRoundObject( object oObject, float fMaxDist, float fMinDist=0.0, int nAngle=0,int nAngleSpread=180);



So if you wanted to spawn in a creature  15 to 20 meters away anywhere in the 180 degrees behind a PC. You could use.

location lSpawnPoint = GetRndLocRoundObject( oPC, 20.0, 15.0, 180 ,90);

The 15.0 and 20.0 being thenin and max distance, the 180 being the angle direcly behind the pc and the 90 being the spread on both sides of the 180 degree angle.

That would give you a random location at the distance with an angle anywhere from 90-270 degrees from the PC's orientation.
               
               

               


                     Modifié par Lightfoot8, 05 septembre 2011 - 11:50 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Get Random Location By Tag
« Reply #12 on: September 06, 2011, 07:01:45 pm »


               Ok, cool. Thanks for taking the time to explain all this, and also to FB for doing his function.  I am going to take a look at both of them. Yeah 20 meters seems fine for a max distance and also I don't monsters dropping in too close, thus the minimum. One idea would be to start another stickied home brew thread, like we had on the old boards.
But I suppose it's not as busy on the boards these days, though I think that would be a good candidate for a sticky thread.

One of the uses I was thinking of was to spawn waypoints which I would use for monster spawns, then deleting the previous waypoint. You can cool affect wher monsters seems to be following a PC, then when the PC turns around to face the following monster another waypoint now behind them, while before it would of been ahead of them, spawns more monsters.  Really confusing to PC's.
               
               

               


                     Modifié par ffbj, 06 septembre 2011 - 06:10 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Get Random Location By Tag
« Reply #13 on: September 06, 2011, 08:50:31 pm »


               You don't really need a WP spawned for doing what you want to, ffbj.  You should be able to use Lightfoot8's script to simply keep the creatures spawning in the PCs rear arc, without needing a WP for reference.

 For mine, I'd made it for spawning creatures a bit spread out around a static WP initially, and it works quite well in that specific use.
 I'll also be using it if I ever get around to adding seasonal placeables, so snowdrifts, flowers, or whatnot have a little variety in their exact placing, though with a might tighter constraint on the variability of it.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Get Random Location By Tag
« Reply #14 on: September 09, 2011, 12:26:08 am »


               Oh yeah, I know I could do it that way. The idea behind the wp's is just adding a new wrinkle so that on a seprate trigger I could have the spawn to the wp with that tag. With the idea of mixing things up otherwise people start to get wise to where things spawn and how, that's all. Something like enter trigger execute LF script spawning a wp, then another trigger spawns random monsters to that wp, deletes it, and then executes LF script again.  I know that may seem a bit convoluted and totally unecessary.
Yep good for spawning placeables randomly too. I use a similar method to spawn placeable from a switch, as with creatures too for more variation.
               
               

               


                     Modifié par ffbj, 08 septembre 2011 - 11:29 .