Turning *off* the ability to rest

Have trouble running Legend of Grimrock 2 or do you have questions about the purchasing options? Look for help here.
Post Reply
User avatar
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Turning *off* the ability to rest

Post 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?
User avatar
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Re: Turning *off* the ability to rest

Post by David Ward »

I found this, but it is for grimrock 1??

viewtopic.php?f=14&t=4707
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Turning *off* the ability to rest

Post by minmay »

return false from PartyComponent.onRest() to prevent resting
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Turning *off* the ability to rest

Post 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
    
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Turning *off* the ability to rest

Post 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
Finished Dungeons - complete mods to play
User avatar
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Re: Turning *off* the ability to rest

Post 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.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Turning *off* the ability to rest

Post 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.
Finished Dungeons - complete mods to play
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Turning *off* the ability to rest

Post 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.
User avatar
David Ward
Posts: 103
Joined: Wed Jan 07, 2015 11:44 pm
Location: Vancouver, BC, Canada

Re: Turning *off* the ability to rest

Post 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. :)
Post Reply