Script Noobery

Ideas and suggestions for game mechanics and rules.
Locked
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Script Noobery

Post 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 && !! == :mad:

Is there a quick way of doing this? Be the first to help a doddering old fool out.

TIA
TnD
User avatar
AcadiusLost
Chosen of Forumamus, God of Forums
Posts: 5061
Joined: Tue Oct 19, 2004 8:38 am
Location: Montara, CA [GMT -8]
Contact:

Post 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?
User avatar
ç i p h é r
Retired
Posts: 2904
Joined: Fri Oct 21, 2005 4:12 pm
Location: US Central (GMT - 6)

Post 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!)?
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Post 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
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Post 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 :)
User avatar
indio
Ancient Red Dragon
Posts: 2810
Joined: Sat Jan 03, 2004 10:40 am

Post by indio »

Good catch.
Image
Locked