This is the script so far. Now I just have to work out how to actually block the spell and feat regain. I have a system right now I stole from HCR 2.0 years ago, but its kind of cumbersome.
/*
Module OnPlayerRest script
*/
#include "x3_inc_horse"
#include "_inc_time"
#include "_inc_debug"
#include "_inc_rest"
void ps_RestTimerPseudoHB();
void main()
{
object oPC = GetLastPCRested();
object oMount;
//---------------------------- BIOWARE CRAP ------------------------------------
if (!GetLocalInt(GetModule(),"X3_MOUNT_NO_REST_DISMOUNT"))
{
if (HorseGetIsMounted(oPC))
{
if (GetLocalInt(oPC,"X3_REST_CANCEL_MESSAGE_SENT"))
{
DeleteLocalInt(oPC,"X3_REST_CANCEL_MESSAGE_SENT");
}
else
{
FloatingTextStrRefOnCreature(112006,oPC,FALSE);
SetLocalInt(oPC,"X3_REST_CANCEL_MESSAGE_SENT",TRUE);
}
AssignCommand(oPC,ClearAllActions(TRUE));
return;
}
}
if (!GetLocalInt(GetModule(),"X3_MOUNT_NO_REST_DESPAWN"))
{
oMount=HorseGetPaladinMount(oPC);
if (!GetIsObjectValid(oMount)) oMount=GetLocalObject(oPC,"oX3PaladinMount");
if (GetIsObjectValid(oMount))
{
if (oMount==oPC||!GetIsObjectValid(GetMaster(oMount))) AssignCommand(oPC,HorseUnsummonPaladinMount());
else { AssignCommand(GetMaster(oMount),HorseUnsummonPaladinMount()); }
}
}
//------------------------------------------------------------------------------
int nRestTimer = GetLocalInt(GetModule(), "REST_TIMER");
SendDebugMessageToPC(oPC, "INITIAL REST TIMER = " +IntToString(nRestTimer));
int nTimePassed;
if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED )
{
// Set all regain status to TRUE
SetLocalInt(GetModule(), "WIZARD_REGAIN", TRUE);
SetLocalInt(GetModule(), "DIVINE_REGAIN", TRUE);
SetLocalInt(GetModule(), "FEAT_REGAIN", TRUE);
// Check for spellbook
if (GetLevelByClass(CLASS_TYPE_WIZARD, oPC) > 0)
{
if (!HasItem(oPC, "IT_SPELLBOOK") )
{
SetLocalInt(GetModule(), "WIZARD_REGAIN", FALSE);
SendMessageToPC(oPC, "You need a spellbook to regain spells.");
}
}
// Check for divine symbol
if (GetLevelByClass(CLASS_TYPE_CLERIC, oPC) > 0 ||
GetLevelByClass(CLASS_TYPE_DRUID, oPC) > 0 ||
GetLevelByClass(CLASS_TYPE_PALADIN, oPC) > 0 ||
GetLevelByClass(CLASS_TYPE_RANGER, oPC) > 0 )
{
if (!HasItem(oPC, "IT_SYMBOL") )
{
SetLocalInt(GetModule(), "DIVINE_REGAIN", FALSE);
SendMessageToPC(oPC, "You need a divine symbol to regain spells.");
}
}
if (GetGameDifficulty() >= GAME_DIFFICULTY_CORE_RULES )
{
// Check if 24 hours have passed for the PC
if (!nRestTimer )
{
// OK to regain - do nothing
}
else
{
// Too soon - no feat or spell regain
SetLocalInt(GetModule(), "WIZARD_REGAIN", FALSE);
SetLocalInt(GetModule(), "DIVINE_REGAIN", FALSE);
SendMessageToPC(oPC, "You cannot regain spells until 24 hours have passed.");
SetLocalInt(GetModule(), "FEAT_REGAIN", FALSE);
SendMessageToPC(oPC, "You cannot regain feats until 24 hours have passed.");
}
}
}
else if (GetLastRestEventType() == REST_EVENTTYPE_REST_CANCELLED )
{
// Advance game clock
nTimePassed = d8();
ps_AdvanceGameClock(nTimePassed);
SendMessageToPC(oPC, ps_IntToText(nTimePassed)+" hours have passed while you rested.");
// If a rest cycle has already started, index the cycle by the time passed
if (!nRestTimer)
{
SetLocalInt(GetModule(), "REST_TIMER", nRestTimer+nTimePassed);
}
}
else if (GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED )
{
// Regain
SendDebugMessageToPC(oPC, "ARCANE REGAIN = " +IntToString(GetLocalInt(GetModule(), "nWizSpellRegain")));
SendDebugMessageToPC(oPC, "DIVINE REGAIN = " +IntToString(GetLocalInt(GetModule(), "nDivSpellRegain")));
SendDebugMessageToPC(oPC, "FEAT REGAIN = " +IntToString(GetLocalInt(GetModule(), "nFeatRegain")));
if (GetLocalInt(GetModule(), "WIZARD_REGAIN") > 0 )
{
// OK to regain, do nothing
SendDebugMessageToPC(oPC, "SPELLS REGAINED");
}
else
{
// Too soon to regain
SendDebugMessageToPC(oPC, "SPELLS NOT REGAINED");
}
if (GetLocalInt(GetModule(), "DIVINE_REGAIN") > 0 )
{
// OK to regain, do nothing
SendDebugMessageToPC(oPC, "SPELLS REGAINED");
}
else
{
// Too soon to regain
SendDebugMessageToPC(oPC, "SPELLS NOT REGAINED");
}
if (GetLocalInt(GetModule(), "FEAT_REGAIN") > 0 )
{
// OK to regain, do nothing
SendDebugMessageToPC(oPC, "FEATS REGAINED");
}
else
{
// Too soon to regain
SendDebugMessageToPC(oPC, "FEATS NOT REGAINED");
}
// Advance game clock
ps_AdvanceGameClock(8);
SendMessageToPC(oPC, "Eight hours have passed while you rested.");
// If this was the first time resting, start the regain interval timer
if (!nRestTimer)
{
SetLocalInt(GetModule(), "REST_TIMER", 1);
DelayCommand(6.0, ps_RestTimerPseudoHB());
}
else // Index the rest cycle by the time passed
{
SetLocalInt(GetModule(), "REST_TIMER", nRestTimer+8);
}
SendDebugMessageToPC(oPC, "REST TIMER = " +IntToString(GetLocalInt(GetModule(), "REST_TIMER")));
}
}
void ps_RestTimerPseudoHB()
{
int nTime = GetLocalInt(GetModule(), "REST_TIMER");
if (nTime < 480)
{
nTime++;
SetLocalInt(GetModule(), "REST_TIMER", nTime);
DelayCommand(6.0, ps_RestTimerPseudoHB());
}
else
{
DeleteLocalInt(GetModule(), "REST_TIMER");
}
}
_inc_debug
const string PUBLIC_CDKEY = "UP7GTJDE";
// Sends a debug message to the module builder
void SendDebugMessageToPC(object oPC, string sMessage);
void SendDebugMessageToPC(object oPC, string sMessage)
{
if (GetPCPublicCDKey(oPC, TRUE) == PUBLIC_CDKEY) // Change the string to match the PublicCDKey of the module Builder
{
SendMessageToPC(oPC, sMessage);
}
}
_inc_time
/*
Time Functions library
*/
//---------------------- FUNCTION DEFINITIONS ----------------------------------
// Advance the game clock by the time specified (hours, minutes, seconds, milliseconds)
void ps_AdvanceGameClock(int nHr = 0, int nMin = 0, int nSec = 0, int nMil = 0);
// Convert nTime to its text equivalent
string ps_IntToText(int nTime);
//---------------------- FUNCTION IMPLEMENTATION -------------------------------
void ps_AdvanceGameClock(int nHr = 0, int nMin = 0, int nSec = 0, int nMil = 0)
{
int nHour = GetTimeHour() + nHr;
int nMinute = GetTimeMinute() + nMin;
int nSecond = GetTimeSecond() + nSec;
int nMillisecond = GetTimeMillisecond() + nMil;
SetTime(nHour, nMinute, nSecond, nMillisecond);
}
string ps_IntToText(int nTime)
{
string sTime;
if (nTime < 9)
{
switch (nTime)
{
case 1: sTime = "One"; break;
case 2: sTime = "Two"; break;
case 3: sTime = "Three"; break;
case 4: sTime = "Four"; break;
case 5: sTime = "Five"; break;
case 6: sTime = "Six"; break;
case 7: sTime = "Seven"; break;
case 8: sTime = "Eight"; break;
case 9: sTime = "Nine"; break;
}
}
else
{
sTime = IntToString(nTime);
}
return sTime;
}