[SCRIPT] Simple hunger system

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
st1nger
Posts: 19
Joined: Wed May 29, 2013 8:44 pm
Location: Germany

[SCRIPT] Simple hunger system

Post by st1nger »

Hello everyone.

Here is a simple example for a hunger system wich deals damage to champions if the food bar falls to 0.

Code: Select all

defineObject{
	name = "party",
	baseObject = "party",
	components = {
		{
			class = "Timer",
			name = "foodtimer",
			timerInterval = 10.0, -- check every 10 seconds for food / deals damage
			triggerOnStart = true,
			onActivate = function(self)
				for i = 1, 4, 1 do
					local food = party.party:getChampion(i):getFood()
					if food == 0 then
						local h = party.party:getChampion(i):getMaxHealth()
						local dmg = (h/24) -- the champion has 4 minutes to life
						party.party:getChampion(i):damage(dmg, "physical")
					end
				end
			end
		}
	}
}
Last edited by st1nger on Wed May 27, 2015 1:03 pm, edited 1 time in total.
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: simple hunger script

Post by Eleven Warrior »

Awesome script man :) Thxs for the help I was thinking of this and totally forgot about the party at the imam hungry stage :)
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [SCRIPT] Simple hunger system

Post by Drakkan »

definitely wonderful idea ! Do you think it is possible to expand it a little (or make another possible version), which works following way -- After starving trait appears for some champion (food = 0), champion start to be damaged lets say every 10 seconds for some dmg (like 5-10 dmg).
Also the damaging should start NOT immediately when food = 0 but lets say after one minute of gameplay.
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
st1nger
Posts: 19
Joined: Wed May 29, 2013 8:44 pm
Location: Germany

Re: [SCRIPT] Simple hunger system

Post by st1nger »

Drakkan wrote:definitely wonderful idea ! Do you think it is possible to expand it a little (or make another possible version), which works following way -- After starving trait appears for some champion (food = 0), champion start to be damaged lets say every 10 seconds for some dmg (like 5-10 dmg).
Also the damaging should start NOT immediately when food = 0 but lets say after one minute of gameplay.
Sure, almost everything is possible.

The original hunger system in LoG2 is the following:

The hunger bar has 1000 units = Full bar
At 349 units the bar is yellow and no effect to champions.
At 249 units the bar is red and starving effect to the champion. With this effect the champion does not regen health and energy when resting.
At 0 units the bar is empty but no other effect, still starving.

The player has enough time if the champion are starving before the bar reach 0 units.

you can change the units in my script if you just want to start damage at a specific value.


timerInterval = 10.0, <- how often to check food or deals damage.

if food == 0 then <- damage starts at here. change as you wish. 1000 is full bar, 349 is yellow bar, 249 is red bar.

local dmg = (h/24) <- value of damage. with h/24 the champion has 4 minutes to life. or change as you wish.


Tell me what exactly you want to change and i look what i can do

st1nger
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [SCRIPT] Simple hunger system

Post by Drakkan »

st1nger wrote:
Drakkan wrote:definitely wonderful idea ! Do you think it is possible to expand it a little (or make another possible version), which works following way -- After starving trait appears for some champion (food = 0), champion start to be damaged lets say every 10 seconds for some dmg (like 5-10 dmg).
Also the damaging should start NOT immediately when food = 0 but lets say after one minute of gameplay.
Sure, almost everything is possible.

The original hunger system in LoG2 is the following:

The hunger bar has 1000 units = Full bar
At 349 units the bar is yellow and no effect to champions.
At 249 units the bar is red and starving effect to the champion. With this effect the champion does not regen health and energy when resting.
At 0 units the bar is empty but no other effect, still starving.

The player has enough time if the champion are starving before the bar reach 0 units.

you can change the units in my script if you just want to start damage at a specific value.


timerInterval = 10.0, <- how often to check food or deals damage.

if food == 0 then <- damage starts at here. change as you wish. 1000 is full bar, 349 is yellow bar, 249 is red bar.

local dmg = (h/24) <- value of damage. with h/24 the champion has 4 minutes to life. or change as you wish.


Tell me what exactly you want to change and i look what i can do

st1nger
local dmg = (h/24) <- value of damage. with h/24 the champion has 4 minutes to life. or change as you wish.

I dont get this - it means champion will be killed after 4 minutes ? Thats quite drastic. Id rather champion to be dealed some minor damage every lets say 30 seconds if he/she is starving.
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
st1nger
Posts: 19
Joined: Wed May 29, 2013 8:44 pm
Location: Germany

Re: [SCRIPT] Simple hunger system

Post by st1nger »

Drakkan wrote: local dmg = (h/24) <- value of damage. with h/24 the champion has 4 minutes to life. or change as you wish.

I dont get this - it means champion will be killed after 4 minutes ? Thats quite drastic. Id rather champion to be dealed some minor damage every lets say 30 seconds if he/she is starving.
How long it takes from starving to 0? maybe 10 minutes?
Starving begins at 249. The damage begins at 0.

For me, this is enough time to react.

If you want a 30 second timer, just change the code to this one: timerInterval = 30.0,
And for damage you can use any number you want:

local dmg = (h/24) <- 3,75 damage if the champion has 90 hp, this means 4 minutes to life.
local dmg = 1 <- 1 damage per check. if 10 second timer, the champion hast 15 minutes to life with 90 hp for example.

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

Re: [SCRIPT] Simple hunger system

Post by minmay »

st1nger wrote:How long it takes from starving to 0? maybe 10 minutes?
Food consumption doesn't occur with time at all unless you are 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
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: [SCRIPT] Simple hunger system

Post by AndakRainor »

Is there an event corresponding to food consumption when the party moves or rests ? If there is it could be another way to deal some damage without using directly time.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: [SCRIPT] Simple hunger system

Post by Isaac »

Why not use OnMove() ?
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: [SCRIPT] Simple hunger system

Post by AndakRainor »

Isaac wrote:Why not use OnMove() ?
Yes, that and onRest() could be used as an alternative to damage over time. But do we know the formulas used by the game to calculate food consumption ? I'm just curious here, this system does not need to exactly match for health what the game does for food to be a good addition to immersion in a mod. But it could be nice if it took into account the minotaur, fast_metabolism and endurance traits for example.
Post Reply