Page 1 of 1

Encountercreature Despawning

Posted: Wed Sep 03, 2003 11:59 am
by Neve
This script is useful to prevent low level players from being killed by leftover creatures, spawned by higher lvl players. The script checks the area for players. If there are no players in the area, it will check for players again after 30 seconds. If there are no players at that time, the creatures and their inventory are destroyed. Commoners which are spawned using encounters will not be destroyed.

Code: Select all

/* 
    September 03, 2003 - Eric Ettes - Raiko - zeiren@hotmail.com 
    This script checks an area for encounterspawns and removes them 
    Place this script in the OnExit slot of an area 
*/ 

void RemoveInventory(object oTrash){
    object oInventory = GetFirstItemInInventory(oTrash);
    while(oInventory != OBJECT_INVALID){
        DestroyObject(oInventory);
        oInventory = GetNextItemInInventory(oTrash);
    }
}

void Despawn(object oArea){
    object oTrash = GetFirstObjectInArea(oArea);

    SetLocalInt(oArea, "DespawnPending", 0);

    while(oTrash != OBJECT_INVALID){
        if(GetIsEncounterCreature(oTrash) && !GetStandardFactionReputation(STANDARD_FACTION_COMMONER, oTrash)){
            RemoveInventory(oTrash);
            DestroyObject(oTrash);
        }
        oTrash = GetNextObjectInArea(oArea);
    }
}

void AttemptDespawning(object oArea){
    object oTrash       = GetFirstObjectInArea(oArea);

    while(oTrash != OBJECT_INVALID){
        if(GetIsPC(oTrash)){
            DelayCommand(30.0, AttemptDespawning(oArea));
            return;
        }
        oTrash = GetNextObjectInArea(oArea);
    }
    Despawn(oArea);
}

void main(){
    object oArea        = GetArea(OBJECT_SELF);
    object oTrash       = GetFirstObjectInArea(oArea);

    while(oTrash != OBJECT_INVALID){
        if(GetIsPC(oTrash)) return;
        oTrash = GetNextObjectInArea(oArea);
    }

    oTrash = GetFirstObjectInArea(oArea);

    if(!GetLocalInt(oArea, "DespawnPending")){
        SetLocalInt(oArea, "DespawnPending", 1);
        DelayCommand(30.0, AttemptDespawning(oArea));
    }
}

Posted: Wed Sep 03, 2003 12:10 pm
by Sindol
Hey, that sounds familiar. Judging by your description it must be a lot like the script that Papillon wrote for Avlis.

Posted: Wed Sep 03, 2003 12:18 pm
by Dirk Cutlass
Shouldn't be using the faction rather than the racial type for GetIsCommoner()? You might have some nasty Dwarven Mercs there - that return true for the GetIsCommoner() test.

Not that I know anything about scripting. :wink:

Posted: Wed Sep 03, 2003 12:28 pm
by Neve
@Sindol : I didn't know Avlis had a script for despawning... I recall putting a script here for Remains removal which got a similiar remark =) Then again... I haven't been able to login to Avlis because I haven't acquired SoU yet :(

@Dirk
Whoops, Good point there Dirk, I fixed it. Thanks =P

It now also runs the script once at a time per area no matter how many times someone walks in and out of it, rather than just starting the script an extra time.

Posted: Wed Sep 03, 2003 12:53 pm
by Sindol
Neve wrote:@Sindol : I didn't know Avlis had a script for despawning... I recall putting a script here for Remains removal which got a similiar remark =) Then again... I haven't been able to login to Avlis because I haven't acquired SoU yet :(
Avlis has a script for despawning. It's been running succesfully for some time now after some minor tweaks in the beginning. Maybe you and Papillon should compare notes as he already did some debugging on his scripts for the same goal.

BTW: It still scares the shit out of me when all commoners on the streest of Elysia suddenly die. Apparently the script doesn't recognize DMs present.

Posted: Wed Sep 03, 2003 1:00 pm
by Neve
Hmm, my script doesn't use EffectKill(), which indeed just drops them dead on the floor (And possible inventoryitems will be dropped as loot), the DestroyObject function fades the creatures away :)

Posted: Wed Sep 03, 2003 1:10 pm
by Silk
hehe, actually I wrote the NPC Despawn Script. Pap enhanced it.

It basically works like this:

When the last player leaves an area, a despawn script fires. If nobody enters the area after a delay, it will despawn all npcs in that area.

The next person that enters will trigger the respawn script.

Rinse, Repeat.

Posted: Wed Sep 03, 2003 1:18 pm
by Neve
Yup, that's basically how mine works aswell, mine despawns all hostile NPC's after a delay if there are no players in that area at that time, otherwise it retries after a while etc.