Script not working
TheTinman
Member Posts: 74
This script compiles fine but does not work. Intended to destroy all enemies when the PC exits an area.
void main() { object oPC = GetExitingObject(); object oCreature; oCreature = GetNearestObject(OBJECT_TYPE_CREATURE); while(GetIsObjectValid(oCreature)) { if (GetIsEnemy(oPC, oCreature)) { DestroyObject(oCreature); } oCreature = GetNextObjectInArea(); } }
0
Comments
Always ask - what object is running this script?
In this case, it's the area.
So OBJECT_SELF - the default second parameter - is the area.
Since the area has no location, GetNearestObject will return OBJECT_INVALID.
If you specify oPC as the second parameter, it will work, but then you have to change GetNextObjectInArea to GetNearestObject, passing a parameter to get the 2nd, 3rd... instance until there are no more.
Alternatively, start with GetFirstObjectInArea. Test that the object is a creature before testing GetIsEnemy (for good order). Then GetNextObjectInArea is the correct way to continue the lóop.
https://nwnlexicon.com/index.php/GetObjectType
The lexicon is hard for me to understand at times. lol!
Try removing OBJECT_TYPE_CREATURE from both, then change the test to
or if you prefer
That's useful to know, thanks.