#include "inc_misc_tools"
void main()
    {
    object oPC = GetLastPCRested();
    if (GetLocalInt(GetArea(oPC),"Town"))
        return;// Resting in town is always allowed.
    object oHench = GetAssociate(ASSOCIATE_TYPE_HENCHMAN ,oPC);
    object oItem;
    if (!GetIsPC(oPC) || GetIsDM(oPC))
        return;
    int iType = GetLastRestEventType();
    int iRest = GetLocalInt(oPC,"Rest");
    int iFood = GetLocalInt(oPC,"Food");

    if (iType == REST_EVENTTYPE_REST_STARTED)
        {
        if (!iRest)
            {
            FloatingTextStringOnCreature("You have used your allowed rest.",oPC,FALSE);
            AssignCommand(oPC,ClearAllActions());
            return;
            }
        else if (GetHasFood(OBJECT_SELF)) // Must eat food to rest.
            {
            FloatingTextStringOnCreature("Hungry.",oPC,FALSE);
            AssignCommand(oPC,ClearAllActions());
            return;
            }
        DelayCommand(1.0,ExecuteScript("rdg_wand_monster",oPC));
        }
    else if (iType == REST_EVENTTYPE_REST_FINISHED
          || iType == REST_EVENTTYPE_REST_CANCELLED)
        {
        SetPanelButtonFlash(oPC,PANEL_BUTTON_REST,TRUE);
        DeleteLocalInt(oPC,"Rest");
        if (GetLocalInt(oPC,"Food"))
            DeleteLocalInt(oPC,"Food");
        else if (GetIsObjectValid(GetItemPossessedBy(oPC,"food")))
            DestroyObject(GetItemPossessedBy(oPC,"food"));
        }
    }
