Author Topic: GetFirstObjectInShape versus GetNearestCreature  (Read 380 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
GetFirstObjectInShape versus GetNearestCreature
« on: May 20, 2012, 04:49:08 pm »


               [Edit: This thread lead to an AOE solution for this problem which is described in another thread.]

I have a heartbeat event script on a placeable. (Gargoyle style)

Since this will be executing on every heartbeat, I'd like to keep it efficient. Is there any difference between GetFirstObjectInShape and GetNearestCreature?

I am leaning towards GetNearestCreature since it is more specific, but if its a wasteful method I'd prefer to avoid it.
               
               

               


                     Modifié par henesua, 22 mai 2012 - 03:39 .
                     
                  


            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
GetFirstObjectInShape versus GetNearestCreature
« Reply #1 on: May 20, 2012, 04:55:29 pm »


               I don't know for certain, as I've never read the code for both of those functions, maybe if you look them up you would be able to define the difference for yourself, I'd be willing to guess they both use a loop, as they both need to cycle through all objects in the area, probably...

However, get first object in shape would only need to check one object, taking the first object in the specified area, which seems like it would be far more efficient than GetNearestCreature, which would then need to calculate distance, which is definitely more CPU Intensive, as it must use the recourse hog GetDistanceBetween() function...

Hope this helps..

(Though, I'm not saying this is accurate, as I have never looked at these two functions' actual code)
               
               

               


                     Modifié par _Guile, 20 mai 2012 - 03:58 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
GetFirstObjectInShape versus GetNearestCreature
« Reply #2 on: May 20, 2012, 05:24:17 pm »


               I also have not looked at the machine code for the two functions.    both functions are intensive however.    Both functions will do distance checks between a point and every object in the area.  The GetObjectInShape will also have to have a check to see if the position of the object also falls into the shape.   how much more or less effecient it is would all depend on if that check is done before or after the distance check.  In truth I am not even sure at this point which way would be faster.

I am not sure what you are doing,  But perhap a EOF would be a better approach.  You could turn it off and on with PC entering/leaving the area.  

Or even place an invisiable creature by your placable with all the events blank except for the OnPerception script.

Just some thoughts.
               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
GetFirstObjectInShape versus GetNearestCreature
« Reply #3 on: May 20, 2012, 06:21:43 pm »


               Both are about the same, like LF said you could put a on enter area check for PC that if it 0 meaning no PC then stop and on 1 keep running. If you really want to save then do not even do a heartbeat. Place triggers around the placeable that will do what you want when a pc enters them.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
GetFirstObjectInShape versus GetNearestCreature
« Reply #4 on: May 20, 2012, 08:44:51 pm »


               Thanks for the feedback.

What I am doing is similar to the gargoyle code that bioware has done. A placeable turns into a monster when a PC is near, and the creature if not in combat turns back into the placeable. The placeables are only spawned in the area when a PC is present.

This however means that a trigger won't work. An area of effect however would. I'll need to create an area of effect that is created when the placeable is created. Interesting idea, I'll look into getting that to work.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
GetFirstObjectInShape versus GetNearestCreature
« Reply #5 on: May 21, 2012, 12:11:14 am »


               

henesua wrote...

. An area of effect however would. I'll need to create an area of effect that is created when the placeable is created. Interesting idea, I'll look into getting that to work.


Or since the placable no longer need to be running a HB script or any script for that matter.   You could just leave the placable where it is at and add/remove the EOF OnPC Enter/Leave. 

just another thought.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
GetFirstObjectInShape versus GetNearestCreature
« Reply #6 on: May 21, 2012, 12:38:46 am »


               The Area of Effect I created is only created when the placeable is spawned (via NESS) or when the monster reverts to a placeable - and the only event applied to it is OnEnter.  I made several generic Area Of Effect entries in vfx_persistent  none of the events for these entries have a default script identified in the 2da.

Only draw back to this system is that it is not easy for a DM to place active placeables since they only function via Area of Effect. (Although the onAttacked, onDamaged events of the placeable also spawn monsters)

The monsters however when placed will soon turn into a placeable and create an area of effect at that time.
               
               

               


                     Modifié par henesua, 20 mai 2012 - 11:40 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
GetFirstObjectInShape versus GetNearestCreature
« Reply #7 on: May 21, 2012, 12:43:04 am »


               Sould not be that hard for the DM to place them. The Placeable yes that could be a problem, But if they placed the creature and they where not in combat, They should then simply turn into your placeable with everything intact.  It is just letting the DM's know to place the creatures and not the placeables.
               
               

               


                     Modifié par Lightfoot8, 20 mai 2012 - 11:44 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
GetFirstObjectInShape versus GetNearestCreature
« Reply #8 on: May 21, 2012, 01:23:14 am »


               I just realized that I could tie my simple spawn into this system so that HP could be persistent. I have not done that yet. Also could do an interesting thing with AI... a creature that turns into a placeable could use it as a means to avoid a fierce opponent. If unable to harm an opponent, they could go dormant as a placeable and wait out the encounter. Thats a situation where persistent HP would be useful. This would make for a nice special combat ai.

[EDIT] ***********************************************
Ug... AOE not working. Too much going on to figure out why. I'll puzzle through later and post an update.

[EDIT 2]
Found the problem. the AOE can not be applied to the spawned object. So I am creating a special AOE target object similar to how glyph of warding works, and applying the AOE at that location. When the creature is spawned the AOE is destroyed.

I should have this coded in a couple days. I've got the day job to work around.

[EDIT 3]
While the method mentioned above in Edit 2 is working, I've just realized that the AOE at location is an object itself of type area of effect. So I'll need to figure out how to make this work for me. Time to start a new thread on AOE's.
               
               

               


                     Modifié par henesua, 22 mai 2012 - 03:38 .