These resources are available to all Broodslayers
for use in modules to be submitted for the Broodslayers Official
PW server. If you use them in other projects, please give the
guild and scripters credit, thank you.
BROODSLAYERS
PW SCRIPTS
onDeath
and onOpen scripts for RESPAWNABLE CONTAINERS
onOpen script for RESPAWNABLE CONTAINERS...
NOTE: You must use these onOpen
and onDeath scripts TOGETHER for this respawning and reseeding
chests to work right. Also, you need a unique name for each variant
of this script you create. For example, I have 01barl01ondeath
and 01barl01onopen for the first barrel, then the second barrel
has a torch in it instead of the gold, so it requires a totally
different script that spawns a torch in both the onopen and ondeath
events. This one is then called 01barl02ondeath and 01barl02onopen.
I hope that makes sense.
This particular one seeds the container with
a random amount of 4-80 gold.
It can be used for any type of container placeable:
Chests, barrels, treasure piles, loot bags, chest of drawers,
crates, etc.
// function to convert the in-game time into total
seconds and
// check the current time against the chests first opened time.
// This function is setup to use 2 minutes/1 hour default time
// setting. If the server is not at 2 minutes/1 hour this script
// will not keep exact time. 1800= 1/2 hour
#include "NW_O2_CONINCLUDE"
void CheckRealTime()
{
// If the container has already reset, we do not want to do anything
if (GetLocalInt (OBJECT_SELF, "NW_DO_ONCE")
== 0)
return;
int iX = Random (1800) + 1800;
int respawntime = iX; //time in seconds to respawn
int realtimeyr = GetCalendarYear() - GetLocalInt(OBJECT_SELF,
"timeyr");
int realtimemonth = GetCalendarMonth() - GetLocalInt(OBJECT_SELF,
"timemonth");
int realtimeday = GetCalendarDay() - GetLocalInt(OBJECT_SELF,
"timeday");
int realtimehour = GetTimeHour() - GetLocalInt(OBJECT_SELF, "timehour");
int realtimemin = GetTimeMinute() - GetLocalInt(OBJECT_SELF, "timemin");
int realtimesec = GetTimeSecond() - GetLocalInt(OBJECT_SELF, "timesec");
int realtimetest = ((realtimeyr*967680) + (realtimemonth*80640)
+ (realtimeday*2880) + (realtimehour*120) + (realtimemin*60) +
realtimesec);
// Time in seconds after container was opened to respawn
if (realtimetest > respawntime)
SetLocalInt(OBJECT_SELF, "NW_DO_ONCE", 0); //Set do
once flag back to 0
}
// Function to empty all contents of the container
void ClearInventory()
{
object oItem = OBJECT_INVALID;
oItem = GetFirstItemInInventory();
while ( oItem != OBJECT_INVALID )
{
DestroyObject( oItem, 0.0 );
oItem = GetNextItemInInventory();
}
}
// Function to generate the new treasure in the container.
void FillInventory()
{
object oLastOpener = GetLastOpener();
ClearInventory(); // Clear the inventory out first
// Now we can finally place loot into the
//nRandom used to give gold
int nRandom =d20(4);
CreateItemOnObject ("NW_IT_GOLD001", OBJECT_SELF, nRandom);
}
//
//
//
void main()
{
CheckRealTime(); // Check how long
since first chest opening
// Check to see if NW_DO_ONCE is set to 0, if it isn't, do nothing
if (GetLocalInt (OBJECT_SELF,"NW_DO_ONCE")
!= 0)
return;
SetLocalInt(OBJECT_SELF, "timeyr", GetCalendarYear()
);
SetLocalInt(OBJECT_SELF, "timemonth", GetCalendarMonth()
);
SetLocalInt(OBJECT_SELF, "timeday", GetCalendarDay()
);
SetLocalInt(OBJECT_SELF, "timehour", GetTimeHour() );
SetLocalInt(OBJECT_SELF, "timemin", GetTimeMinute()
);
SetLocalInt(OBJECT_SELF, "timesec", GetTimeSecond()
);
// Set the NW_DO_ONCE variable to 1 to indicate it has now been
opened and
// needs to start waiting for a respawn
SetLocalInt (OBJECT_SELF, "NW_DO_ONCE",1);
ShoutDisturbed();
// If we've made it this far, we can now safely repopulate the
chest's inventory
FillInventory();
}
onDeath script for RESPAWNABLE CONTAINERS...
#include "NW_O2_CONINCLUDE"
void ClearInventory()
{
object oItem = OBJECT_INVALID;
oItem = GetFirstItemInInventory();
while ( oItem != OBJECT_INVALID )
{
DestroyObject( oItem, 0.0 );
oItem = GetNextItemInInventory();
}
}
// Function to generate the new treasure in the container.
void FillInventory()
{
object oLastOpener = GetLastOpener();
ClearInventory(); // Clear the inventory out first
// Now we can finally place loot into the
//nRandom used to give gold
int nRandom =d20(4);
CreateItemOnObject ("NW_IT_GOLD001", OBJECT_SELF, nRandom);
}
void RespawnChest(location lLoc, string sResRef)
{
object oTarget = OBJECT_SELF;
CreateObject (OBJECT_TYPE_PLACEABLE, sResRef, lLoc);
}
void main()
{
//Get resref of container
string sResRef = GetResRef (OBJECT_SELF);
// Get location of chest that was destroyed
location lSpawnPoint = GetLocation (OBJECT_SELF);
// Assign command to respawn chest in same location, with delay
1800.0 (30 mins)
float fX = IntToFloat(Random (1800) + 1801);
AssignCommand (GetArea (OBJECT_SELF), DelayCommand(fX,RespawnChest
(lSpawnPoint, sResRef)));
if (GetLocalInt (OBJECT_SELF, "NW_DO_ONCE") != 0)
{
return;
}
object oLastOpener = GetLastOpener();
ClearInventory();
FillInventory();
SetLocalInt (OBJECT_SELF, "NW_DO_ONCE",1);
ShoutDisturbed();
}
If you have further questions, contact Chokra at
chokra@broodslayers.com.