Rent A Room Tutorial

How to make an NPC Rent you a bed for the night.

PreparationsEdit

Preparing the roomEdit

We Start with the door;
First set Ownership to your NPC's BaseID.
Then Lock it. Not with a key, just choose hard or something.
Add a Reference ID, Example: "(YourInnName)Rentdoor" And check the Persistent Reference box.
Then set the same Ownership to the bed and add a Refrence ID, Example: "(YourInnName)Rentbed". Then check the Persistent Reference box.

The NPCEdit

The NPC needs a script to be able to rent you the bed.

Add a Name:

Scriptname Publican_(YourInnName)(YourNPCName)

Then add the variables;

short rent         ;if you have rent the room or not
short rentday      ;make sure it's the same day
short cleanup      ;For the Resetting
short setup        ;Check if the first part has been run

Write the rest of the Script:

begin gamemode

if ( rent == 1 )                        ;If you have rented the room
	
 if ( setup == 0 )                      ;If this hasn't been done before
  set rentday to GameDaysPassed         ;Saves the day of the rental 
  set setup to 1                        ;We don't want this to happen again
  (YourDoorRef).unlock                  ;Unlock the door
  (YourBedRef).SetOwnership             ;Makes it legal to sleep in the bed

 else                                   ;If we have already done that
	
  if ( GameDaysPassed != rentday )             ;If it is a new day
   set cleanup to 1                     ;Makes the reset ready
  endif
 endif

 if Player.GetinCell (YourInnCell) == 0 ;If the player is outside the inn
  if ( Cleanup == 1 )                   ;If the reset Is ready
   set Cleanup to 2                     ;Start the reset
  endif
 endif



 if ( Cleanup == 2 )                    ;If the reset should start


;Resets The Variables
	
  set rent to 0                         
  set setup to 0                        
  set rentday to 0
  set cleanup to 0


  (YourDoorRef).SetOpenState 0         ;Close the door
  (YourDoorRef).lock 30                ;Lock the door
  (YourBedRef).SetOwnership (NpcID)    ;Make it illegal to sleep in the bed
 endif
endif

End

Change The Class to MerchPublican.
Be sure to save the script as an Object, not a Quest.
If you want you can add AI so the npc can sell beer And food (see point 4, 4.2 and 5.2 in My First Shop

The DialoguesEdit

Now the last thing: The dialogues.

Open the quest window, select the BedRental quest and click on the Topics tab.
Select the Bed topic.
In the response list you add a new response with a text like: "Hope it suits you".
Then add the audio, if you don't want to record your own voice you can unpack some voices from oblivion.

Then add conditions; First add one with:

Target: No
Fuction Name:GetInCell
Function Info: (YourInnCell)
Comp:==
Value:1
AND

This makes it so you can't rent a bed outside the inn
If your NPC doesn't move away from the inn you can skip the first one.

Add a new Condition:
This condition makes sure this dialogue only works for our NPC.

Target: No
Fuction Name:GetIsId
Function Info: (YourInnNPC)
Comp:==
Value:1
AND

Add the last Condition:
He only says this dialogue if you have rented the bed

Target: No
Fuction Name:GetScripVariable
Function Info: (YourInnNPC)Rent
Comp:==
Value:1
AND

Go back to the Response list and add a new response.
Write something like this: "I've got a room, and a cheap one at that. You looking for one?".
Add audio.
Add the same Condition as last time, but change the value of the GetSctiptVariable condition to 0.
We want him to say this if you haven't rented the bed.
Then in the Choices list to the right, you add: BedNo and BedYes.

The next part is optional, you only need to do this if you want to make a special response if you choose no.

Select BedNo in the list to the left.
Add a new response with a text like this: "Then stop wasting my time.".
Add audio.
Add a Conditon; The same GetIsId Condition as before.

If you skipped the last part, continue here.

Select the BedYes in the left menu.
Make a new response with text like this: "Right then. Head up the stairs, and it's the first door on your right. Remember, I didn't say it was clean. I said it was cheap.".
Add audio.

In the Result Script box you write this:

player.removeitem Gold001(Priceoftheroom) ;Remove gold from the player           
set (YourNPCRef).rent to 1               ;You have now rented the room

Then add the same GetIsId as always.

Add this condition:
It makes the NPC say this only if you have enough gold.

Target: Yes
Fuction Name:GetItemCount
Function Info:Gold001
Comp:>=
Value: (Priceoftheroom)
AND

Then add a new response with text like this: "Not even (Priceoftheroom) gold to your name? And here I thought I had it bad. Sorry, but I need you to pay before I can let you stay here.".
Add Audio.
Add the same conditions as the last one, but change the Comp in the Getitemcont condition to <. So he says this if you don't have (Priceoftheroom) gold.

And now you're done.