Aller au contenu

Photo

Will this script work for respawning loot in a container?


  • Veuillez vous connecter pour répondre
10 réponses à ce sujet

#1
SuperFly_2000

SuperFly_2000
  • Members
  • 1 004 messages
// Treasure OnClose script
//::////////////////////////////////////
#include "x0_i0_treasure"
const float RESTOCK_TREASURE_DELAY = 900.0; // How long until <span class="highlight">chest</span> will <span class="highlight"><span class="highlight">respawn</span></span> 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));
}

Got it from Pattycake a long time ago.

So I'll be putting this script on the OnCLosed event...

and the usual scripts for generating treasure on the OnOpen even.

(different ones.. such that start with
x0_
x2_
nw_
)

#2
SuperFly_2000

SuperFly_2000
  • Members
  • 1 004 messages
*bump*

#3
Olblach

Olblach
  • Members
  • 175 messages
That looks good, you can test if it works by changing the 900 into 9 and the 60 into a 6. That way you don't have to wait 15 minutes until something happens!

#4
Builder_Anthony

Builder_Anthony
  • Members
  • 450 messages
Silicon scouts treasure dystem

#5
SuperFly_2000

SuperFly_2000
  • Members
  • 1 004 messages
Can I add something to the script so that it puts a lock and/or trap back on the chest/container?

I know it is easy for doors. I can close doors after a certain amount...and re-lock them...


Spin off question: If not I guess I would have to put a door in before you reach the chest..so I know how to close and re-lock the door...but how to "re-trap" it?

Edit: Actually we have this also Sir Elric's Random Respawning Traps v2.7 but shouldn't there be an even easier way?

Modifié par SuperFly_2000, 03 novembre 2010 - 12:17 .


#6
Baragg

Baragg
  • Members
  • 271 messages
This should work for a trap on the chest:



// Creates a Trap on the object specified.
// - nTrapType: The base type of trap (TRAP_BASE_TYPE_*)
// - oObject: The object that the trap will be created on. Works only on Doors and Placeables.
// - nFaction: The faction of the trap (STANDARD_FACTION_*).
// - sOnDisarmScript: The OnDisarm script that will fire when the trap is disarmed.
//                    If "" no script will fire.
// - sOnTrapTriggeredScript: The OnTrapTriggered script that will fire when the
//                           trap is triggered.
//                           If "" the default OnTrapTriggered script for the trap
//                           type specified will fire instead (as specified in the
//                           traps.2da).
// Note: After creating a trap on an object, you can change the trap's properties
//       using the various SetTrap* scripting commands by passing in the object
//       that the trap was created on (i.e. oObject) to any subsequent SetTrap* commands.
void CreateTrapOnObject(int nTrapType, object oObject, int nFaction=STANDARD_FACTION_HOSTILE, string sOnDisarmScript="", string sOnTrapTriggeredScript="")



I added an average holy trap to your script delayed just a hair more than the restocking delay:



// Treasure OnClose script
//::////////////////////////////////////
#include "x0_i0_treasure"
const float RESTOCK_TREASURE_DELAY = 900.0; // How long until <span class="highlight">chest</span> will <span class="highlight"><span class="highlight">respawn</span></span> 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));
  DelayCommand( RESTOCK_TREASURE_DELAY +0.02, CreateTrapOnObject(TRAP_BASE_TYPE_AVERAGE_HOLY,
  OBJECT_SELF));
}


#7
Baragg

Baragg
  • Members
  • 271 messages
Here it is with locking:

// 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));
  DelayCommand(RESTOCK_TREASURE_DELAY +0.02, SetLocked(OBJECT_SELF, TRUE));    DelayCommand(RESTOCK_TREASURE_DELAY+0.03,CreateTrapOnObject(TRAP_BASE_TYPE_AVERAGE_HOLY,
  OBJECT_SELF));
}

Modifié par Baragg, 03 novembre 2010 - 02:55 .


#8
SuperFly_2000

SuperFly_2000
  • Members
  • 1 004 messages
That looks cool...thanks a lot.

#9
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

Baragg wrote...

Here it is with locking:

// 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));
  DelayCommand(RESTOCK_TREASURE_DELAY +0.02, SetLocked(OBJECT_SELF, TRUE));    DelayCommand(RESTOCK_TREASURE_DELAY+0.03,CreateTrapOnObject(TRAP_BASE_TYPE_AVERAGE_HOLY,
  OBJECT_SELF));
}


Just pointing out a side effect in this script that you may not like.  

Bad effect would be as follows. 

PC one opens and closes the chest. 
All Items in the Chest get destroyed 60 sec later. 
870 seconds after the chest was closed PC two opens the chest finds nothing and closes it. 
900 seconds after first open the chest sets itself to regenerate treasure. 
925 seconds after first open PC 3 opens the chest and finds new treasure just to watch it dissapear 5 seconds later. because it is 60 sec after PC 2 closeing the chest.  

The script works. But when the timming of PC opening and closeing the chests happen right you may get complaints of treasure vanishing.  

 

#10
SuperFly_2000

SuperFly_2000
  • Members
  • 1 004 messages
Well...there will be monster respawns in the area that have about the same respawn time as the containers/chests...so I shouldn't have any players walking through unspawned monster areas...or at least probably not looting while doing it....but sure...that could happen....



Guess there is no way to minimize this also as this is how the system works right....(?).

#11
Baragg

Baragg
  • Members
  • 271 messages
Here this should catch that snag that Lightfoot8 brought up.

// 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 oChest = OBJECT_SELF)
{ object oItem = GetFirstItemInInventory(oChest);
  while( GetIsObjectValid( oItem))
  { DestroyObject( oItem, (GetHasInventory( oItem) ? 0.2 : 0.1));
    oItem = GetNextItemInInventory();
  }
}

void RebootTreasure(object oChest)
{
  CTG_SetIsTreasureGenerated( oChest, FALSE);
  SetLocked(oChest, TRUE);
  CreateTrapOnObject(TRAP_BASE_TYPE_AVERAGE_HOLY, oChest);
  SetLocalInt(oChest, "RESET_TREASURE", 0);
}
void main()
{
  int nCheck = GetLocalInt(OBJECT_SELF, "RESET_TREASURE");
  if(nCheck == 1) return;
  else
  {
   SetLocalInt(OBJECT_SELF, "RESET_TREASURE", 1);
   DelayCommand(60.0, DestroyChestContents(OBJECT_SELF));
   DelayCommand(RESTOCK_TREASURE_DELAY, RebootTreasure(OBJECT_SELF));
  }
}

At least I hope my thinking is right on that.

Modifié par Baragg, 05 novembre 2010 - 08:58 .