On area heartbeat code isn't getting dropped item
4BOLTMAIN
Member Posts: 90
I've been fighting this code for a while now and I just cant get it to pick up a dropped item in the area.
I just started coding again after years of not playing NWN so I am going to guess its something really simple that I am overlooking. What am I doing wrong?
void main()
{
object oObject, oCopy, oTalker = GetObjectByTag("security");
AssignCommand(oTalker, ActionSpeakString("HB Hall fires",TALKVOLUME_SHOUT));
object oChest = GetNearestObjectByTag("Donation_Chest");
object oInvItem;
location lLoc;
object oArea = GetArea(OBJECT_SELF);
AssignCommand(oTalker, ActionSpeakString("Get Area =" + GetName(oArea),TALKVOLUME_SHOUT));
object oTrash = GetFirstObjectInArea(oArea);
while (GetIsObjectValid(oTrash) && GetObjectType(oTrash) == OBJECT_TYPE_ITEM)
{
AssignCommand(oTalker, ActionSpeakString("Object is valid:" + GetName(oTrash),TALKVOLUME_SHOUT));
AssignCommand(oTalker, ActionSpeakString("Object type is item:" + GetName(oTrash),TALKVOLUME_SHOUT));
ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_FNF_FIREBALL),lLoc);
PlaySound("bf_large");
DestroyObject(oTrash, 0.0);
oTrash = GetNextObjectInArea(oArea);
}
}
I just started coding again after years of not playing NWN so I am going to guess its something really simple that I am overlooking. What am I doing wrong?
void main()
{
object oObject, oCopy, oTalker = GetObjectByTag("security");
AssignCommand(oTalker, ActionSpeakString("HB Hall fires",TALKVOLUME_SHOUT));
object oChest = GetNearestObjectByTag("Donation_Chest");
object oInvItem;
location lLoc;
object oArea = GetArea(OBJECT_SELF);
AssignCommand(oTalker, ActionSpeakString("Get Area =" + GetName(oArea),TALKVOLUME_SHOUT));
object oTrash = GetFirstObjectInArea(oArea);
while (GetIsObjectValid(oTrash) && GetObjectType(oTrash) == OBJECT_TYPE_ITEM)
{
AssignCommand(oTalker, ActionSpeakString("Object is valid:" + GetName(oTrash),TALKVOLUME_SHOUT));
AssignCommand(oTalker, ActionSpeakString("Object type is item:" + GetName(oTrash),TALKVOLUME_SHOUT));
ApplyEffectAtLocation(DURATION_TYPE_INSTANT,EffectVisualEffect(VFX_FNF_FIREBALL),lLoc);
PlaySound("bf_large");
DestroyObject(oTrash, 0.0);
oTrash = GetNextObjectInArea(oArea);
}
}
Post edited by 4BOLTMAIN on
0
Comments
PlaySound("bf_large");
DestroyObject(oTrash, 0.0);
}
oTrash = GetNextObjectInArea(oArea);
}
... and it still doesn't destroy the item.
The GetObjectType() in the while() is the issue, the loop will stop the moment it encounters a non item object.
If you move the ObjectType check inside the while loop it should work:
EDIT
I misunderstood what you meant about the "while" statement. I redid the code to match what you posted and moved the "getnext" back where it was and it is closer to being 100%. I didnt define a location so the effect wont show and the sound doesnt play. I will post working code when finished.