resist physical damage item

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

resist physical damage item

Post by bongobeat »

Hello,

can somebody "script" me an item which give 25% of resistance against physical damage please? If it can be done of course.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: resist physical damage item

Post by Isaac »

* Technically this seems to work, but it's not at all ideal; damage does not show with the usual blood splatter. :(

Code: Select all

	defineObject{
	name = "party",
	class = "Party",
	editorIcon = 32,
	onDamage = function(champion,dmg,type)
					if champion:getItem(10) ~= nill and champion:getItem(10).name == "stone_skin_bracelet" then
						if type == "physical" then
							local hitpoints = champion:getStat('health')
							champion:setStat('health', hitpoints - (dmg*.75))
							champion:playDamageSound()
							return false
						end
					end
				end
}
*Using champion:damage() in the hook [to get the blood-splatter indicator] causes a stack overflow.

In the code, 'stone_skin_bracelet' can be any defined item [.name] for slot 10; (bracers).

______

An odd alternative could be to simply add 25% of the attack damage to the hitpoints before it scores the damage.

Code: Select all

	defineObject{
	name = "party",
	class = "Party",
	editorIcon = 32,

	onDamage = function(champion,dmg,type)

					if champion:getItem(10) ~= nill and champion:getItem(10).name == "stone_skin_bracelet" then
						if type == "physical" then
							local hitpoints = champion:getStat('health')
							champion:setStat('health', hitpoints + (dmg*.25))
							return
						end
					end
				end
}
This adds [to their health] 25% of the damage that will be done ~just prior to them taking 100% of that damage.
It works; but they don't visibly take less damage than the others.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: resist physical damage item

Post by minmay »

Isaac wrote:*Using champion:damage() in the hook [to get the blood-splatter indicator] causes a stack overflow.
Isn't this fixable by setting an arbitrary variable before calling damage() and checking for it, like this:

Code: Select all

recursing = false
onDamage = function(champion,dmg,type)
               if recursing then recursing = false return true end
               if champion:getItem(10) and champion:getItem(10).name == "stone_skin_bracelet" then
                  if type == "physical" then
                     recursing = true
                     champion:damage(dmg*.75,type)
                     return false
                  end
               end
            end
("recursing" here probably needs to be in an arbitrary script entity or something, IIRC variables defined in asset definition files aren't available during runtime, but you get the point)
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.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: resist physical damage item

Post by bongobeat »

thanks all for the replies

I ve used your first script:
SpoilerShow
defineObject{
name = "party",
class = "Party",
editorIcon = 32,
onDamage = function(champion,dmg,type)
if champion:getItem(10) ~= nill and champion:getItem(10).name == "stone_skin_bracelet" then
if type == "physical" then
local hitpoints = champion:getStat('health')
champion:setStat('health', hitpoints - (dmg*.75))
champion:playDamageSound()
return false
end
end
end
}
works well! no crash
what do you mean by stack overflow? this script can cause a crashes?

To Minmay:
I can't load the mod with your script, because it said I have to close something at line x
it works when removing recursing false, what did I do wrong?
SpoilerShow
defineObject{
name = "party",
class = "Party",
editorIcon = 32,
-- recursing = false
onDamage = function(champion,dmg,type)
if recursing then recursing = false return true end
if champion:getItem(10) and champion:getItem(10).name == "stone_skin_bracelet" then
if type == "physical" then
recursing = true
champion:damage(dmg*.75,type)
return false
end
end
end
}
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: resist physical damage item

Post by Isaac »

bongobeat wrote: works well! no crash
what do you mean by stack overflow? this script can cause a crashes?
Well the obvious choice (I thought) was to intercept the hit, and adjust the damage in the hook before returning false... Thinking that that would cancel the original attack, and allow the Champion to get damaged by the script, using champion:damage(); but when used it caused a stack overflow... Not surprising, as that's damaging the champion in the hook that's called when they are damaged.

A better solution could be a .1 second timer & script call that damages the champion after execution has left the damage hook, but it would need some check in the hook to ignore that timer's damage (which calls it again).

Both of the first two scripts work for the damage aspect, but the second one shows the blood spatter. I will see if I can get my timer idea working, and post back later.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: resist physical damage item

Post by minmay »

My code wasn't intended to be used directly, it was just to demonstrate the concept. Here's a cleaned up version that would be better to use:

Code: Select all

onDamage = function(champion,dmg,type)
	if recursing then recursing = false return true end
	if champion:getItem(10) and champion:getItem(10).name == "stone_skin_bracelet" then
		if type == "physical" then
			recursing = true
			champion:damage(math.ceil(dmg*.75),type)
			return false
		end
	end
	return true
end
bongobeat wrote:To Minmay:
I can't load the mod with your script, because it said I have to close something at line x
it works when removing recursing false, what did I do wrong?
You don't want to define recursing inside the party definition. My idea was to put it in a script entity somewhere (thus you'd need to change the references to script.recursing or whatever), but apparently it doesn't even need to be defined at all before entering the function (shows how much I know about Lua), so that's not necessary in the first place.
The specific error you got occurred because you didn't use a comma to separate the table values.
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: resist physical damage item

Post by Isaac »

minmay wrote:My code wasn't intended to be used directly, it was just to demonstrate the concept. Here's a cleaned up version that would be better to use:

Code: Select all

onDamage = function(champion,dmg,type)
	if recursing then recursing = false return true end
	if champion:getItem(10) and champion:getItem(10).name == "stone_skin_bracelet" then
		if type == "physical" then
			recursing = true
			champion:damage(math.ceil(dmg*.75),type)
			return false
		end
	end
	return true
end
Works beautifully. 8-)


Interestingly: math.ceil() does not have to be used... it will display fractional injuries for ~like 4.75 damage. 8-)
I've tested injury damages that reduce to less than a point, and they work.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: resist physical damage item

Post by bongobeat »

minmay wrote:My code wasn't intended to be used directly, it was just to demonstrate the concept. Here's a cleaned up version that would be better to use:

Code: Select all

onDamage = function(champion,dmg,type)
	if recursing then recursing = false return true end
	if champion:getItem(10) and champion:getItem(10).name == "stone_skin_bracelet" then
		if type == "physical" then
			recursing = true
			champion:damage(math.ceil(dmg*.75),type)
			return false
		end
	end
	return true
end
bongobeat wrote:To Minmay:
I can't load the mod with your script, because it said I have to close something at line x
it works when removing recursing false, what did I do wrong?
You don't want to define recursing inside the party definition. My idea was to put it in a script entity somewhere (thus you'd need to change the references to script.recursing or whatever), but apparently it doesn't even need to be defined at all before entering the function (shows how much I know about Lua), so that's not necessary in the first place.
The specific error you got occurred because you didn't use a comma to separate the table values.

ok, thanks for your help :)
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505
Post Reply