int GetTime()
{
  int nYear = GetCalendarYear();
  int nMonth = GetCalendarMonth();
  int nDay = GetCalendarDay();
  int nHour = GetTimeHour();
  int nTime = nYear*12*28*24 + (nMonth-1)*28*24 + (nDay-1)*24 + nHour;
  return nTime;
}

void main()
{
// Set default rest delay to 8 hours
  int nRestDelay = 8;

  object oPC = GetLastPCRested();
  int nTimeSinceRest = GetTime() - GetLocalInt(oPC,"LastRest");

  if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
  {
    // Check if enough time has gone by since last rest
    if (nTimeSinceRest < nRestDelay)
    {
      AssignCommand(oPC,ClearAllActions());
      if (nRestDelay - nTimeSinceRest == 1)
        FloatingTextStringOnCreature("You still feel rested but in another " +
          "1 hour you can rest again.",oPC);
      else
        FloatingTextStringOnCreature("You still feel rested but in another " +
          IntToString(nRestDelay - nTimeSinceRest) +
          " hours you can rest again.",oPC);
    }
    else
    {
        // Rest and set time of last rest to current time
        SetLocalInt(oPC,"LastRest",GetTime());
    }
  }
}
