Page 1 of 1

Turning *off* the ability to rest

Posted: Wed Jan 28, 2015 12:30 am
by David Ward
Is there a way to turn off the ability for the player to rest their party? If the party is going through a sort of gauntlet of monsters/traps etc., they can just stop and rest mid-way through the gauntlet unless a monster is close enough that it wakes them up or prevents them from sleeping. But is there a way to prevent resting another way?

Re: Turning *off* the ability to rest

Posted: Wed Jan 28, 2015 12:31 am
by David Ward
I found this, but it is for grimrock 1??

viewtopic.php?f=14&t=4707

Re: Turning *off* the ability to rest

Posted: Wed Jan 28, 2015 1:02 am
by minmay
return false from PartyComponent.onRest() to prevent resting

Re: Turning *off* the ability to rest

Posted: Wed Jan 28, 2015 1:39 am
by Isaac
Depending on how you want it, a timer run script can check party.party:isResting() for a true/false answer, or you can add the aforementioned party hook that triggers onRest(). Returning false from the hook simply breaks resting, with no explanation; which is great if that's what you want, but probably frustrating to the player, unless you've given them some warning that they will be unable to rest.

The timer version can be shut off when not needed; the hook version triggers its function every time the party ever rests during the game.
Generally you should only use one or the other. However, you can also choose to call a script object on the map from the hook; allowing you to edit what the hook does from within the editor, and with no need of a timer.
  • The timer method: Add a script and paste this into it:

    Code: Select all

    message_displayed = false
    
    function bedCheck()
    	if party.party:isResting() then
    		if not message_displayed then
    			--=--------------------------[user instructions]--
    		
    			hudPrint("The party cannot rest here.")
    			
    			--==--------------------------------------
    			message_displayed = true
    		end	
    	else message_displayed = false	
    	end
    party.party:wakeUp(true)
    end
    
    Connect a timer to the script and start or stop it as needed.
    The main [and perhaps only] advantage of the timer method, is that you can easily adjust the amount of time between checks.
    other than that... the hook method is probably best.
  • The hook method: define the party [usually] in object.lua as:

    Code: Select all

    defineObject{
    	name = "party",
    	components = {
    		{
    			class = "Party",
    			onRest = function(self)
    						--=--------------------------[user instructions]--
    						hudPrint("The party makes camp, but")
    						hudPrint("is uncomfortable here.")
    
    						--Optional: Returning false disables resting completely.
    					return false
    						--Optional:  Use a user script to return false; and add any additional instructions or changes/or testing
    								--that you wish from within the editor.
    					--return user_script_1.script:userFunction()
    						--=-----------------------------------------------
    					end,
    		},
    		{
    			class = "Light",
    			name = "torch",
    			range = 12,
    		},
    	},
    	editorIcon = 32,
    	placement = "floor",
    }
    
  • Example userScript (for use with the hook):

    Code: Select all

    function userFunction()
    	hudPrint("The party decides that it cannot rest here.")
    	return false
    end
    

Re: Turning *off* the ability to rest

Posted: Wed Jan 28, 2015 12:05 pm
by Komag
I would definitely recommend onRest hook to run a function, which conditionally breaks resting and does whatever else you want, such as printing a message

Re: Turning *off* the ability to rest

Posted: Wed Jan 28, 2015 9:06 pm
by David Ward
This forum is great. You guys are awesome. Thank you very much for the detailed responses.

I guess I'm not quite understanding the hook method. The timer method seems fairly straight forward...? Party enters a dungeon - timer starts, no resting here - if they leave the dungeon, timer stops, and they can rest again.

Re: Turning *off* the ability to rest

Posted: Wed Jan 28, 2015 11:05 pm
by Komag
The timer has to repeatedly run, and it's just not the right way to handle this, even if it works. Hooks are very important, so take the chance to learn them at this opportunity.

Re: Turning *off* the ability to rest

Posted: Thu Jan 29, 2015 12:43 am
by Isaac
The only real benefit of the timer is ~that it's easily understood. Anything else that can be done using the timer method can be done better with hooks [two hooks: onRest & onWakeUp].

The timer method allows you to easily change the amount of time in between checks; allowing for events (spawned encounters :twisted: ) ~sometime~ later during the night; but even this can be done [better] with hooked functions.

** Another thing to consider, is that you can of course use the timer method until you are comfortable with using hooks... Just plan to change it before you release the mod... You don't have to change it, but using the hook method is the MUCH better way.

Re: Turning *off* the ability to rest

Posted: Thu Jan 29, 2015 6:59 am
by David Ward
Okay this is very good, again thank you guys for the responses and details. My friend is taking a look at the hook method. I think we'll make it work. :)