Archives des forums MMO/MMORPG > Neverwinter Nights > NWN - Maskado > [script]:régénérer le contenu des coffres et autres
[script]:régénérer le contenu des coffres et autres
Par LeProctophantasmiste le 30/10/2002 Ă 17:17:46 (#2442167)
Il nécessite la version 1.26
//::///////////////////////////////////////////////
//:: Name tp_tb_i0_re_inv
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
Include Script for treasure respawn.
ResRef of the items in the inventory and Respawn delay is stored
on the first
opening of the container. Later usage of the container will check
if the time
for respawning the inventory is reached. Then all items in the
container will
be destroyed and the original items will be created.
*/
//:://////////////////////////////////////////////
//:: Created By: Thomas Buckermann (tabu_niw@freenet.de)
//:://////////////////////////////////////////////
//**************************************************
//Function Declaration
//init Respawn function, called only once
//object oContainer = the container which inventory should respawn,
default is the calling object
//int iTime = intervall between respawn in hours, default is 1 hour
void InitTreasureRespawn(object oContainer = OBJECT_SELF, int iTime =
1);
//check if respawn time is reached, if true destroy inventory amd
respawn items
void TreasureRespawn(object oContainer = OBJECT_SELF);
//The actual CreateObject Function.
void CreateTreasure(object oContainer = OBJECT_SELF);
//***************************************************
//Function implementation
void InitTreasureRespawn(object oContainer = OBJECT_SELF, int iTime =
1)
{
if (GetLocalInt(oContainer, "TP_INIT_RESPAWN") == TRUE)
return;
int iItemCount = 0;
string sItemResRef = ";
//Count all objects in oContainer and store their ResRef
object oItem = GetFirstItemInInventory(oContainer);
int iStackSize = GetNumStackedItems(oItem);
while (oItem != OBJECT_INVALID)
{
iItemCount ++;
sItemResRef = GetResRef(oItem);
SetLocalString(oContainer,
"sItemResRef"+IntToString(iItemCount), sItemResRef);
SetLocalInt(oContainer, "iStackSize"+IntToString(iItemCount),
iStackSize);
oItem = GetNextItemInInventory(oContainer);
iStackSize = GetNumStackedItems(oItem);
}
SetLocalInt(oContainer, "iItemCount", iItemCount);
//Set Respawn Time
int iReHour = GetTimeHour() + iTime;
int iReDay = GetCalendarDay();
int iReMonth = GetCalendarMonth();
int iReYear = GetCalendarYear();
while (iReHour > 23)
{
iReHour = iReHour - 24;
iReDay ++;
if (iReDay > 28)
{
iReDay = iReDay - 28;
iReMonth ++;
if (iReMonth > 12)
{
iReMonth = iReMonth -12;
iReYear ++;
}
}
}
SetLocalInt(oContainer, "iRespawnDelay", iTime);
SetLocalInt(oContainer, "iReHour", iReHour);
SetLocalInt(oContainer, "iReDay", iReDay);
SetLocalInt(oContainer, "iReMonth", iReMonth);
SetLocalInt(oContainer, "iReYear", iReYear);
SetLocalInt(oContainer, "TP_INIT_RESPAWN", TRUE);
}
void TreasureRespawn(object oContainer = OBJECT_SELF)
{
//check if InitTreasureRespawn() function has already been
executed.
//If not, abort script.
if (GetLocalInt(oContainer, "TP_INIT_RESPAWN") == FALSE)
return;
object oItem;
int iReYear = GetLocalInt(oContainer, "iReYear");
int iReMonth = GetLocalInt(oContainer, "iReMonth");
int iReDay = GetLocalInt(oContainer, "iReDay");
int iReHour = GetLocalInt(oContainer, "iReHour");
// iTotalReTime is the respawn "combined" date in hours
int iTotalReTime =
(iReYear*(12*28*24))+(iReMonth*(28*24))+(iReDay*24)+ iReHour;
// iTotalNowTime is the current "combined" date in hours
int iTotalNowTime =
(GetCalendarYear()*(12*28*24))+(GetCalendarMonth()*(28*24))+(GetCalendarDay()*24) + GetTimeHour();
//check for respawn time
if (iTotalReTime > iTotalNowTime)
return;
//Set Respawn Time
int iTime = GetLocalInt(oContainer, "iRespawnDelay");
iReHour = GetTimeHour() + iTime;
iReDay = GetCalendarDay();
iReMonth = GetCalendarMonth();
iReYear = GetCalendarYear();
if (iReHour > 24)
{
iReHour = iReHour - 24;
iReDay ++;
if (iReDay > 28)
{
iReDay = iReDay - 28;
iReMonth ++;
if (iReMonth > 12)
{
iReMonth = iReMonth -12;
iReYear ++;
}
}
}
SetLocalInt(oContainer, "iRespawnDelay", iTime);
SetLocalInt(oContainer, "iReHour", iReHour);
SetLocalInt(oContainer, "iReDay", iReDay);
SetLocalInt(oContainer, "iReMonth", iReMonth);
SetLocalInt(oContainer, "iReYear", iReYear);
//destroy current inventory
oItem = GetFirstItemInInventory(oContainer);
while (oItem != OBJECT_INVALID)
{
DestroyObject(oItem);
oItem = GetNextItemInInventory(oContainer);
}
//create inventory
//Because of timing problems this had to be moved to
//its own function and delayed for 0.2 seconds.
DelayCommand(0.2, CreateTreasure(oContainer));
}
void CreateTreasure(object oContainer = OBJECT_SELF)
{
int iItemCount = GetLocalInt(oContainer, "iItemCount");
string sItemResRef;
int iStackSize;
int x; //generic counter
for (x = 1; x < (iItemCount+1); x++)
{
sItemResRef = GetLocalString(oContainer, "sItemResRef" +
IntToString(x));
iStackSize = GetLocalInt(oContainer, "iStackSize" +
IntToString(x));
object oItem = CreateItemOnObject(sItemResRef, oContainer,
iStackSize);
if (oItem == OBJECT_INVALID)
{
//+++++++++++Debug Message+++++++++++\\
PrintString("!! Failed to create item nr " + IntToString(x) +
" with ResRef " + sItemResRef + " on container "
+ GetTag(oContainer) + " in Area " + GetTag(GetArea(oContainer)) +
"!!");
//+++++++++++++++++++++++++++++++++++\\
}
}
}
en provenance de infinity scripters
Par mobidique le 30/10/2002 Ă 17:36:53 (#2442326)
T'as plus qu'Ă t'ouvrir un post ici
http://forums.jeuxonline.info/showthread.php?s=&threadid=127079
pour référencer les fils ouverts avec ton nom ... ;)
JOL Archives 1.0.1
@ JOL / JeuxOnLine