Recent changes Random page
GAMING
Gaming
 
WoWWiki
Halopedia
FFXIclopedia
Age of Conan
Warhammer Online
Grand Theft Wiki
See more...

Respawn chest

From NWNWiki

Jump to: navigation, search

This respawn chest script is intended to be the onEnter event handler for a trigger. The trigger should be placed so that a player character cannot miss it. Since this script uses the area to store data instead of the trigger, multiple triggers (one for each entrance) can be used for the same chest.

Presumably, this script will cause a chest to reappear if it was previously destroyed, but the exact functionality is not yet documented here. The snippets that have been document are below, followed by the script itself.

This script uses an object (typically a waypoint) with the tag "WP_CHEST" to indicate the place where the chest will appear. The wide end of the waypoint indicates where a PC must stand to open the chest.

This script requires two local strings stored on the module: vCHEST (the ResRef of a chest without a trap) and vtCHEST (the ResRef of a chest with a trap).

// destroy all items with the specified
// resref in this area
//- koconnor100
void CleanArea(string sItem){
    object oObject = GetFirstObjectInArea();
    while(oObject != OBJECT_INVALID)
    {
        if(GetResRef(oObject) == sItem)
        {
            DestroyObject(oObject);
        }
        oObject = GetNextObjectInArea();
    }
}
void main()
{
   float fDelay = 600.0; // delay in seconds until rebuild
   location lChest;
   object wp  ;
   string sChest;
   string sChestUntrapped;
   string sChestTrapped;
   object oArea = GetArea(OBJECT_SELF);
   object oChest;
   object oPC = GetEnteringObject();
   string sExtraScript = GetLocalString(oArea,"ExtraScript");
   string sTrapFairy="trapfairy";
   int i = 1;
   sChestUntrapped = GetLocalString(oArea,"vCHEST");
   sChestTrapped = GetLocalString(oArea,"vtCHEST");
   int vTimer = GetLocalInt(oArea,"TIMER");
   CleanUpSecretDoors();// do this every time, despite timer
   cg_debug("Checking Timer At Begin: "+IntToString(vTimer));
   if (vTimer > 0) return; // timer is running

   //trap logic     -------------------
   //i = 1;
  // wp = GetNearestObjectByTag("WP_TRAP",OBJECT_SELF, i);
   //while (GetIsObjectValid(wp)){
    //  CreateObject( OBJECT_TYPE_CREATURE,
    //     sTrapFairy,
    //     GetLocation(wp)
    //  );
    //  i=i+1;
    //  wp = GetNearestObjectByTag("WP_TRAP",OBJECT_SELF, i);
   //}
   //end trap logic -------------------
   //cg_debug("Starting routine");
   //cg_debug("Chest ="+sChestUntrapped);
   //cg_debug("Chest ="+sChestTrapped);
   // CLEAN UP old chests ..
   CleanArea(sChestUntrapped);
   CleanArea(sChestTrapped);
   i=1;
   wp = GetNearestObjectByTag("WP_CHEST",OBJECT_SELF, i);
   while (GetIsObjectValid(wp)){
      //FloatingTextStringOnCreature("Spawning Chest",oPC);
      lChest = GetLocation(wp);
      if(d2() > 1) {   // 50% trapped
         sChest = sChestUntrapped;
      } else {
         sChest = sChestTrapped;
      }
      // create the chest
      oChest = CreateObject(OBJECT_TYPE_PLACEABLE,
        sChest, lChest
      );
      if(d2() > 1) { // 50% locked
        SetLocked(oChest,TRUE);
      } else {
        SetLocked(oChest,FALSE);
      }
      i=i+1;
      wp = GetNearestObjectByTag("WP_CHEST",OBJECT_SELF, i);
   }
   //CleanUpSecretDoors();
   //cg_debug("Ending area setup routine");
   // any extra proceedures we need to do ?
   if(sExtraScript != ""){
      ExecuteScript(sExtraScript,OBJECT_SELF);
      cg_debug("Executing "+sExtraScript );
   }
   // delay control
   //cg_debug("Setting Timer Value");
   SetLocalInt(oArea,"TIMER",1);
   vTimer = GetLocalInt(oArea,"TIMER");
   //cg_debug("Checking Timer Value:"+IntToString(vTimer));
   //ActionWait(fDelay);
   //SetLocalInt(oArea,"TIMER",0);
   DelayCommand(fDelay,SetLocalInt(oArea,"TIMER",0));
}
Rate this article:
Share this article: