resist physical damage item
resist physical damage item
Hello,
can somebody "script" me an item which give 25% of resistance against physical damage please? If it can be done of course.
can somebody "script" me an item which give 25% of resistance against physical damage please? If it can be done of course.
Re: resist physical damage item
* Technically this seems to work, but it's not at all ideal; damage does not show with the usual blood splatter.
*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.
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.
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
}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
}It works; but they don't visibly take less damage than the others.
Re: resist physical damage item
Isn't this fixable by setting an arbitrary variable before calling damage() and checking for it, like this:Isaac wrote:*Using champion:damage() in the hook [to get the blood-splatter indicator] causes a stack overflow.
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
endGrimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: resist physical damage item
thanks all for the replies
I ve used your first script:
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?
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
}
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
}
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
}
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
}
Re: resist physical damage item
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.bongobeat wrote: works well! no crash
what do you mean by stack overflow? this script can cause a crashes?
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.
Re: resist physical damage item
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:
The specific error you got occurred because you didn't use a comma to separate the table values.
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
endYou 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.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?
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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: resist physical damage item
Works beautifully.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
Interestingly: math.ceil() does not have to be used... it will display fractional injuries for ~like 4.75 damage.
I've tested injury damages that reduce to less than a point, and they work.
Re: resist physical damage item
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 endYou 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.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?
The specific error you got occurred because you didn't use a comma to separate the table values.
ok, thanks for your help