Spawn Point Woes

For toolset tutorials as well as question and answers.
Locked
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Spawn Point Woes

Post by Teric neDhalir »

I'm trying to finish off my system for handling encounters generated on the scaled down travel map for 011 and have hit a wall, so could do with some fresh eyes looking at the scripts... The encounter system works fine in that any PC or party in a travel area is checked every minute or so and if an encounter is rolled they are moved to a "real" area where the encounter takes place. In the encounter area are two spawn points (day and night) that use group scripts to generate a random encounter from a table. So far so good. My problem is that I need to clean up after the encounter so that the next encounter re-rolls a new set of creatures.

At the moment I have a counter running that counts the number of PCs in the encounter area. When that counter hits 0 (ie all PCs have exited or been killed and moved to the morgue) I want the spawn points to reset. So I have an OnExit script that says:
////////////////////////////////////////////////////////////////////////////////
//
// System Name : ACR Configuration File
// Filename : acf_area_onexit.nss
// Version : 0.1
// Date : 7/25/06
// Author : Ronan
//
// Local Variable Prefix =
//
//
// Dependencies external of nwscript:
//
// Description
// This script calls the ACR's OnAreaExit code, and any custom code a server
// may need. It is not updated in ACR updates.
//
// Revision History
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Includes ////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

#include "acr_area_i"
#include "acr_spawn_i"

////////////////////////////////////////////////////////////////////////////////
// Constants ///////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Structures //////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Global Variables ////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Function Prototypes /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

// The main event handler.
void main();

////////////////////////////////////////////////////////////////////////////////
// Function Definitions ////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

void main() {
ACR_AreaOnExit();

// Custom code goes below this line.
object oExiter = GetExitingObject();
if (GetIsPC(oExiter) && !GetIsDM(oExiter))
{
int iPCCount = GetLocalInt(OBJECT_SELF, "sjc_PCCount");
iPCCount--;
string sPCCount = IntToString(iPCCount); //Debug
SendMessageToPC(GetFirstPC(), sPCCount); //Debug
SetLocalInt(OBJECT_SELF, "sjc_PCCount", iPCCount);
}
if (GetLocalInt(OBJECT_SELF, "sjc_PCCount") == 0)
{
object oArea = OBJECT_SELF;
object oWP = GetFirstObjectInArea(oArea);
while (GetIsObjectValid(oWP))
{
string sTag = GetTag(oWP);
if (sTag == "ACR_SPAWN_WP")
{ACR_SetIsSpawnPointEnabled(oWP, 0, 1);
}
object oWP = GetNextObjectInArea();
}
}
}
So basically if when a PC exits the area and there are no more PCs left then "ACR_SetIsSpawnPointEnabled(oWP, 0, 1);" runs in order to reset the spawn points ready for the next encounter. I have the reverse of this running on the OnEnter script so that when the first PC enters the area the spawn points are turned on. Alas, this is not happening in that when you re-enter the encounter area the spawn from the previous encounter is still there. If anyone can see any errors in the above then I would appreciate some help in fixing it.
Thanks,
Teric
User avatar
peterdin
Orc Champion
Posts: 456
Joined: Sat Jul 09, 2005 3:40 pm
Location: GMT+1

Re: Spawn Point Woes

Post by peterdin »

think the flaw is in iPCCount--;
and the compare in
if (GetLocalInt(OBJECT_SELF, "sjc_PCCount") == 0)
{

sjc_PCCount should be decremented not the local var iPCCount
A.K.A Pee Dee

past PC: Maha Tari, aka. Alinia Mountain curiousity killed the cat

All those moments, lost in time.
Like tears in the rain.
Time to die.
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Re: Spawn Point Woes

Post by Teric neDhalir »

peterdin wrote:think the flaw is in iPCCount--;
and the compare in
if (GetLocalInt(OBJECT_SELF, "sjc_PCCount") == 0)
{

sjc_PCCount should be decremented not the local var iPCCount
? Haven't I set the value of the LocalInt equal to iPCCount after it is decreased?
User avatar
peterdin
Orc Champion
Posts: 456
Joined: Sat Jul 09, 2005 3:40 pm
Location: GMT+1

Re: Spawn Point Woes

Post by peterdin »

oh my

you did

but few remarks can be made:
- first check if value = 0 before you decrement. otherise yit might overflow
- your while stops of object is not valid.
this shouldnt be the case. you shoudl iterate over ALL objects and skip the not valid ones.
This while stops when you bump into a not valid object.

furthermore questions:
- do you get into the first if?
- if so, what's the value of pccount?
A.K.A Pee Dee

past PC: Maha Tari, aka. Alinia Mountain curiousity killed the cat

All those moments, lost in time.
Like tears in the rain.
Time to die.
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Re: Spawn Point Woes

Post by Teric neDhalir »

peterdin wrote:oh my

you did

but few remarks can be made:
- first check if value = 0 before you decrement. otherise yit might overflow
- your while stops of object is not valid.
this shouldnt be the case. you shoudl iterate over ALL objects and skip the not valid ones.
This while stops when you bump into a not valid object.

furthermore questions:
- do you get into the first if?
- if so, what's the value of pccount?
Thanks for the additional suggestions, PD. What I think I'm doing is as folows:
The code for looping through the objects and testing them for their tags is lifted directly from the sample code in the NWN Lexicon for the GetFirstObjectInArea() function.
As far as GetIsObjectValid(), the Lexicon says:
This function is a widely used utility function to check the return values for functions that return objects. While looping through objects NWN functions usually return invalid objects to signify that there are no more objects left. This function can be used to test that condition.

(my italics), which I take to mean that it returns false only when you have run out of objects to test.
You don't trigger the first "if" clause unless you are a PC. I should point out again that there is a mirror-image version of this script OnEnter that is counting the PCs in and incrementing the iPCCount variable upwards. I suppose that I am assuming that these counters are working, and that on an OnExit event the iPCCount variable > 0.

I am happy to be proved wrong on any of the above...
Teric
User avatar
peterdin
Orc Champion
Posts: 456
Joined: Sat Jul 09, 2005 3:40 pm
Location: GMT+1

Re: Spawn Point Woes

Post by peterdin »

then the only thing I can suggest is you add some debug statements to check the value of your variables.

otherwise.. :wall:
A.K.A Pee Dee

past PC: Maha Tari, aka. Alinia Mountain curiousity killed the cat

All those moments, lost in time.
Like tears in the rain.
Time to die.
User avatar
Creslyn
Orc Champion
Posts: 423
Joined: Sat Jan 10, 2004 2:30 am

Re: Spawn Point Woes

Post by Creslyn »

Code: Select all

	while (GetIsObjectValid(oWP))
			{
			string sTag = GetTag(oWP);
			if (sTag == "ACR_SPAWN_WP")
				{ACR_SetIsSpawnPointEnabled(oWP, 0, 1);
				}
			object oWP = GetNextObjectInArea();
			}
shift the declaration of sTag out of the loop.

Code: Select all

string sTag;
while (GetIsObjectValid(oWP))
			{
			sTag = GetTag(oWP);
			if (sTag == "ACR_SPAWN_WP")
				{ACR_SetIsSpawnPointEnabled(oWP, 0, 1);
				}
			object oWP = GetNextObjectInArea();
			}
User avatar
peterdin
Orc Champion
Posts: 456
Joined: Sat Jul 09, 2005 3:40 pm
Location: GMT+1

Re: Spawn Point Woes

Post by peterdin »

think I have it

it's not the string that make it buggy
its the definition of the oWP object

change it to
object oWP = GetFirstObjectInArea(oArea);
while (GetIsObjectValid(oWP))
{
string sTag = GetTag(oWP);
if (sTag == "ACR_SPAWN_WP")
{ACR_SetIsSpawnPointEnabled(oWP, 0, 1);
}
oWP = GetNextObjectInArea();
}
}
this because you are defining the same OWP in the if and it is also defined outside (where it should be)
It depends on how the script engine interprets the code but its worth given it a try
A.K.A Pee Dee

past PC: Maha Tari, aka. Alinia Mountain curiousity killed the cat

All those moments, lost in time.
Like tears in the rain.
Time to die.
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Re: Spawn Point Woes

Post by Teric neDhalir »

Thanks for the suggestions; I think PD is onto something... I added some debugging code to report the names of the items that were found and have been getting the same name over and over again so I think it's constantly doing GetFirstObjectInArea() because

object oWP = GetNextObjectInArea();

doesn't mean anything. Doh.
User avatar
peterdin
Orc Champion
Posts: 456
Joined: Sat Jul 09, 2005 3:40 pm
Location: GMT+1

Re: Spawn Point Woes

Post by peterdin »

it does
but your code use the first declaration and that does not change....
good luck hunting
A.K.A Pee Dee

past PC: Maha Tari, aka. Alinia Mountain curiousity killed the cat

All those moments, lost in time.
Like tears in the rain.
Time to die.
User avatar
Teric neDhalir
Githyanki
Posts: 1495
Joined: Mon Jan 05, 2004 10:04 pm
Location: Manchester UK

Re: Spawn Point Woes

Post by Teric neDhalir »

Well I'm now getting a list of all the objects in the area - spawns, waypoints, PCs etc. so at least that's a start. Thanks a lot! Whether the spawn point is being affected is another question...
Locked