Author Topic: Respawning loot in containers  (Read 555 times)

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Respawning loot in containers
« on: August 05, 2010, 12:54:12 pm »


               I found this script while rummaging through the old forums.

// Treasure OnClose script
//::////////////////////////////////////
#include "x0_i0_treasure"
const float RESTOCK_TREASURE_DELAY = 900.0; // How long until chest will respawn treasure (in seconds).
void DestroyChestContents()
{ object oItem = GetFirstItemInInventory();
  while( GetIsObjectValid( oItem))
  { DestroyObject( oItem, (GetHasInventory( oItem) ? 0.2 : 0.1));
    oItem = GetNextItemInInventory();
  }
}
void main()
{
  DelayCommand(60.0, DestroyChestContents());
  DelayCommand( RESTOCK_TREASURE_DELAY +0.01, CTG_SetIsTreasureGenerated( OBJECT_SELF, FALSE));
}
(Posted by Pattycake initially)

It will work right?

I mean assuming you have the normal scripts on the containers OnOpened event and so on...
               
               

               


                     Modifié par SuperFly_2000, 05 août 2010 - 11:55 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Respawning loot in containers
« Reply #1 on: August 05, 2010, 12:59:16 pm »


               yeah, but its not persistent
               
               

               
            

Legacy_SuperFly_2000

  • Hero Member
  • *****
  • Posts: 1292
  • Karma: +0/-0
Respawning loot in containers
« Reply #2 on: August 05, 2010, 01:06:40 pm »


               It's not?
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Respawning loot in containers
« Reply #3 on: August 05, 2010, 01:30:41 pm »


               It works but if your using the Generic Treasure System I suggest going to the Module Wide to control gear better. Or better yet Silicons System. Here is another way that works froma different source.



This is just a matter of altering the script that is already there. For this example I will use the script nw_02_classlow treasure script. The same alteration can be made to all of them.
When the chest is first opened, the Local Variable on the chest called "NW_DO_ONCE" is 0. Therefore the treasure spawns. After that the Local Variable is then set to 1. Which prevents the treasure from respawning because of the "if" statement.
We simply need to add a delay time and set the int back to 0 so the treasure can spawn again. Replace the following script in the OnOpen node of the chest or placable.

If you definatly want this on all chest you place, you can save this script with the same name of the default script you are replaceing. This way it will be on each chest you place down. Keep in mind that it only effects that module.


//::///////////////////////////////////////////////
//:: General Treasure Spawn Script
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Spawns in general purpose treasure, usable
    by all classes.
    Altered By Glenn J. Berden aka Jassper
    fDelay is the time in seconds before the chest
    will respawn a treasure.
    i.e. a time of 60.0 = 1 minute Real Time.
*/
//:://////////////////////////////////////////////
//:: Created By:   Brent
//:: Created On:   February 26 2001
//:://////////////////////////////////////////////
#include "NW_O2_CONINCLUDE"
void main()
{
    float fDelay = 120.0;
    if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)
    {
       return;
    }
    object oLastOpener = GetLastOpener();
    GenerateLowTreasure(oLastOpener, OBJECT_SELF);
    SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
    DelayCommand(fDelay,SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",0));
    ShoutDisturbed();
}




Note; After fDelay to set the time in sec before the treasure will respawn.
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Respawning loot in containers
« Reply #4 on: August 05, 2010, 06:25:53 pm »


               I use this for my spiders webs ..put it ondeath and make sure resref and tag are the same .Found it on the vault I think.
void RespawnObject(string sResRef, int iType, location lLoc) {
CreateObject(iType, sResRef, lLoc);
}
void main()
{
string sResRef = GetResRef(OBJECT_SELF);
int iType = GetObjectType(OBJECT_SELF);
// For creatures, save the location at spawn-time as a local location and
// use it instead. Otherwise, the creature will respawn where it died.
// No changes are required for placeables as they do not move (usually ;-)
location lLoc =GetLocation(OBJECT_SELF);
float fDelay = 10.0; // 5 minute delay; adjust as desired
AssignCommand(GetModule(), DelayCommand(fDelay, RespawnObject(sResRef, iType, lLoc)));
}

Oh shoot just realize you are respawning loot and not the container...'Posted
               
               

               


                     Modifié par Knight_Shield, 05 août 2010 - 05:28 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Respawning loot in containers
« Reply #5 on: August 05, 2010, 08:07:16 pm »


               I think it depends on what your "normal" OnOpened script is. if your using  the "nw_o2_classhig" type scripts then I don't think it will work as that is setting a "DO_ONCE" integer variable on the chest(unless i missed something in one of the bioware include scripts that changes it back to 0). If you are using those scripts then I would do exactly what TSMDude posted and skip the "OnClosed" all together. And if you want the items in the chest to be destroyed if no one takes them, as the script you posted does, then you can add a bit more to take care of that as well.



Good Luck.