Ask a simple question, get a simple answer

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
akroma222
Posts: 1025
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 » Wed Dec 05, 2018 4:13 pm

Killcannon wrote:
Mon Dec 03, 2018 12:14 am
To piggy back on the food question. Is there a way to 'lock' a champions food bar, until say an item is used or spell is cast? For example a 'curse of hunger' until remove curse is cast. Could also work in the opposite with an elixir of plenty where it stops champions decay for a period of time.
Something to consider - if you want to lock their food bar... are you prohibiting the champions from eating? Or can they eat and just nothing happens to their food bar.
(Stopping the champs from eating can be tricky as you can just drop food over the champs menu portrait
You would need to alter this from the onClickItemSlot + onDrawGui party hooks )

Killcannon
Posts: 72
Joined: Sun Apr 12, 2015 2:57 pm

Re: Ask a simple question, get a simple answer

Post by Killcannon » Sat Dec 08, 2018 11:49 am

akroma222 wrote:
Wed Dec 05, 2018 4:13 pm
Killcannon wrote:
Mon Dec 03, 2018 12:14 am
To piggy back on the food question. Is there a way to 'lock' a champions food bar, until say an item is used or spell is cast? For example a 'curse of hunger' until remove curse is cast. Could also work in the opposite with an elixir of plenty where it stops champions decay for a period of time.
Something to consider - if you want to lock their food bar... are you prohibiting the champions from eating? Or can they eat and just nothing happens to their food bar.
(Stopping the champs from eating can be tricky as you can just drop food over the champs menu portrait
You would need to alter this from the onClickItemSlot + onDrawGui party hooks )
That is a very good thought, and I had thought of that. For what I want to do, this wasn't really a concern for me. To be fair, for the design I am looking at doing; the hunger system has become a burden. While it's a cool system and really works for Grimrock 2 in general. There's only a grand total of 8 monster encounters in this dungeon and I don't see it going past 10. That's including 'trash monsters' as well as Bosses. In fact there's more bosses than non bosses. With the majority of the dungeon comprised of deadly puzzles, mazes, and traps. This has really upset the balance that Almost Human's original designs worked with. Being that you'd generally find creatures that had food, or could be food when killed. On top of the occasional packet of food stored in an alcove by said creatures.

While the simple answer is just to chuck some sort of food around every corner; it undermines some of the atmosphere I'm going for. 'Ancient forgotten ruins, recently rediscovered and inhabited by foul constructs, and a mad lich-architect.' That some how have been restocking fresh food and preserving stockpiles for the adventurer to casually feed themselves? Not likely, and I do realize that the adventurers could bring their own food. Then you're stocking player inventories to the brim with food, which they promptly dump and may or may not be able to get back to if trapped on floor x in the middle of a puzzle and run out. Or you're placing a storage area, where they can put the food near the starting area. For which you run into the same problem.

What I'm looking for is a way of turning it into an engaging mechanic for the player in the environment I've set. Probably via creative use of spell or potion, or failing that. A way to remove the mechanic from play entirely. At the end of the day, if I cannot find a good solution I can always start a timer and use the Champion:setFood(food) hook to simply reset the meter back to full on rundown and have it loop. Not something I want to do as overuse of timers will cause performance problems and potentially bugs if too many timers are running at once. I could also litter additional invisible pressure plates across my maps to trigger the script as well. I want that to be a last resort though as it feels to me like 'giving up' at finding a solution.

minmay
Posts: 2697
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay » Sat Dec 08, 2018 12:34 pm

Killcannon wrote:
Sat Dec 08, 2018 11:49 am
Not something I want to do as overuse of timers will cause performance problems and potentially bugs if too many timers are running at once.
no it won't
Killcannon wrote:
Sat Dec 08, 2018 11:49 am
I could also litter additional invisible pressure plates across my maps to trigger the script as well.
FloorTriggerComponent has a much bigger performance impact than TimerComponent does. Even if you make it only triggered by the party, it's still going to use as much cpu time as like 10 timers.

Also, you only need a single TimerComponent for all of this. Put it on the party object (so that it's always on the same map as the party) and set its timerInterval to 0. It will then call its onActivate() hook exactly once per frame. You can set the champions' food level to 1000 in that hook, and of course do anything else you want to do every frame.

Do not worry about the performance impact of TimerComponents ever. On my computer I have to add about 10,000 TimerComponents to increase the frame delay by 1 millisecond.
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.

Pompidom
Posts: 486
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom » Sat Dec 08, 2018 12:51 pm

The author of Resident Grimrock removed the entire food mechanic. Ask him if he wants to share the solution :)

Killcannon
Posts: 72
Joined: Sun Apr 12, 2015 2:57 pm

Re: Ask a simple question, get a simple answer

Post by Killcannon » Sat Dec 08, 2018 12:56 pm

minmay wrote:
Sat Dec 08, 2018 12:34 pm
FloorTriggerComponent has a much bigger performance impact than TimerComponent does. Even if you make it only triggered by the party, it's still going to use as much cpu time as like 10 timers.

Also, you only need a single TimerComponent for all of this. Put it on the party object (so that it's always on the same map as the party) and set its timerInterval to 0. It will then call its onActivate() hook exactly once per frame. You can set the champions' food level to 1000 in that hook, and of course do anything else you want to do every frame.

Do not worry about the performance impact of TimerComponents ever. On my computer I have to add about 10,000 TimerComponents to increase the frame delay by 1 millisecond.
That's very good information to have. You would think that the computer tracking a counter would be more intensive than a passive floor trigger activating a script. Now I know, and can worry less about that. I do have another question as well. Is there something about "pressureplate.floortrigger:setDisableSelf(true)" and "torch.controller:getHasTorch(false)" that's not looking at their boolean values? For example I have this:

Code: Select all

function Pittrappuzzle()

	for i = 1, 9 do
		local pittrigger = findEntity("pit_trigger_"..i)

	if pitfall_1.pit:isClosed() and
	 pitfall_2.pit:isClosed() and
	 pitfall_3.pit:isClosed() and
	 pitfall_4.pit:isClosed() and
	 pitfall_5.pit:isClosed() and
	 pitfall_6.pit:isClosed() and
	 pitfall_7.pit:isOpen() and
	 pitfall_8.pit:isOpen() and
	 pitpuzzletorch_1.socket:getItem(true) and
	 pitpuzzletorch_2.controller:getHasTorch(false) and
	 pitpuzzletorch_3.socket:getItem(true) then
		Executionroom_1.door:open()
		Executionroom_2.door:open()
		pittrigger.floortrigger:setDisableSelf(true)
	else
		Executionroom_1.door:close()
		Executionroom_2.door:close()
	end
end
Which sort of works, except that pitpuzzletorch_2.controller:getHasTorch(false) doesn't actually check to see if it's false. I.E. there's no torch in the holder. Instead, when you do have a torch in the holder it will flag the condition as met and open the door when the rest are met as well. Also pittrigger.floortrigger:setDisableSelf(true) doesn't actually disable the floor triggers and when you step on them, they will reset the puzzle.

minmay
Posts: 2697
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay » Sat Dec 08, 2018 11:05 pm

FloorTriggerComponent:setDisableSelf() does not disable the component, it sets the "disableSelf" property. If disableSelf is true, the FloorTriggerComponent disables itself when it is triggered. If you just wanted to disable it immediately, use Component:disable().

TorchHolderControllerComponent:getHasTorch() returns true if the torch holder contains a torch, and false if it does not contain a torch. It doesn't take any arguments, the false you're passing to it does nothing.
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.

Killcannon
Posts: 72
Joined: Sun Apr 12, 2015 2:57 pm

Re: Ask a simple question, get a simple answer

Post by Killcannon » Sun Dec 09, 2018 8:04 am

Thank you so much for that information. I was able to fix the problem from there and it works beautifully now. I'm still trying to work out how to activate the timer player object I setup. I know i need to put the 'party.timer:onActivate()' in a script then set the interval and what I want it to do. My head just isn't connecting the dots between what needs to be done and the commands to do it just yet.

minmay
Posts: 2697
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay » Sun Dec 09, 2018 10:05 am

Killcannon wrote:
Sun Dec 09, 2018 8:04 am
I know i need to put the 'party.timer:onActivate()' in a script
You don't need to do that. In fact, doing that will cause an error. The onActivate hook goes in the definition of your TimerComponent, like this:

Code: Select all

defineObject{
	name = "party",
	baseObject = "party",
	components = {
		class = "Timer",
		name = "frameTimer",
		timerInterval = 0,
		onActivate = function(self)
			for i=1,4 do
				local c = party.party:getChampionByOrdinal(i)
				if c:getEnabled() then
					c:setFood(1000)
				end
			end
		end,
	},
}
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.

Killcannon
Posts: 72
Joined: Sun Apr 12, 2015 2:57 pm

Re: Ask a simple question, get a simple answer

Post by Killcannon » Mon Dec 10, 2018 9:49 am

Thanks again Minmay, I'm seriously having to retrain my brain on how to think logically with this. I also spoke to the Author of Resident Grimrock and he said that he uses a trait to accomplish this in his mod. Which isn't something I'd thought of at all.

Zo Kath Ra
Posts: 863
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra » Mon Dec 10, 2018 8:34 pm

Is there a way to increase the number of lines in the console?

Post Reply