Aller au contenu

Photo

Determine Perception Range of Creature


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

#1
henesua

henesua
  • Members
  • 3 867 messages
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.

#2
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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.

#3
Morbane

Morbane
  • Members
  • 1 883 messages
isnt there a property for perception range? there is in nwn2 anyway - in the creatures properties half way down the list iirc.

#4
GhostOfGod

GhostOfGod
  • Members
  • 863 messages

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.

#5
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
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.

#6
henesua

henesua
  • Members
  • 3 867 messages
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.

#7
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
<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>

#8
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

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.

#9
Rolo Kipp

Rolo Kipp
  • Members
  • 2 791 messages
<Looks flabbergasted...>

<says something vicious>. :-P

Explains why I can't find it...

<...i.e. normal>

#10
Alaster Wolf

Alaster Wolf
  • Members
  • 14 messages
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.

#11
bdtgazo

bdtgazo
  • Members
  • 53 messages
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.

#12
henesua

henesua
  • Members
  • 3 867 messages
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.

#13
bdtgazo

bdtgazo
  • Members
  • 53 messages
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.

#14
henesua

henesua
  • Members
  • 3 867 messages
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.

#15
MrZork

MrZork
  • Members
  • 940 messages
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.

#16
Axe_Murderer

Axe_Murderer
  • Members
  • 279 messages
Perception range is one of the things laid out in ranges.2da (lines 8-10 & maybe 13), so you can use Get2DAString to look it up if you know the index it's using. Though you'd need a plugin to change it on the fly. If you aren't gonna go that route, and simply knowing what it is will be sufficient, then you ought to know ahead of time what the blueprint is going to be set to and then hard code it into that blueprint's scripts...or you could simply add a variable to the blueprint that specifies what the blueprint is set up to use and look it up that way @ runtime (since it won't be changing).

And naturally, if you do use a plugin to set it, I would imagine the plugin ought to also have an associated Get function for it as well and then your prob is solved. Don't know for sure, but I'm guessing/nearly certain the value carried on instances of the creature is merely an index into the 2DA and not the actual distance value, so you would be limited to those discrete values supported in ranges.2da (Short, Normal, Long). Unless, of course, you append new lines to it with custom values.

Perception is also a 2 layer deal. There is a primary and a secondary range (which only differ when set to long range by default, the two are identical for short and normal). I have no idea what each is used for or when each kicks in. Maybe audible range and visual range? Or direct LOS and obstructed LOS? Shouldn't be too difficult to discover through testing because you know what the distances must be limited to and OnPerception tells you why it fired via the GetLastPerception* family. I seem to recall Bioware guys saying they had some performance problems with audible perception being tracked independently of visual, so they ditched it and combined it in with visual such that the two events always fire at the same time. Thus you might not see any differences (i.e. either primary or secondary range might be unused).

Modifié par Axe_Murderer, 24 août 2013 - 02:52 .