Author Topic: Determine Perception Range of Creature  (Read 754 times)

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Determine Perception Range of Creature
« on: August 23, 2011, 03:56:59 am »


               Does anyone know how to get this value? I want to determine how far a creature can see, but I don't know the function which returns this value.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #1 on: August 23, 2011, 07:43:18 am »


               Hmm. Actually I don't think there is a function for this with vanilla NWN. Maybe NWNX?

Off the top of my head the only thing I can think of would be to put an int variable on the NPCs representing the perception range you give them. Then in game just check for that variable. Not a very practical solution if you needed to add the variable to a bazillion creature blueprints.
               
               

               
            

Legacy_Morbane

  • Jr. Member
  • **
  • Posts: 79
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #2 on: August 23, 2011, 08:48:06 am »


               isnt there a property for perception range? there is in nwn2 anyway - in the creatures properties half way down the list iirc.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #3 on: August 23, 2011, 09:00:33 am »


               

Morbane wrote...

isnt there a property for perception range? there is in nwn2 anyway - in the creatures properties half way down the list iirc.


Yes. You can set the creatures perception range in the toolset. But there is no scripting function (that I know of) that can get that info from the NPC.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #4 on: August 23, 2011, 01:14:20 pm »


               Coming from NWN2 here, and there this is listed out in Ranges.2da - does NWN have this also? If not, or you need something more specific, you could write a script to check and report the distances.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #5 on: August 23, 2011, 04:54:28 pm »


               I need a function that enables me to get the range of perception for a specific creature object. I can access the 2DA but then how do I relate that information to the creature? The creature likely has an index for ranges.2da but I don't know how to get it.

And BTW - I am looking for this in Vanilla NWN as opposed to using a wrapper like NWNX.

Thanks for the responses so far. I suspect that GoG has the best work around.
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #6 on: August 23, 2011, 05:35:03 pm »


               <looks overwhelmed...>

Well, is there a simpler way of tracking down the GetObjectSeen() function than trying to load and search *every* bloody script?  I'd think that function will give a clue how to extract a creature's perception, but damn-me if I can find it :-P

<...by a *huge* pile of scrolls>
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #7 on: August 23, 2011, 10:45:29 pm »


               

Rolo Kipp wrote...

<looks overwhelmed...>

Well, is there a simpler way of tracking down the GetObjectSeen() function than trying to load and search *every* bloody script? I'd think that function will give a clue how to extract a creature's perception, but damn-me if I can find it :-P

<...by a *huge* pile of scrolls>


It is a built in function, So there is no script for it.
               
               

               
            

Legacy_Rolo Kipp

  • Hero Member
  • *****
  • Posts: 4349
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #8 on: August 23, 2011, 11:25:21 pm »


               <Looks flabbergasted...>

<says something vicious>. :-P

Explains why I can't find it...

<...i.e. normal>
               
               

               
            

Legacy_Alaster Wolf

  • Newbie
  • *
  • Posts: 20
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #9 on: July 15, 2013, 05:23:50 pm »


               Here is an idea how to shorten the perception range, but I have not tested it yet. You may be able to tweak the OnPerception script for the creatures. Check the distance of the perceived object and if it is too far away then just ignore the object.
               
               

               
            

Legacy_bdtgazo

  • Jr. Member
  • **
  • Posts: 98
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #10 on: August 21, 2013, 12:31:25 am »


               I believe Alaster Wolf is correct.

I was playing around with the Dragon Combat script from the vault, and was having the dragon spawn in wyrmlings every x heartbeats.  But the wyrmlings were attacking any PC in the area, regardless of distance.  So I tinkered, and yes, I believe I used a distance check that worked.

However, I also believe I lost that change on a computer crash.  But I don't think it was that difficult to make, and I am terrible with scripting.  So if you still need it, let me know, I can try to recreate it.  I haven't gotten around to adding the dragon combat stuff back into my mod yet, but as I said, I don't recall it taking too long, a few hours at best.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #11 on: August 21, 2013, 03:41:50 am »


               I did not respond to Alister because his comment doesn't relate to the thread.

Nevertheless, I would like to caution both of you from checking distances during execution of the OnPerception event. If you are making a single player module, you can disregard my caution, but for multiplayer the overhead would need to be carefully considered.

Admittedly my Light Shy AI does check distance in a few of the AI scripts, and these can operate on a multiplayer server if the number of creatures with that AI is kept in check. But 20 creatures spawned with that AI can slow things down. Someday I will get around to rewritting that AI....

The topic of the thread however has nothing to do with this. I wanted a method in vanilla NWN to get this data from a creature, and even better change it. It is however not possible. NWNX is the way to go for this if you are running a server.
               
               

               
            

Legacy_bdtgazo

  • Jr. Member
  • **
  • Posts: 98
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #12 on: August 21, 2013, 01:46:54 pm »


               I don't believe I used the OnPerception event.  I used OnHeartbeat.  I also set the HB to kill the spawns after a set period if no PCs were in range (during testing I blundered into quite a few wyrmlings).

So every Nth HB the wyrmlings were doing a range check and then going after the PC, or despawning.

Upon further reflection, I'm certain I had the range check working because I used some similar wyrmlings in a dungeon, and on the first test they traversed half of the zone and attacked me, which I didn't want.  I was able to fix it.

But you are right, my input is nonresponsive.  I had assumed you were inquiring for combat purposes.  My apologies.

I know NESS uses a range finder for some spawn flags.  I believe that is where I got the core script for my own range finder script.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #13 on: August 21, 2013, 10:18:39 pm »


               I don't mind that you are off topic. My purpose in stating that was to clarify that the two discussions were not connected. And yes the method you describe can work for the purposes you describe. My caution was about the approach on a multiplayer server.

NESS's approach however is cleaner because it operates on a single heart beat in an area to decide whether or not to spawn creatures. Furthermore with NESS you can use pseudo heartbeats only in areas that PCs are active in. This means that it is efficient, AND you only spawn the creatures when PCs are close enough to their spawn point. Much better than spawning the creatures regardless of where the PC is, check for PC proximity, and then if the PC is too far away despawn.

My original inquiry was actually related to my familiar system in which I use a single creature blueprint for all possible familiar types. I wanted to alter the perception ranges of these creatures during run time. We are currently looking into doing such things with NWNX.
               
               

               
            

Legacy_MrZork

  • Hero Member
  • *****
  • Posts: 1643
  • Karma: +0/-0
Determine Perception Range of Creature
« Reply #14 on: August 23, 2013, 10:31:17 pm »


               One could use moneo/letoscript offline to scan all of the creatures in the module (including the BW default creatures and those in required HAKs) and grab the perception range data from them en masse. That data could easily be sent to a custom 2DA to make the data available runtime. (In MP the 2DA would only be needed on the server side, so no HAKs required.) I think that would accomplish the initial purpose of allowing a scripter access to the perception range for a given creature at runtime. It would not allow changing the perception distance at runtime.

A consideration is that the resulting 2DA would be quite large, with essentially one line for every single creature resref. Of course, each line only has one real piece of data, the perception range. If that is too much of a lag hazard, then a potentially quicker solution might be to send the same data to a #include file that your custom GetCreaturePerceptionRange(object oCreature) function includes.

Gathering the data offline to either an updated 2DA or a #include means running the letoscript (probably taking a few minutes) whenever new creatures have been added to the module. And, taking the #include method requires recompiling as well. But, since new creatures cannot be added to the palette at runtime, it's a viable option.