abstract
| - This goes in the onEnter event of a trigger. Lay it down where a player cant miss it. Since it's using the area itself to store the data it needs instead of the trigger, you can lay down several triggers, at several doors, and they'll all act as if they were the same trigger. Oh, when you fill up the area with way points ? WP_CHEST is the one, and make sure the wide end faces where the player must stand to open it. vCHEST = resref of a chest (no trap) vtCHEST = resref of a chest (with a trap) enter these two variables as local strings on the module itself (just go to the advacned tab and hit variables and enter them by hand) and you're all set. Regular NWN chest, custom chest, it doesn't matter. // 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)); }
- This respawn chest script allows chests (placeables) to be regenerated. (The inspiration was placing treasure chests within an area, but any placeable can be used.) The module builder marks the locations where the chests appear. When this script is run, instances of a single placeable blueprint are created at each of those locations, and any objects remaining from an earlier run are destroyed. This script was written as the onEnter event handler for a trigger, but can be used for any event, or even executed by other means. The main requirement is that it is executed by an object within an area or by the area itself (but not by the module). Processing is done per area, so execution by an object within the area is equivalent to execution by the area. There is a delay (600 seconds, or 10 minutes) built into the script to prevent it from firing too often. To use this script, the builder must place objects, usually waypoints, to mark where the placeables will appear (paying attention to both position and facing). These objects must have the same tag, which is specified as WP_CHEST in the below script. The builder must also prepare (or choose) a blueprint from which the chests will be created. This blueprint must include any lock or trap that is desired; half of the created objects will become unlocked, and an independent half will become untrapped, but it is up to the builder to specify the lock and trap for the remainder. The ResRef of this blueprint can replace plc_chest1 in the below script, or it can be specified as affecting only one area by setting a local string named vtCHEST on the area. // ** configuration ** const float DELAY_REBUILD = 600.0; // Delay in seconds until the chests respawn. const string TAG_MARKER = "WP_CHEST"; // Tag of the objects marking where chests appear. const string RESREF_CHEST = "plc_chest1"; // Default ResRef of the chest to create; may be overridden by the area. // If some of the chests should be locked, the ResRef must be set to "locked". // If some of the chests should be trapped, the ResRef must include a trap. const string LV_RESREF_CHEST = "vtCHEST"; // Name of the local string (on an area) that overrides the default chest ResRef. // ** internal constants ** const string LV_CHEST = "vtCHEST__Mine"; const string LV_TIMER = "vtCHEST__Suppressed"; void main() {object oArea = GetArea(OBJECT_SELF); // Do not run too often. if ( GetLocalInt(oArea, LV_TIMER) ) return; SetLocalInt(oArea, LV_TIMER, TRUE); AssignCommand(oArea, DelayCommand(DELAY_REBUILD, SetLocalInt(oArea, LV_TIMER, FALSE))); // What chest to use? string sChestResRef = GetLocalString(oArea, LV_RESREF_CHEST); if ( sChestResRef == "" ) sChestResRef = RESREF_CHEST; // Loop through the markers in this area. int nNth = 1; object oAnchor = GetFirstObjectInArea(oArea); // In case OBJECT_SELF is the area. object oMarker = GetNearestObjectByTag(TAG_MARKER, oAnchor, nNth); while ( OBJECT_INVALID != oMarker ) { // Destroy any existing chest. DestroyObject(GetLocalObject(oMarker, LV_CHEST)); // Create a chest. object oChest = CreateObject(OBJECT_TYPE_PLACEABLE, sChestResRef, GetLocation(oMarker)); SetLocalObject(oMarker, LV_CHEST, oChest); if ( Random(2) ) SetLocked(oChest, FALSE); // 50% unlocked if ( Random(2) ) SetTrapDisabled(oChest); // 50% not trapped // Update the loop. oMarker = GetNearestObjectByTag(TAG_MARKER, oAnchor, ++nNth); } }
|