Here's the entire script, the other script this ties into will follow below this one:
//::///////////////////////////////////////////////
//:: AD On Rest
//:: ad_on_play_rest
//with Purple Rose v 1.1.3
//::///////////////////////////////////////////////
#include "pri_inc"
#include "srace_inc"
#include "ad_inc_food_rest"
#include "hc_inc_fatigue"
#include "ad_inc_cls_restr"
#include "ad_debug_inc"
#include "inc_movement"
int iRESTBREAK;
int iFOODSYSTEM;
int iMinRest;
int nRestHP;
int nSSB;
int nHasFood;
object oBedroll;
int iCount;
int iBedUse;
//object oMod = GetModule();
void InitRestVariables()
{
// FOODSYSTEM - Controls if the player needs to eat
iFOODSYSTEM = 1;
// RESTBREAK - Controls how long between rests in hours
iRESTBREAK = 4;
iMinRest = iRESTBREAK*nConv;
nSSB=SecondsSinceBegin();
}
void SetRestTime(object oPC, int iCount)
{
int iDec = iRESTBREAK/6;
//int n0SSB = GetLocalInt(oMod, "SecSB"+GetName(oPC)+GetPCPublicCDKey(oPC));
if(iDec < 1) iDec =1;
iCount = iCount-iDec;
if(iCount > 0)
{
int nNSB = nSSB-(iCount*60);
if(nNSB < 1) nNSB = 1;
if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
SetLocalInt(oMod, ("LastRest" + GetName(oPC) + GetPCPublicCDKey(oPC)), nNSB);
DelayCommand(6.0, SetRestTime(oPC, iCount));
}
}
}
// void ApplyArmorRestPenalty(object oPC)
//{
// Armor penalty. Check only if rest fully completed.
// if (GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED ) {
//int bFatigued = GetLocalInt(oPC, "bFatigued");
//int bExhausted = GetLocalInt(oPC, "bExhausted");
// Check for armor, and give a penalty for armor +5 and above.
// object oArmor = GetItemInSlot(INVENTORY_SLOT_CHEST, oPC);
// if(GetChestArmorBaseType(oArmor) > 1 && GetChestArmorBaseType(oArmor) <= 5)
// {
// MakePlayerFatigued(oPC,FATIG);
// }else if(GetChestArmorBaseType(oArmor) > 5) {
// MakePlayerExhausted(oPC,EXHAUS);
// }
// }
// }
int DoesPCHaveBedroll(object oPC)
{
oBedroll = GetItemPossessedBy(oPC,"bedroll");
if (GetIsObjectValid(oBedroll))
return 1;
else {
oBedroll = GetLocalObject(oMod,"inbedroll" + GetName(oPC) + GetPCPublicCDKey(oPC));
if (GetIsObjectValid(oBedroll))
return 1;
}
return 0;
}
void ApplySleepEffects(object oPC)
{
effect eSnore = EffectVisualEffect(VFX_IMP_SLEEP);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSnore, oPC, 7.0);
//insert special effects here. I tried EffectSleep along with different
//animations. They either get overrode by the rest anim or cancel the rest.
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSnore, oPC, 7.0);
effect eBad = GetFirstEffect(oPC);
//Search for negative effects
int nBlindMe=1;
while(GetIsEffectValid(eBad))
{
int nEtype=GetEffectType(eBad);
if(nEtype==EFFECT_TYPE_TRUESEEING)
nBlindMe=0;
eBad=GetNextEffect(oPC);
}
if(nBlindMe)
{
effect eBlind = EffectBlindness();
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eBlind, oPC, 29.0);
}
DelayCommand(7.0, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSnore, oPC, 7.0));
}
void RemoveSleepBlindness(object oPC)
{
effect eBad = GetFirstEffect(oPC);
//Search for negative effects
while(GetIsEffectValid(eBad)) {
int nEtype=GetEffectType(eBad);
if (nEtype == EFFECT_TYPE_BLINDNESS) {
//Remove effect if it is negative.
RemoveEffect(oPC, eBad);
}
eBad = GetNextEffect(oPC);
}
}
void ReplaceBedroll(object oPC)
{
oBedroll=GetLocalObject(oMod, "inbedroll"+GetName(oPC)+GetPCPublicCDKey(oPC));
CreateItemOnObject("bedroll", oPC);
DestroyObject(oBedroll);
DeleteLocalObject(oMod, "inbedroll"+GetName(oPC)+GetPCPublicCDKey(oPC));
}
void main()
{
object oPC = GetLastPCRested();
// DEBUG PRINT OUT
if (AD_DEBUG == 1) {
string sDebug = "ad_on_play_rest: "+GetName(oPC)+" attempt to rest";
PrintString(sDebug); }
string sID = GetName(oPC) + GetPCPublicCDKey(oPC);
// See if they are in a Barracks
object oArea = GetArea(oPC);
int nBARRACK = GetLocalInt(oPC, "BARRACKS");
object oFam = GetPCFamiliar(oPC);
if(GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED){
EffectArmorEncumbrance(oPC);
RestrictionCheckDruid(oPC);
if(GetLocalInt(oPC,"NOSPELLS")==1)
RemoveAllSpellsAndFeats(oPC);
}
if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
nRestHP = GetCurrentHitPoints(oPC);
// Don't allow rest if it is restricted
object noRest = GetNearestObjectByTag("NORESTWP", oPC);
if(GetIsObjectValid(noRest))
{
AssignCommand( oPC, ClearAllActions());
FloatingTextStringOnCreature("You must rest in a Inn or Tavern!",oPC,FALSE);
return;
}
string sFullArea = GetStringUpperCase(GetTag(oArea));
int nBarks = FindSubString(sFullArea, "BARRACK");
int nSRace = sr_GetSubRace(oPC);
if(nBarks != -1)
{
// Vamp fledgling check
if(nSRace==SUBRACE_VAMPIRE && GetHitDice(oPC)>4)
{
AssignCommand( oPC, ClearAllActions());
FloatingTextStringOnCreature(VAMPNOREST,oPC,FALSE);
}else{
if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
ApplySleepEffects(oPC);
SavePreRestFamiliarHP(oPC, oFam);
}
if(GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED)
{
SetLocalInt(oPC,"RESTING",0);
DeleteLocalInt(oPC, "REST");
RemoveSleepBlindness(oPC);
SetSubRaceAbilites(oPC, nSRace);
}
}
SetLocalInt(oPC, "BARRACKS",1);
return;
}
if(GetCurrentHitPoints(oPC)<=FloatToInt((IntToFloat(GetMaxHitPoints(oPC))*0.2)))
DeleteLocalInt(oMod, ("LastRest" + sID));
int iBedroll;
int iBedUse = GetLocalInt(oPC, "RSA_BedUse");
if (iBedUse == 0) iBedroll = DoesPCHaveBedroll(oPC);
//Start of Inn Resting Mod
int iCanBedRoll = 1;
int iSleep = 0;
int iKill = 0;
int iWakeUp = 0;
int iRatChance = 0;
int iFail = 0;
string sWhyNoSleep = "Error in pri_on_play_rest script";
string sPoorRoom = "Error in pri_on_play_rest script";
//string sFood = GetLocalString(oPC, "RSA_FoodType");
object oButler = OBJECT_INVALID;
object oPRIForceInnRest = GetNearestObjectByTag("PRIForceInnRest", oPC);
if (GetIsObjectValid(oPRIForceInnRest)) iCanBedRoll = 0;
if(iBedUse > 0)
{
DeleteLocalInt(oMod, ("LastRest" + sID));
GetInnArea(oPC);
iRatChance = GetLocalInt(oPC, "RSA_RatChance");
string sButler = GetLocalString(oPC, "RSA_Butler");
sPoorRoom = GetLocalString(oPC, "RSA_PoorWake");
oButler = GetObjectByTag(sButler);
if(iBedUse == iRSA_POORBED) iWakeUp = 1;
if(iBedUse == iRSA_RICHBED) iKill = GetLocalInt(oButler, "RSA_KillInSleep");
}
if(iBedUse > 0 || (iCanBedRoll > 0 && iBedroll > 0)) iSleep = 1;
if(iSleep == 0 && GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
AssignCommand(oPC, ClearAllActions());
sWhyNoSleep = NOBEDROLL;
if (iCanBedRoll == 0) sWhyNoSleep = SLEEPINN;
FloatingTextStringOnCreature(sWhyNoSleep, oPC, FALSE);
return;
}
// Vampire for sleeping in a Inn
if(iBedUse > 0 && nSRace==SUBRACE_VAMPIRE && GetHitDice(oPC)>4 &&
GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
AssignCommand(oPC, ClearAllActions());
FloatingTextStringOnCreature(VAMPNOREST, oPC, FALSE);
return;
}
if((iSleep == 0 && GetLastRestEventType() == REST_EVENTTYPE_REST_CANCELLED) ||
(iSleep == 0 && GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED))
{
return;
}
//End of Inn Sleeping Mod
InitRestVariables();
// Limit group resting
//if(nSRace=!SUBRACE_VAMPIRE && RestrictPartyRestOnLimitRestHealAndArmorPen(oPC)) return;
// Vampires dont need food
if(nSRace == SUBRACE_VAMPIRE)
{
if(!GetLocalInt(oPC, "IN_COFFIN"))
{
AssignCommand( oPC, ClearAllActions());
FloatingTextStringOnCreature(VAMPNOREST, oPC, FALSE);
return;
}else{
// Vamps dont need food
iFOODSYSTEM = 0;
nHasFood = 1;
}
}
if(GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
SavePreRestFamiliarHP(oPC, oFam);
if(iFOODSYSTEM) nHasFood = 0;
SetLocalInt(oMod,"HPStartRest" + sID,nRestHP);
object oFood;
int iFail = 0;
// Fail checks
iMinRest = iRESTBREAK*nConv;//(iRESTBREAK+4)*nConv;
if(iBedUse == 0)
{
if(iFail==0) iFail = IsTooSoonToRest(oPC, iMinRest, nSSB, nConv);
if(iFail==0) iFail = IsPCTooWeakToRest(oPC);
if(iFOODSYSTEM && !iFail)
{
if(HasPCEaten(oPC)==1)
nHasFood = 1;
else
iFail = 1;
}
}
if(iFail==0)
{
ApplySleepEffects(oPC);
}else
return;
if(iBedroll && iBedUse == 0)
{
object oNewBedroll=CreateObject(OBJECT_TYPE_PLACEABLE,"bedroll",GetLocation(oPC));
DestroyObject(oBedroll);
SetLocalInt(oMod,"LostBedRoll"+sID,1);
SetLocalObject(oMod,"inbedroll"+sID,oNewBedroll);
}
//PRI Mod
if(iBedUse > 0)
{
if(iWakeUp == 1 && iFail == 0)
{
int iRoll = d100(1);
if(iRoll >= iRatChance)
{
AssignCommand(oPC, ClearAllActions());
SendMessageToPC(oPC, sPoorRoom);
}
}
if(iKill == 1 && iFail == 0)
{
SendMessageToAllDMs(GetName(oPC)+" has been targeted by the Assassin in "+GetName(GetArea(oPC))+".");
location lLoc = GetLocation(GetWaypointByTag("AssassinSpawn"));
object oAssassin = CreateObject(OBJECT_TYPE_CREATURE, "assassian", lLoc, TRUE);
AssignCommand(oAssassin, ActionAttack(oPC, FALSE));
SetLocalInt(oButler, "RSA_KillInSleep", 0);
SendMessageToAllDMs("Assassin in"+GetName(GetArea(oPC))+" is now toggled off!");
}
}
//End of PRI Mod
}
if(iFOODSYSTEM && iFail==0 && nHasFood==1)
{
if(!DidPCSetUpCamp(oPC) && GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
if(RestrictPartyRestOnLimitRestHealAndArmorPen(oPC)) return;
iCount = iRESTBREAK;
DelayCommand(1.5, SetRestTime(oPC, iCount));
}
}else if(!iFOODSYSTEM && GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED){
iCount = iRESTBREAK;
DelayCommand(1.5, SetRestTime(oPC, iCount));
}
int nLastRestType=GetLastRestEventType();
if(nLastRestType == REST_EVENTTYPE_REST_FINISHED || nLastRestType == REST_EVENTTYPE_REST_CANCELLED)
{
RemoveSleepBlindness(oPC);
if (iBedroll && iBedUse == 0 && nBARRACK==0 && GetLocalInt(oMod,"LostBedRoll"+sID)==1)
{
ReplaceBedroll(oPC);
DeleteLocalInt(oMod,"LostBedRoll"+sID);
}
//set the variables for the current time to mark the pc as resting
SetLocalInt(oPC,"RESTING",0);
DeleteLocalInt(oPC, "REST");
if(nLastRestType == REST_EVENTTYPE_REST_FINISHED)
{
if(iFOODSYSTEM && !iBedUse) GetFoodEaten(oPC);
if(iFOODSYSTEM && iBedUse) ApplyInnRest(oPC, iBedUse);
// Vampire heal
if(!iFOODSYSTEM) ApplyInnRest(oPC, 4);
iCount = iRESTBREAK;
DelayCommand(1.5, SetRestTime(oPC, iCount));
//SetLocalInt(oMod, "SecSB"+sID, nSSB);
// if(nBARRACK==0) ApplyArmorRestPenalty(oPC);
if(nSRace > 0) SetSubRaceAbilites(oPC, nSRace);
if(!GetIsDM(oPC))
SetLocalInt(oMod, ("LastRest" + sID), nSSB);
effect eConDec = ExtraordinaryEffect(EffectAbilityDecrease(ABILITY_CONSTITUTION,GetLocalInt(oMod,"CONPEN"+sID)));
DelayCommand(1.0, DeleteLocalInt(oMod,"HPStartRest" + sID));
}
if(nLastRestType == REST_EVENTTYPE_REST_CANCELLED)
{
SetSubRaceAbilites(oPC, nSRace);
ResetRestingHP(oPC);
}
DeleteLocalInt(oPC, "BARRACKS");
DeleteLocalInt(oPC, "RSA_BedUse");
DeleteLocalInt(oPC, "RSA_HasRoom");
}
}
Here's the other file:
// Food and Rest Functions
//void main() {}
//::////////////////////////////////////////////
//:: Creating Food follow this model
//:: Food_<type><bonus>
//:: i.e. Food_NORM2
//:: TYPES: POOR, NORM, RICH, MAGI
//:: BONUSES: 0, 1
//::////////////////////////////////////////////
#include "ad_text_rest"
#include "hc_i0_plyrstate"
#include "hc_i0_timecheck"
int HasPCEaten(object oPC);
void EatFood(object oPC, object oFood);
void ClearFood(object oPC);
void GetFoodEaten(object oPC);
void ApplyFoodEffects(object oPC, int nHeal, int nBonus);
// Call on Rest Cancel and player enter.
void ResetRestingHP(object oPC);
object GetPCFamiliar(object oPC);
void pet_rest_dam(object oFam, object oPC, int nAny=0);
int RestrictPartyRestOnLimitRestHealAndArmorPen(object oPC);
void SavePreRestFamiliarHP(object oPC, object oFam);
int IsTooSoonToRest(object oPC, int iMinRest, int nSSB, int nConv);
int IsPCTooWeakToRest(object oPC);
int DidPCSetUpCamp(object oPC);
void ApplyInnRest(object oPC, int nHeal);
// Remove all player spells
void RemoveSpells(object oPC);
// Cook some food
void CookFood(string sTag, object oPC);
//:: FUNCTIONS :://
void CookFood(string sTag, object oPC)
{
if(FindSubString(sTag, "FISH")!= -1)
CreateItemOnObject("fish", oPC);
else if(FindSubString(sTag, "BAT")!= -1)
CreateItemOnObject("food_bat", oPC);
else if(FindSubString(sTag, "BADGER")!= -1)
CreateItemOnObject("food_badger", oPC);
else if(FindSubString(sTag, "BEAR")!= -1)
CreateItemOnObject("food_bear", oPC);
else if(FindSubString(sTag, "VENISON")!= -1)
CreateItemOnObject("food_deer", oPC);
else if(FindSubString(sTag, "FELINE")!= -1)
CreateItemOnObject("food_feline", oPC);
else if(FindSubString(sTag, "WOLF")!= -1)
CreateItemOnObject("food_wolf", oPC);
else
CreateItemOnObject("cookedfood", oPC);
}
void ApplyInnRest(object oPC, int nHeal)
{
object oMod = GetModule();
int nHD=GetHitDice(oPC)*nHeal;
int nSHP=GetLocalInt(oMod,("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
int nDam;
int nLTC;
//Double healing rate if long term care was applied successfully.
if(GetLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC)) == 2)
nLTC=GetHitDice(oPC)*2;
else
nLTC=0;
if(GetCurrentHitPoints() > (nSHP+nHD+nLTC))
{
nDam=(GetCurrentHitPoints() - (nSHP+nHD+nLTC));
effect eDamage = EffectDamage(nDam);
ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);
}
DeleteLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC));
object oFam = GetPCFamiliar(oPC);
if(GetIsObjectValid(oFam))
DelayCommand(1.0,pet_rest_dam(oFam, oPC));
}
int DidPCSetUpCamp(object oPC)
{
int nCamp = 1;
// Ranger or Druid go no further
if(GetLevelByClass(CLASS_TYPE_RANGER, oPC)>0 || GetLevelByClass(CLASS_TYPE_DRUID, oPC)>0)
return nCamp;
int nCreatureChance = 79;
object oCamp = GetNearestObjectByTag("hc_campfire", oPC);
if(!GetIsObjectValid(oCamp))
nCamp = 0;
string sID = GetName(oPC) + GetPCPublicCDKey(oPC);
if(GetIsObjectValid(oCamp) && GetDistanceBetween(oPC, oCamp) > 6.0)
{
if(d100() <= nCreatureChance)
{
FloatingTextStringOnCreature(NOCAMP, oPC, FALSE);
AssignCommand(oPC, ClearAllActions());
SetLocalInt(GetModule(), ("LastRest" + sID), SecondsSinceBegin());
}
nCamp = 0;
}
return nCamp;
}
int HasPCEaten(object oPC)
{
int nResult = 0;
if(GetLocalInt(oPC,"FOODHEAL")>0)
{
nResult = 1;
}else{
FloatingTextStringOnCreature(TOOHUNGRY, oPC, FALSE);
AssignCommand( oPC, ClearAllActions());
}
return nResult;
}
void EatFood(object oPC, object oFood)
{
string sTag = GetTag(oFood);
string sType = GetStringRight(GetStringLeft(sTag,9),4);
int nNum = GetStringLength(sTag)-9;
int nBonus = StringToInt(GetStringRight(sTag, nNum));
int nHeal;
if(sType == "POOR") nHeal = 1;
if(sType == "NORM") nHeal = 2;
if(sType == "RICH") nHeal = 3;
if(sType == "MAGI") nHeal = 5;
SetLocalInt(oPC, "FOODHEAL", nHeal);
SetLocalInt(oPC, "FOODBONUS", nBonus);
// Effects valid for 8 hours OR until Rest
DelayCommand(HoursToSeconds(, DeleteLocalInt(oPC, "FOODHEAL"));
DelayCommand(HoursToSeconds(, DeleteLocalInt(oPC, "FOODBONUS"));
AssignCommand(oPC, ActionPlayAnimation(ANIMATION_FIREFORGET_SALUTE, 1.0));
DelayCommand(0.8, AssignCommand(oPC, ActionSpeakString(MUNCHFOOD)));
SendMessageToPC(oPC, EATFOOD + " [" + GetName(oFood) + "]");
DestroyObject(oFood);
}
void ClearFood(object oPC)
{
DeleteLocalInt(oPC, "FOODHEAL");
DeleteLocalInt(oPC, "FOODBONUS");
}
void GetFoodEaten(object oPC)
{
int nHeal = GetLocalInt(oPC, "FOODHEAL");
int nBonus = GetLocalInt(oPC, "FOODBONUS");
ApplyFoodEffects(oPC, nHeal, nBonus);
ClearFood(oPC);
}
void ApplyFoodEffects(object oPC, int nHeal, int nBonus)
{
object oMod = GetModule();
int nHD=GetHitDice(oPC)*nHeal;
SpeakString(IntToString(nHD));
int nSHP=GetLocalInt(oMod,("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
SpeakString(IntToString(nSHP));
int nDam;
int nLTC;
//Double healing rate if long term care was applied successfully.
if(GetLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC)) == 2)
nLTC=GetHitDice(oPC)*2;
else
nLTC=0;
if(GetCurrentHitPoints(oPC) > (nSHP+nHD+nLTC))
{
nDam = GetCurrentHitPoints(oPC) - (nSHP+nHD+nLTC);
effect eDamage = EffectDamage(nDam);
ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oPC);
}
DeleteLocalInt(oMod, "LONGTERMCARE"+GetName(oPC)+GetPCPublicCDKey(oPC));
object oFam = GetPCFamiliar(oPC);
if(GetIsObjectValid(oFam))
DelayCommand(1.0,pet_rest_dam(oFam, oPC));
// Do bonuses
if(nBonus == 0) return;
int nModify = d4() + 1;
float fDuration = RoundsToSeconds(d10());
effect eVis = EffectVisualEffect(VFX_IMP_IMPROVE_ABILITY_SCORE);
effect eBonus, eLink;
if(nBonus ==1){ // Poison Food
SendMessageToPC(oPC, "You start to feel sick.");
SendMessageToAllDMs(GetName(oPC)+" ate some poisoned food!");
effect ePoison = EffectPoison(POISON_TINY_SPIDER_VENOM);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, ePoison, oPC);
}
if(nBonus == 2){ // Hero's Feast
effect eRemove = GetFirstEffect(oPC);
while(GetIsEffectValid(eRemove))
{
if(GetEffectType(eRemove)==EFFECT_TYPE_DISEASE||GetEffectType(eRemove)==EFFECT_TYPE_POISON
||GetEffectType(eRemove)==EFFECT_TYPE_NEGATIVELEVEL)
{
RemoveEffect(oPC, eRemove);
}
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(d4()+4),oPC);
}
}
if(nBonus==3){ // Badger
eBonus = EffectAbilityIncrease(ABILITY_STRENGTH,nModify);
eLink = EffectLinkEffects(eBonus, eVis);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, fDuration);
}
if(nBonus==4){ // Feline
eBonus = EffectAbilityIncrease(ABILITY_DEXTERITY,nModify);
eLink = EffectLinkEffects(eBonus, eVis);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, fDuration);
}
if(nBonus==5){ // Wolf
eBonus = EffectMovementSpeedIncrease(30);
eLink = EffectLinkEffects(eBonus, eVis);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oPC, fDuration);
}
DeleteLocalInt(oMod,("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
}
void ResetRestingHP(object oPC)
{
int nSHP=GetLocalInt(GetModule(),("HPStartRest"+GetName(oPC)+GetPCPublicCDKey(oPC)));
if(nSHP == 0 || nSHP>=GetCurrentHitPoints(oPC)) return;
int nRestHP = GetCurrentHitPoints(oPC);
int nDam = nRestHP-nSHP;
effect eDamage = EffectDamage(nDam);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC);
RemoveSpells(oPC);
SendMessageToAllDMs("WARNING: "+GetName(oPC)+" may be trying to cancel rest to re-gain spells.");
object oFam = GetPCFamiliar(oPC);
if(GetIsObjectValid(oFam))
DelayCommand(1.0,pet_rest_dam(oFam, oPC));
}
object GetPCFamiliar(object oPC)
{
object oFam=GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oPC);
if(!GetIsObjectValid(oFam))
oFam=GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oPC);
return oFam;
}
void pet_rest_dam(object oFam, object oPC, int nAny=0)
{
int nSHP=GetLocalInt(oPC,"FamiliarHealth");
int nHD=GetHitDice(oPC);
int nRestHP=GetCurrentHitPoints(oFam);
if((nRestHP > nSHP+nHD) || nAny) {
int nDam=(nRestHP-(nSHP+nHD));
if(nAny) nDam=nRestHP-nSHP;
effect eDamage = EffectDamage(nDam,
DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_NORMAL);
ApplyEffectToObject( DURATION_TYPE_INSTANT, eDamage, oFam);
}
}
int RestrictPartyRestOnLimitRestHealAndArmorPen(object oPC)
{
object oPM=GetFirstFactionMember(oPC);
while(GetIsObjectValid(oPM))
{
if(GetLocalInt(oPM,"RESTING") && oPM != oPC)
{
AssignCommand(oPC, ClearAllActions());
SendMessageToPC(oPC,"You cannot rest while another party member is resting, sleep in shifts.");
return 1;
}
oPM=GetNextFactionMember(oPC);
}
return 0;
}
void SavePreRestFamiliarHP(object oPC, object oFam)
{
if(GetIsObjectValid(oFam) && !GetLocalInt(oPC,"RESTING"))
SetLocalInt(oPC,"FamiliarHealth",GetCurrentHitPoints(oFam));
}
int IsTooSoonToRest(object oPC, int iMinRest, int nSSB, int nConv)
{
int nNotOkToRest = 0;
string sRestedText = GetName(oPC) + NOTTIRED;
//First get the time last rested and the current time.
int iLastRest = GetLocalInt(GetModule(), ("LastRest" + GetName(oPC) + GetPCPublicCDKey(oPC)));
if (iLastRest && ((iLastRest+iMinRest) > nSSB))
{
AssignCommand(oPC, ClearAllActions());
sRestedText+=" Try again in ";
if(((iMinRest+iLastRest)-nSSB)/nConv > 0)
sRestedText+=IntToString(((iMinRest+iLastRest)-nSSB)/nConv) + " hours.";
else
sRestedText+=IntToString(((iMinRest+iLastRest)-nSSB)/6)+" minutes.";
FloatingTextStringOnCreature(sRestedText,oPC,FALSE);
nNotOkToRest = 1;
}
return nNotOkToRest;
}
int IsPCTooWeakToRest(object oPC)
{
int nNotOkToRest = 0;
if(GPS(oPC)==PS_RECOVERY)
{
FloatingTextStringOnCreature(NOTWELL, oPC, FALSE);
AssignCommand( oPC, ClearAllActions());
nNotOkToRest = 1;
}
return nNotOkToRest;
}
void RemoveSpells(object oPC)
{
if(!GetIsPC(oPC)) return;
int nSpell, nID, nLoop, nFeat;
for(nID=0; nID < 498; nID++)
{
nSpell = GetHasSpell(nID, oPC);
if(nSpell > 0)
{
for(nLoop=0; nLoop < nSpell; nLoop++)
{
// Only removes 1 use at a time
DecrementRemainingSpellUses(oPC, nID);
}
}
}
for(nID=0; nID < 444; nID++)
{
nFeat = GetHasFeat(nID, oPC);
if(nFeat > 0)
{
for(nLoop=0; nLoop < nFeat; nLoop++)
{
// Only removes 1 use at a time
DecrementRemainingFeatUses(oPC, nID);
}
}
}
}
Sorry for so much spam in this thread, the scripts are pretty big on this module.