Rest system glitched HELP

Hello i am using this rest system and my issue is that I created an inn ((Set to unrestable in properties of area)) but I made my own trigger for allowing resting there and it doesnt work at all but everything compiles fine… Here is the rest system of module:

//::///////////////////////////////////////////////
//:: Resting Script
//:: boz_o1_resting
//:: Copyright © 2002 Brotherhood of Zock
//:://////////////////////////////////////////////
/*
This script allows the players to rest after a specified amount of hours
has passed and only (optional) if they are in possession of a “Bedroll” or use a local
“placeable” item that allows them to rest (and sets the LocalInt “iRestAllowed” to 1).
/
//:://////////////////////////////////////////////
//:: Created By: Kihon
//:: Created On: July 8, 2002
//:://////////////////////////////////////////////
// Counting the actual date from Year0 Month0 Day0 Hour0 in hours
int GetHourTimeZero()
{
int iHourTimeZero;
iHourTimeZero = (GetCalendarYear()-1)1228
24 + (GetCalendarMonth()-1)2824 + (GetCalendarDay()-1)*24 + GetTimeHour();
return iHourTimeZero;
}

// The main function placed in the onRest event
void main()
{
object oPlayer = GetLastPCRested();
int iRestDelay = 8; //The ammount of hours a player must wait between Rests
int iBedrollRequired = 1; // 0=No requirements for resting
// 1=A “Bedroll” is needed in order to rest.
// Optional may a “Rest-allowing-placable” be used,
// that sets the value of the local “iRestAllowed”
// variable on the player to “1”.

if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
{
// Check if the Rest Dely is over.
if (GetHourTimeZero() < GetLocalInt (oPlayer, “iNextRestHourTimeZero”))
{
AssignCommand (oPlayer, ClearAllActions()); // Prevent Resting
SendMessageToPC (oPlayer, “You must wait " + IntToString (GetLocalInt (oPlayer, “iNextRestHourTimeZero”)-GetHourTimeZero()) + " hour(s) before resting again.”);
}
else // Resting possible.
{
// Resting allowed if No Bedroll required or Player has a Bedroll or a Rest-allowing-placeable set the local “iRestAllowed” variable to 1
if (iBedrollRequired == 0 || iBedrollRequired == 1 && (GetIsObjectValid (GetItemPossessedBy (oPlayer,“Bedroll”)) || GetLocalInt (oPlayer,“iRestAllowed”) == 1))
{
SetLocalInt (oPlayer, “iRestAllowed”, 0);
SetLocalInt (oPlayer, “iNextRestHourTimeZero”, GetHourTimeZero()+iRestDelay);
}
else // Resting not allowed
{
AssignCommand (oPlayer, ClearAllActions()); // Prevent Resting
SendMessageToPC (oPlayer, “No Bed(roll) - No Rest”);
}
}
}
}

Now here is my generic trigger that’s supposed to allow resting, same thing for exiting but changes the int to 0:

OnEnter:
void main()
{
object oPC = GetEnteringObject();
if(GetIsPC(oPC))
SetLocalInt(oPC, “iRestAllowed”, 1);
}

Onexit is same thing but 0 HELP PLEASE

I even tried for ONUSED of a bed item but it still did same error: Cannot rest in this area

it doesnt work this way, i haven’t check the code but as far as i know its not possible to do this the way you want

instead you need to leave area with rest allowed and use trigger that disallows rest (which is not that pretty as the rest starts and then is canceled).

The only alternative I can see is nwnx. NWNX_Patch has option to make area rest-able, however to make it work when players are in that area players would have to run NWNCX_Patch. It would also be possible using nwnx to fire OnRest event before the rest actually starts however I am not aware of any plugin with that kind of functionality.

I just copied your code to take a look and immediately discovered a bug before I had even made it readable by indenting it properly. You have an open block quote /* but your close block quote is malformed / which results in the whole of that script being commented out. So you probably want fix that pronto.

Will take a look at the rest of it when I can.

TR

1 Like

Another bug is that you forgot to multiply when you wrote -

	iHourTimeZero = (GetCalendarYear()-1)122824 + (GetCalendarMonth()-1)2824 + (GetCalendarDay()-1)*24 + GetTimeHour();

instead of

	iHourTimeZero = (GetCalendarYear()-1) * 122824 + (GetCalendarMonth()-1) * 2824 + (GetCalendarDay()-1) * 24 + GetTimeHour();

TR

1 Like

Another place that will not work as you expect is the line -

if (iBedrollRequired == 0 || iBedrollRequired == 1 && (GetIsObjectValid (GetItemPossessedBy (oPlayer,“Bedroll”)) || GetLocalInt (oPlayer,“iRestAllowed”) == 1))

as written the section - iBedrollRequired == 0 || iBedrollRequired == 1 - is redundant because it says in effect that it doesn’t matter whether a bedroll is required or not. In order to make it work as I think you intended you need another level of parenthesis which makes that line look like -

if (iBedrollRequired == 0 || (iBedrollRequired == 1 && (GetIsObjectValid (GetItemPossessedBy (oPlayer,“Bedroll”)) || GetLocalInt (oPlayer,“iRestAllowed”) == 1)))

Correcting those 3 errors gives you this code -

//::///////////////////////////////////////////////
//:: Resting Script
//:: boz_o1_resting
//:: Copyright © 2002 Brotherhood of Zock
//:://////////////////////////////////////////////
/*
This script allows the players to rest after a specified amount of hours
has passed and only (optional) if they are in possession of a "Bedroll" or use a local
"placeable" item that allows them to rest (and sets the LocalInt "iRestAllowed" to 1).
*/

//:://////////////////////////////////////////////
//:: Created By: Kihon
//:: Created On: July 8, 2002
//:://////////////////////////////////////////////
// Counting the actual date from Year0 Month0 Day0 Hour0 in hours
int GetHourTimeZero()
{
	int iHourTimeZero;
	iHourTimeZero = (GetCalendarYear()-1) * 122824 + (GetCalendarMonth()-1) * 2824 + (GetCalendarDay()-1) * 24 + GetTimeHour();
	return iHourTimeZero;
}

// The main function placed in the onRest event
void main()
{
	object oPlayer = GetLastPCRested();
	int iRestDelay = 8; //The ammount of hours a player must wait between Rests
	int iBedrollRequired = 1; // 0=No requirements for resting
	
	// 1=A "Bedroll" is needed in order to rest.
	// Optional may a "Rest-allowing-placable" be used,
	// that sets the value of the local "iRestAllowed"
	// variable on the player to "1".

	if (GetLastRestEventType() == REST_EVENTTYPE_REST_STARTED)
	{
		// Check if the Rest Dely is over.
		if (GetHourTimeZero() < GetLocalInt (oPlayer, "iNextRestHourTimeZero"))
		{
			AssignCommand (oPlayer, ClearAllActions()); // Prevent Resting
			SendMessageToPC (oPlayer, "You must wait " + IntToString (GetLocalInt (oPlayer, "iNextRestHourTimeZero")-GetHourTimeZero()) + " hour(s) before resting again.");
		}
		else // Resting possible.
		{
			// Resting allowed if No Bedroll required or Player has a Bedroll or a Rest-allowing-placeable set the local "iRestAllowed" variable to 1
			if (iBedrollRequired == 0 || (iBedrollRequired == 1 && (GetIsObjectValid (GetItemPossessedBy (oPlayer,"Bedroll")) || GetLocalInt (oPlayer,"iRestAllowed") == 1)))
			{
				SetLocalInt (oPlayer, "iRestAllowed", 0);
				SetLocalInt (oPlayer, "iNextRestHourTimeZero", GetHourTimeZero()+iRestDelay);
			}
			else // Resting not allowed
			{
				AssignCommand (oPlayer, ClearAllActions()); // Prevent Resting
				SendMessageToPC (oPlayer, "No Bed(roll) - No Rest");
			}
		}
	}
}

There doesn’t (at first glance anyway) look to be anything wrong with the Area OnEnter part anyway

OnEnter:

void main()
{
	object oPC = GetEnteringObject();

	if(GetIsPC(oPC))
		SetLocalInt(oPC, "iRestAllowed", 1);
}

Whether or not this now works as advertised is another matter given those bugs I’ve squashed. You’ll just have to try it.

TR

2 Likes

I have just been told that the fixed version does actually work. While I didn’t have time a friend made a little module and tested it.

Here are three links to threads on here that you will probably find useful.

A Short Tour of These Forums - Shows you how to get the most out of these forums including how to change your avatar and how to make any code you post “prettier”.

The Starting Point - module building tutorials for beginners - and where to find them - loads of links to different tutorials including various scripting tutorials.

And - Books & Things - Lots of links to various useful things that need at worst minimal scripting.

TR

1 Like

Fixed your code needed " " for variables testing now :wink:

I think I know what it was (as in I think I’ve fixed it). Because the original code wasn’t formatted as code when it was pasted into the thread, Discourse must have auto-corrected it to the “prettier” unicode variant. As I didn’t look at the quotes when I copied, corrected and pasted the code, these wrong quotes were still there even after I turned on code formatting before pasting. Look at the code as it was originally posted and you’ll see it has the wrong quotation marks. I have gone through and corrected all 34 wrong quote characters (copied into notepad++, search and replace all). Try it now.

TR

Did some experimenting and confirmed to my satisfaction that what I described in my previous post is in fact true. So I strongly urge you to look at the “A Short Tour of These Forums” thread linked to above.

TR

1 Like