Page 1 of 1
Script Noobery
Posted: Tue Jul 24, 2007 11:53 pm
by Teric neDhalir
Hi all,
Sorry to be a dummy but I'm trying to write a script that compares the number of PCs perceived by an NPC to the number of creatures of the same faction (or tag) perceived by the NPC. Or rather gives me the total number of (eg) PCs=3 TalkingFrogs=78.
I can't see a function that's called anything like GetNumberOfThingsInAGivenArea() and any scripts I look at for inspiration do unfathomable things with GetFirstPC/GetNextPC && !! ==
Is there a quick way of doing this? Be the first to help a doddering old fool out.
TIA
TnD
Posted: Wed Jul 25, 2007 12:53 am
by AcadiusLost
I've never scripted with perception, but you could iterate through an area of effect using GetFirstObjectInShape() with the filter set to OBJECT_TYPE_CREATURE, If you make it a sphere of the radius you're looking for, you can make counters for whatever you want to add up (creatures with said tag, PCs, faction members, etc), and divide that by the total creature count, or what have you, after the loop is complete. GetNextObjectInShape() should be the function to call at the end of the loop to move on through it.
Note that this may be an expensive operation in terms of CPU cycles, so it should be used judiciously.
This also only takes a snapshot of whatever is within the radius- if you're looking to keep a running tally of allies or enemies a given NPC has seen, that's something better handled with local ints OnPerception, I expect. (though it may have unexpected results, as well).
What are you trying to accomplish with the script?
Posted: Wed Jul 25, 2007 3:17 am
by ç i p h é r
OnPerception triggers every time a creature perceives an object, but IIRC it's a generic event. You will need to perform the audible/visible checks to determine whether the creature should react and how.
Are you trying to script some sort of rudimentary morale system (ie they outnumber us, so run!)?
Posted: Wed Jul 25, 2007 8:43 am
by Teric neDhalir
ç i p h é r wrote:Are you trying to script some sort of rudimentary morale system (ie they outnumber us, so run!)?
Yes. There are other factors such as CR and damage sustained, but the one that's doing me in is getting the ratio of good guys to bad guys.
Teric
Posted: Sat Jul 28, 2007 7:43 pm
by Teric neDhalir
Just FYI, I found a function in x0_i0_enemy called CountEnemiesAndAllies() which appears to be working in the way I want. It's a struct. Like I know what one of those is

Posted: Sat Jul 28, 2007 8:48 pm
by indio
Good catch.