Ironworks Gaming Forum

Ironworks Gaming Forum (http://www.ironworksforum.com/forum/index.php)
-   Neverwinter Nights 1 & 2 Also SoU & HotU Forum (http://www.ironworksforum.com/forum/forumdisplay.php?f=16)
-   -   Hello scripters...Why isn't this working? (http://www.ironworksforum.com/forum/showthread.php?t=37122)

robertthebard 08-17-2006 08:44 AM

void main()
{
object oPC = GetFirstObjectInArea(OBJECT_SELF);
while ( GetIsObjectValid( oPC ) )
{
if (GetIsPC(oPC))
{
// Well, there you have it. Someone is still in the area. We don't want to
// clean up quite yet.

return;
}
if (GetObjectType( oPC )!=OBJECT_TYPE_CREATURE)
{
oPC = GetNextObjectInArea( OBJECT_SELF );
continue;

}

oPC = GetNextObjectInArea(OBJECT_SELF );
int iCount = 0;
object oObject = GetObjectByTag( "BodyBag", iCount );
while ( GetIsObjectValid( oObject ) )
{
// First, remove whatever treasure might be in it.
object oTreasure = GetFirstItemInInventory( oObject );
while ( GetIsObjectValid( oTreasure ) )
{
DestroyObject( oTreasure );
oTreasure = GetNextItemInInventory( oObject );
}
// Now, remove the body bag itself.
DestroyObject( oObject );
oObject = GetObjectByTag( "BodyBag", ++iCount );
}

}
}

This is supposed to check if there are any PC's in the area, and then destroy body bags. It compiles, and is on area exit, but doesn't destroy the body bags.

Legolas 08-17-2006 11:04 AM

The script does the following:

1) Pick an object in the area. The entire script runs until there are no unchecked objects remaining.
2) If that object is a player, abort the script
3) If it's not a player and not a creature, pick another object
4) Pick yet another object instead even if you already did so (see 3)
5) Cycle through all 'bodybag' itens in the area
6) Cycle through all treasure in these bags
7) Destroy all treasure
8) Destroy all bags
9) Do it all over again for the currently selected object in the area

A couple of points:

Assume an area has 4 bodybags, 2 npcs and 1 player in it.
The first object might be the PC, but it could also be that you check 3 bags and 1 npc first meaning you delete part or all of the bags even with players in the area.

In addition, if you first select an npc, then a bag, then the PC, then another bag, your second check would mean that you find a creature so the next object is a bag. The bag is not a creature, so the next object is not the PC, but the bag that comes after it. Effectively you skip the PC in your object check.

After that, you never use the PC object again. In otehr words, all you want to use it for is to see if there's any PC in the area at all. There's no reason to place the second part inside this loop and you can put one of the last closing brackets between the
oPC = GetNextObjectInArea(OBJECT_SELF ); and int iCount = 0; parts instead.

You're likely better off replacing the first part with something like:
Quote:

object oPC = GetFirstPC();
while(GetIsObjectValid(oPC))
{
if(GetArea(oPC)==OBJECT_SELF)
{
return;
}
oPC = GetNextPC();
}
If you want you can also add a check to exclude DMs but that's optional.

As for the second part, the GetObjectByTag command doesn't just select body bags in the current area, but in all areas in your module. So if one area gets cleaned, so does another regardless of how many players are there.

Replace the second part with something like:
Quote:

object oBag = GetFirstObjectInArea(OBJECT_SELF);
while (GetIsObjectValid(oBag))
{
if(GetTag(oBag)=="BodyBag")
{
object oTreasure = GetFirstItemInInventory(oBag);
while (GetIsObjectValid(oTreasure))
{
DestroyObject(oTreasure);
oTreasure = GetNextItemInInventory(oBag);
}
DestroyObject(oBag);
}
oBag = GetnextObjectInArea(OBJECT_SELF);
}
Put parts 1 and 2 between a void main() { } and you should have something that works.

robertthebard 08-17-2006 11:08 AM

Cool, off to try it out, thanks a bunch...

robertthebard 08-17-2006 11:26 AM

Quote:

void main()
{
object oPC = GetFirstPC();
while(GetIsObjectValid(oPC))
{
if(GetArea(oPC)==OBJECT_SELF)
{
return;
}
oPC = GetNextPC();
}
object oBag = GetFirstObjectInArea(OBJECT_SELF);
while (GetIsObjectValid(oBag))
{
if(GetTag(oBag)=="BodyBag")
{
object oTreasure = GetFirstItemInInventory(oBag);
while (GetIsObjectValid(oTreasure))
{
DestroyObject(oTreasure);
oTreasure = GetNextItemInInventory(oBag);
}
DestroyObject(oBag);
}
oBag = GetnextObjectInArea(OBJECT_SELF);
}
}

Ok, this won't compile, I commented out the last oBag = line, and it compiled but I got: OID, Tag: ERROR: TOO MANY INSTRUCTIONS, message on area exit, and it didn't remove the body bag. I'm probably missing something really easy, but...

Should there be a true/false statement in either or both, aside from the object valid?

[ 08-17-2006, 11:27 AM: Message edited by: robertthebard ]

robertthebard 08-17-2006 11:39 AM

Quote:

void main()
{
object oPC = GetFirstPC();
while(GetIsObjectValid(oPC))
{
if(GetArea(oPC)==OBJECT_SELF)
{
return;
}
oPC = GetNextPC();
}
object oBag = GetFirstObjectInArea(OBJECT_SELF);
while (GetIsObjectValid(oBag))
{
if(GetTag(oBag)=="BodyBag")
{
object oTreasure = GetFirstItemInInventory(oBag);
while (GetIsObjectValid(oTreasure))
{
DestroyObject(oTreasure);
oTreasure = GetNextItemInInventory(oBag);
}
DestroyObject(oBag);
}
//oBag = GetnextObjectInArea(OBJECT_SELF);
}
}
This variation cleaned the area, but still gave the too many instructions error.

Edit: Further testing results show that the cleaner part is only cleaning one bag out at a time, instead of all bags in the area.

[ 08-17-2006, 11:50 AM: Message edited by: robertthebard ]

Legolas 08-17-2006 11:55 AM

I think I see the problem there. Instead of GetnextObjectInArea use GetNextObjectInArea. Commenting this part out is the reason it only cleans one at a time, and the small letter n means the command is not understood, resulting in compile errors.
The too many instructions sound like they're the result of a loop. And indeed, you'll get one if you don't cycle through the bags because you're always testing for the first one.

robertthebard 08-17-2006 12:02 PM

LOL, knew it would be something easy...

Edit: Hooray, it works, thanks loads Legolas, 'preciate the help.

[ 08-17-2006, 12:06 PM: Message edited by: robertthebard ]


All times are GMT -4. The time now is 11:18 AM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved