Skip to content

On area heartbeat code isn't getting dropped item

4BOLTMAIN4BOLTMAIN Member Posts: 90
edited January 2020 in Builders - Scripting
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);
}
}
Post edited by 4BOLTMAIN on

Comments

  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    edited January 2020
    I just realized that if the first item isn't valid or an OBJECT_TYPE_ITEM then GetNextObjectInArea will never happen so I changed the bottom lines of the code to this...

    PlaySound("bf_large");
    DestroyObject(oTrash, 0.0);
    }
    oTrash = GetNextObjectInArea(oArea);
    }

    ... and it still doesn't destroy the item.
  • DazDaz Member Posts: 127
    while (GetIsObjectValid(oTrash) && GetObjectType(oTrash) == OBJECT_TYPE_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:
        object oTrash = GetFirstObjectInArea(oArea);
        while (GetIsObjectValid(oTrash))
        {
            if (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);
        }
    
  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    edited January 2020
    I tried that when I realized that issue. It still doesn't destroy the item.

    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.
    Post edited by 4BOLTMAIN on
  • 4BOLTMAIN4BOLTMAIN Member Posts: 90
    This is the working code. Thank you for your help.
    void main()
    {
    object oObject, oCopy, oTalker = GetObjectByTag("security");
    AssignCommand(oTalker, ActionSpeakString("HB Hall fires",TALKVOLUME_SHOUT));
    object oChest = GetNearestObjectByTag("Donation_Rack");
    object oInvItem, oPC;
    location lLoc;
    string sName, sMessage;
    object oArea = GetArea(OBJECT_SELF);
    AssignCommand(oTalker, ActionSpeakString("Get Area =" + GetName(oArea),TALKVOLUME_SHOUT));
    
    object oTrash = GetFirstObjectInArea(oArea);
    while (GetIsObjectValid(oTrash))
        {
        if (GetObjectType(oTrash) == OBJECT_TYPE_ITEM)
            {
            lLoc = GetLocation(oTrash);
            oPC = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, oTrash);
            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);
            AssignCommand(oPC, PlaySound("bf_large"));
            DestroyObject(oTrash, 0.0);
            }
        oTrash = GetNextObjectInArea(oArea);
        }
    }
    
Sign In or Register to comment.