233 lines
9.6 KiB
Plaintext
233 lines
9.6 KiB
Plaintext
|
// pc_export_inc
|
||
|
// Player Characters autosaving function
|
||
|
// Updated: 13-11-2004 IntrepidCW
|
||
|
|
||
|
//Modified by Genisys 5/3/08
|
||
|
//Change to check all PCs for the polymorph effect, not just Shifters.
|
||
|
//Because Spells and Druids polymorph as well.
|
||
|
|
||
|
//***************************************************************************
|
||
|
/*
|
||
|
INSTALLATION:
|
||
|
You need this script, no need to make modifications, except constants
|
||
|
in order to turn options on and off. You could also modify messages.
|
||
|
Tips: You could also save PCs when they sleep, to complement the use of the
|
||
|
timer saving.
|
||
|
|
||
|
In the Module 'OnModuleLoad' script write:
|
||
|
|
||
|
#include "pc_export_inc"
|
||
|
|
||
|
before the main
|
||
|
and
|
||
|
|
||
|
pc_export_onmoduleload();
|
||
|
|
||
|
after the main
|
||
|
*/
|
||
|
//***************************************************************************
|
||
|
|
||
|
|
||
|
//***************************************************************************
|
||
|
// CONSTANTS
|
||
|
|
||
|
//Sets on (TRUE) or off (FALSE) the autosaving for PCs
|
||
|
const int b_charautosavestate = TRUE;
|
||
|
//Time between each saving (seconds)
|
||
|
const float f_autoexportdelay = 180.0;
|
||
|
/*if it fails, time for the second trial, seconds (for each character).
|
||
|
0.0 = No second trial*/
|
||
|
const float f_autoexportdelaytry2 = 15.0;
|
||
|
//How many second intents must we do
|
||
|
const int f_autoexporttry2MaxCounter = 3;
|
||
|
//Turn messages on or off (off FALSE, on TRUE)
|
||
|
const int b_autoexportmessage = TRUE;
|
||
|
/*Time between the Module loads in the server and the first pc saving, in seconds
|
||
|
*/
|
||
|
const float f_autoexportinitime = 180.0;
|
||
|
/*Export all characters in a instant suposses too much work for the hard drive,
|
||
|
it instroduces a moment of lag in the server if there are too much PCs. This
|
||
|
value introduces a small delay between each PC saved. Make it small in order
|
||
|
to avoid problems (script does not check it in order to let you make what you
|
||
|
want)
|
||
|
Recomendation: Must be less than
|
||
|
( f_autoexportdelay - f_autoexportdelaytry2*f_autoexporttry2MaxCounter ) / max_number_of_PCs_on_server
|
||
|
E.g., with default values, with a server for 20 players.
|
||
|
< (60-1*15)/20, it is <2.25
|
||
|
A second is more than enough, if you dont want to have this delay, use 0.0
|
||
|
*/
|
||
|
const float f_export_timeforpc = 0.5;
|
||
|
/* Exporting PCs with the PrC Shifter who are polymorphed, can damage their stats.
|
||
|
If FALSE, it will not save morphed Shifters (default), If TRUE it will save them
|
||
|
anyways. They would not be saved if they are Shifters using the Druid Wild Shape.
|
||
|
*/
|
||
|
const int b_export_morphed_shifters = FALSE;
|
||
|
|
||
|
//***************************************************************************
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//**********************************************************************
|
||
|
//*********************************************************************
|
||
|
// FUNCTIONS
|
||
|
|
||
|
|
||
|
//****************************************************************************
|
||
|
/*Says if the PC has levels in the PrC Shifter and he is morphed, to avoid NWN
|
||
|
Bugs. It will also return TRUE if the PC is a Shifter using the Druid Wild Shape.
|
||
|
Returns TRUE if Morphed Shifter, FALSE if not. */
|
||
|
int IsShifterMorphed(object oPC)
|
||
|
{
|
||
|
effect ef = GetFirstEffect(oPC);
|
||
|
int iShifter = FALSE;
|
||
|
//if (GetLevelByClass(CLASS_TYPE_DRUID,oPC)>0) //Is Shifter, search the PolyEff
|
||
|
while( GetEffectType(ef) != EFFECT_TYPE_INVALIDEFFECT && iShifter == FALSE)
|
||
|
{
|
||
|
if ( GetEffectType(ef) == EFFECT_TYPE_POLYMORPH
|
||
|
/*&& GetLevelByClass(CLASS_TYPE_DRUID,oPC)>0
|
||
|
&& GetAppearanceType(oPC) <= 6*/)
|
||
|
iShifter = TRUE;
|
||
|
ef = GetNextEffect(oPC);
|
||
|
}
|
||
|
return iShifter;
|
||
|
}
|
||
|
//---------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//****************************************************************************
|
||
|
/*It is used for the PC autosaving second trial, if the first time it failed*/
|
||
|
void autoexportfunction2 (object oPlayer, int fb_export_morphed_shifters = FALSE, float fSecondTryDelay = f_autoexportdelaytry2, int fiMaxCounter = f_autoexporttry2MaxCounter, int fiCounter = 1)
|
||
|
{
|
||
|
int MULTI_PLAYER = GetLocalInt(GetModule(), "multi");
|
||
|
|
||
|
if ( GetArea(oPlayer) != OBJECT_INVALID && (IsShifterMorphed(oPlayer) == FALSE || fb_export_morphed_shifters == TRUE) )
|
||
|
{
|
||
|
if(MULTI_PLAYER)
|
||
|
{
|
||
|
ExportSingleCharacter(oPlayer);
|
||
|
}
|
||
|
if (b_autoexportmessage ==TRUE)
|
||
|
SendMessageToPC(oPlayer, "Second intent to save character sucessfull");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (fiCounter >= fiMaxCounter)
|
||
|
{
|
||
|
if (b_autoexportmessage ==TRUE)
|
||
|
SendMessageToPC(oPlayer, "Second intent to save character failed");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
DelayCommand(fSecondTryDelay, autoexportfunction2(oPlayer, fb_export_morphed_shifters, fSecondTryDelay, fiMaxCounter, fiCounter+1) );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
//---------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//****************************************************************************
|
||
|
/*
|
||
|
Saves a character in a secure manner. Works as ExportSingleCharacters(), but, if
|
||
|
the PC cannot be saved (because he is loading another area) it makes another trial
|
||
|
after some seconds have passed.
|
||
|
The time for the second try can be modified with SecondTryDelay (seconds)
|
||
|
If fSecondTryDelay is 0.0 there is no second trial.
|
||
|
*/
|
||
|
void ExportSingleCharacterFix(object oPlayer, int fb_export_morphed_shifters = FALSE, float fSecondTryDelay = f_autoexportdelaytry2, int fMaxCounter = f_autoexporttry2MaxCounter)
|
||
|
{
|
||
|
//Si el personaje no estaba cambiando de Area, se guardo bien
|
||
|
//If the person isn't between areas, save thier character.
|
||
|
if ( GetArea(oPlayer) != OBJECT_INVALID && (IsShifterMorphed(oPlayer) == FALSE || fb_export_morphed_shifters == TRUE) )
|
||
|
{
|
||
|
ExportSingleCharacter(oPlayer);
|
||
|
if (b_autoexportmessage ==TRUE)
|
||
|
SendMessageToPC(oPlayer, "Character Saved");
|
||
|
}
|
||
|
//Sino el personaje estaba cambiando de Area y no se guardo
|
||
|
//Otherwise tell the person why their character was not saved.
|
||
|
else
|
||
|
{
|
||
|
if (b_autoexportmessage ==TRUE)
|
||
|
if (GetArea(oPlayer) == OBJECT_INVALID)
|
||
|
SendMessageToPC(oPlayer, "Your character wasnot saved because you were travelling from one are to another. It will try another time in the next 15 seconds. Tell to DMs if it is not correct.");
|
||
|
else
|
||
|
SendMessageToPC(oPlayer, "Your character wasnot saved because you were Polymorphed. It will try another time in the next 15 seconds. Tell to DMs if it is not correct.");
|
||
|
if (b_autoexportmessage ==TRUE)
|
||
|
//Note I //Commented the line below out because it got annoying as a DM!!!
|
||
|
//SendMessageToAllDMs (GetName(oPlayer)+" ExportPC possible error.");
|
||
|
//Segundo intento de guardado
|
||
|
if (fSecondTryDelay > 0.0)
|
||
|
DelayCommand(fSecondTryDelay, autoexportfunction2(oPlayer, fb_export_morphed_shifters, fSecondTryDelay, fMaxCounter) );
|
||
|
}
|
||
|
}
|
||
|
//---------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
//****************************************************************************
|
||
|
/*
|
||
|
ExportAllCharacters() improved.
|
||
|
Can Export all characters every 'ff_autoexportdelay' seconds (optional) Note
|
||
|
that this event triggers itself, on a timer, when finished -- until the module
|
||
|
is unloaded.
|
||
|
If a PC cannot be exported, it can make a second trial after some seconds
|
||
|
(optional, specify a number of seconds to use the option)
|
||
|
*/
|
||
|
/*
|
||
|
Para que active el autoguardado temporizado: ff_autoexportdelay debe ser positivo > 0.0
|
||
|
Para que NO haga un segundo intento: fSecondTryDelay debe ser 0.0
|
||
|
ff_export_timeforpc: Indica el tiempo que pasa entre que CADA personaje es guardado
|
||
|
esto evita sobrecarga del disco duro por guardar todos los PJs en un instante.
|
||
|
*/
|
||
|
/*Notas sobre la funcion original ExportAllCharacters():
|
||
|
This function is not very robust, this script works in another way.
|
||
|
Note that PCs that are not in an area cannot be saved. (it is a bug/feature of
|
||
|
the ExportCharacter functions). It the first trial is failed
|
||
|
we try it a second time.
|
||
|
Furthermore ExportAll original corrupts some data of PCs with the PrC Shifter.
|
||
|
*/
|
||
|
void ExportAllCharactersFix(int fb_export_morphed_shifters = FALSE, float fSecondTryDelay = f_autoexportdelaytry2, float ff_export_timeforpc = f_export_timeforpc, float ff_autoexportdelay = 0.0, int fMaxCounter = f_autoexporttry2MaxCounter)
|
||
|
{
|
||
|
object oPlayer = GetFirstPC();
|
||
|
float fDelayPerPC = 0.0;
|
||
|
while ( oPlayer!= OBJECT_INVALID )
|
||
|
{
|
||
|
if (ff_export_timeforpc > 0.0)
|
||
|
DelayCommand (fDelayPerPC, ExportSingleCharacterFix(oPlayer, fb_export_morphed_shifters, fSecondTryDelay, fMaxCounter) );
|
||
|
else
|
||
|
ExportSingleCharacterFix(oPlayer, fb_export_morphed_shifters, fSecondTryDelay);
|
||
|
|
||
|
fDelayPerPC = fDelayPerPC + ff_export_timeforpc;
|
||
|
oPlayer = GetNextPC();//next PC
|
||
|
}//end of while
|
||
|
if (ff_autoexportdelay > 0.0)
|
||
|
DelayCommand(ff_autoexportdelay , ExportAllCharactersFix(fb_export_morphed_shifters, fSecondTryDelay , ff_export_timeforpc, ff_autoexportdelay, fMaxCounter));
|
||
|
//delay to next save
|
||
|
}
|
||
|
//---------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
//****************************************************************************
|
||
|
//Sets the autosaving for PCs
|
||
|
/* Start the export characters timer */
|
||
|
//Incorporate this code into Module::OnLoad
|
||
|
//This function must be called by the script in Module's 'OnModuleLoad'.
|
||
|
//When the 'f_autoexportinitime' time passes the autosaving function is executed.
|
||
|
void pc_export_onmoduleload()
|
||
|
{
|
||
|
if (b_charautosavestate == TRUE)
|
||
|
DelayCommand(f_autoexportinitime, ExportAllCharactersFix(b_export_morphed_shifters, f_autoexportdelaytry2 , f_export_timeforpc, f_autoexportdelay, f_autoexporttry2MaxCounter) );
|
||
|
}
|
||
|
//---------------------------------------------------------------------------
|
||
|
|
||
|
|
||
|
|
||
|
//********************************************************************
|
||
|
//********************************************************************
|