Post
by slabar » Fri Feb 14, 2003 12:53 am
Silk,
I took it right out of the aps_include file and placed it into my resting script. Here's everything I'm using.
int GetHourTimeZero(int iYear = 99999, int iMonth = 99, int iDay = 99, int iHour = 99)
{
// Check if a specific Date/Time is forwarded to the function.
// If no or invalid values are forwarded to the function, the current Date/Time will be used
if (iYear > 30000)
iYear = GetCalendarYear();
if (iMonth > 12)
iMonth = GetCalendarMonth();
if (iDay > 28)
iDay = GetCalendarDay();
if (iHour > 23)
iHour = GetTimeHour();
//Calculate and return the "HourTimeZero"-TimeIndex
int iHourTimeZero = (iYear)*12*28*24 + (iMonth-1)*28*24 + (iDay-1)*24 + iHour;
return iHourTimeZero;
}
//:://////////
//:: Main Function
//:: Copyright (c) 2002 Brotherhood of Zock
//:://////////
/*
The Main Function of the resting script.
*/
//:://////////
//:: Created By: Timo "Lord Gsox" Bischoff (NWN Nick: Kihon)
//:: Created On: August 04, 2002
//:://////////
// The main function placed in the onRest event
#include "aps_include"
void main()
{
// This Script only affects Player Characters. Familiars, summoned creatures and probably henchmen WILL rest!
object oPC = GetLastPCRested();
// Get location of PC
location lLoc = GetLocation (oPC);
// The ammount of hours a player must wait between Rests (Default = 8 hours)
int iRestDelay = 8;
// The radius around the players that must be free of hostiles in order to rest.
int iHostileRange = 30;
// iHostileRange = 0: Hostile Check disabled
// iHostileRange = x; Radius of Hostile Check (x meters)
// This can be abused as some sort of "monster radar".
// ---------- Rest Event started ----------
if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
// Check if since the last rest more than <iRestDelay> hours have passed.
if (GetHourTimeZero() < GetPersistentInt (oPC, "i_TI_LastRest") + iRestDelay) // i_TI_LastRest is 0 when the player enters the module
{
// Resting IS NOT allowed
AssignCommand (oPC, ClearAllActions()); // Prevent Resting
SetPersistentLocation(oPC, "Last_Location", lLoc, 0);
SendMessageToPC (oPC, "You must wait " + IntToString (iRestDelay - (GetHourTimeZero() - GetPersistentInt (oPC, "i_TI_LastRest"))) + " hour(s) before resting again.");
}
else // Resting IS possible
{
object oCreature = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY);
if (iHostileRange == 0 || (iHostileRange != 0 && GetDistanceToObject(oCreature) <= IntToFloat(iHostileRange)))
{
// If Hostile Check disabled or no Hostiles within Hostile Radius: Initiate Resting
// Place a static bedroll under the player
object oRestbedroll = CreateObject (OBJECT_TYPE_PLACEABLE, "plc_bedrolls", GetLocation (oPC), FALSE);
// Temporary "global" variable. Gets deleted after deletion of the bedroll.
SetLocalObject (oPC, "o_PL_Bedrollrest", oRestbedroll);
// Set Last Rest Time
SetPersistentInt (oPC, "i_TI_LastRest", GetHourTimeZero());
SetPersistentLocation(oPC, "Last_Location", lLoc, 0);
}
else
{
// Resting IS NOT allowed
AssignCommand (oPC, ClearAllActions()); // Prevent Resting
SetPersistentLocation(oPC, "Last_Location", lLoc, 0);
SendMessageToPC (oPC, "You can't rest. Hostile creatures are nearby");
}
}
}
// ---------- Rest Event finished or aborted ----------
if ((GetLastRestEventType() == REST_EVENTTYPE_REST_FINISHED || GetLastRestEventType() == REST_EVENTTYPE_REST_CANCELLED) && GetIsObjectValid(GetLocalObject (oPC, "o_PL_Bedrollrest")))
{
// If a bedroll was placed under the player: Delete it
DestroyObject (GetLocalObject (oPC, "o_PL_Bedrollrest"), 0.0f);
DeleteLocalObject (oPC, "o_PL_Bedrollrest");
}
}