1) Script Name: Resting Script (Updated
"cleaned" code)
2) What it does: It allows resting only if a specified ammount of time
has passed and (now optional) only if the players are in possesion of a
"Bedroll" item or use a placeable that allows them to rest (a bed, a
bedroll...).
3) Notes: Just a small update. No changes to the functioning of the
script itself.
A "Bedroll" item is any custom item tagged "Bedroll". A placeable item
requires another script that sets the LocalInt "iRestAllowed" to 1
onUsed.
Delay Time between rest and the requirement of a "Bedroll" item can be
modified by setting a variable.
4) The Main Script:
Placed in the onResting event in the Module properties.
NWScript:
int GetHourTimeZero()
{
int iHourTimeZero;
iHourTimeZero = (GetCalendarYear()-1)*12*28*24 + (GetCalendarMonth()-1)*28*24 + (GetCalendarDay()-1)*24 + GetTimeHour();
return iHourTimeZero;
}
void main()
{
object oPlayer = GetLastPCRested();
int iRestDelay = 8;
int iBedrollRequired = 1;
if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
if (GetHourTimeZero() < GetLocalInt (oPlayer, "iNextRestHourTimeZero"))
{
AssignCommand (oPlayer, ClearAllActions());
SendMessageToPC (oPlayer, "You must wait " + IntToString (GetLocalInt (oPlayer, "iNextRestHourTimeZero")-GetHourTimeZero()) + " hour(s) before resting again.");
}
else
{
if (iBedrollRequired == 0 || iBedrollRequired == 1 && (GetIsObjectValid (GetItemPossessedBy (oPlayer,"Bedroll")) || GetLocalInt (oPlayer,"iRestAllowed") == 1))
{
SetLocalInt (oPlayer, "iRestAllowed", 0);
SetLocalInt (oPlayer, "iNextRestHourTimeZero", GetHourTimeZero()+iRestDelay);
}
else
{
AssignCommand (oPlayer, ClearAllActions());
SendMessageToPC (oPlayer, "No Bed(roll) - No Rest");
}
}
}
}
The script placed in the onUsed event of the "Rest-allowing- placable":
NWScript:
void main()
{
object oLastUser = GetLastUsedBy();
if (GetIsPC (oLastUser) && GetIsObjectValid (oLastUser))
{
SetLocalInt (oLastUser, "iRestAllowed", 1);
AssignCommand (oLastUser, ActionRest());
}
}
|