I don't know if the party 'onDamage' hook is called for falling damage. If it is, you could write a script that...
1. Detects when the player steps on a pit and sets a flag in a script entity.
2. In onDamage you check if the flag is set, if it is, clear the flag and return false.
If onDamage isn't called, this clearly won't work :p
Question on Falling Damage
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: Question on Falling Damage
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Re: Question on Falling Damage
Thanks! That new script with the local bit worked! Wow, quick response. I suppose I should email AH again and tell them not to worry bout the bug.
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: Question on Falling Damage
This is a rough (first draft) solution that allows you to become immune to pit damage without having to place any pressure plates on the pits or anything manual like that. Just set 'pitImmunity.enabled = true' and the party becomes completely immune to pit falling damage until you set 'pitImmunity.enabled=false'.
Add this script to your dungeon...
Party hooks for your mod's init.lua script (this will work as is, but if you have other onMove or onDamage hooks you will need to merge them.
Note that this script works by scanning the upcoming square on every move. If the square has an open pit, then we say "ignore the next N physical damage calls" where N is the number of enabled party members. It's minutely possible that the party takes a hit from a monster between walking forward and falling down the pit - in this case, it won't work as expected. However, this seems pretty unlikely, as the damage would have to be physical, and would have to occur during the step onto the pit. A solution to get around this would be more complicated, and I wasn't intending on spending more than 10-15 minutes this morning prototyping a solution :p.
Add this script to your dungeon...
Code: Select all
-------------------------------------------------------
-- Pit Immunity Script
-------------------------------------------------------
-- This script should be placed in a script entity
-- called 'pitImmunity'.
--
-- To make the party immune to pit damage you just
-- need call 'pitImmunity.enabled = true' in another
-- script. To disable it, call pitImmunity.enabled=false.
--
-- For this to work, you will need to hook
-- onMove and onDamage into your party script.
-------------------------------------------------------
enabled = true;
ignoreDamageCount = 0;
function getEnabledChampionCount()
local enabledChamps = 0;
for i=1,4 do
local champ = party:getChampion(i);
if ( champ:getEnabled() ) then
enabledChamps = enabledChamps + 1;
end
end
return enabledChamps;
end
function onMove(self, party, direction)
if ( enabled ~= true ) then
return;
end
local dx, dy = getForward(direction);
local x, y = party.x + dx, party.y + dy;
for e in entitiesAt(party.level, x, y) do
if ( e.class == "Pit" ) then
ignoreDamageCount = getEnabledChampionCount();
end
end
end
function onDamage(self, champion, damAmount, damType)
if ( enabled ~= true ) then
return false;
end
if ( ignoreDamageCount > 0 and damType == 'physical' ) then
ignoreDamageCount = ignoreDamageCount - 1;
return false;
end
end
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onMove = function(party, direction)
pitImmunity:onMove(party,direction);
end,
onDamage = function(champion, damAmount, damType)
return pitImmunity:onDamage(champion, damAmount, damType);
end
}
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
-
- Posts: 275
- Joined: Sat Jun 16, 2012 5:32 am
Re: Question on Falling Damage
I have an question. Is a damage tile ( I can't get it to work anyhows in my MOD) possible to target only 3 champions? So only 1 will survive?.
I was kinda thinking of setting 3 champs health at zero, so they die? But will this work and if yes, how to set this?.
I kinda need this for an event in my dungeon.
note: Log1. Not LoG2
I was kinda thinking of setting 3 champs health at zero, so they die? But will this work and if yes, how to set this?.
I kinda need this for an event in my dungeon.
note: Log1. Not LoG2
Re: Question on Falling Damage
easiest way is to use Champion:damage([amount],"physical")
http://www.grimrock.net/modding_log1/sc ... reference/
http://www.grimrock.net/modding_log1/sc ... reference/
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.
-
- Posts: 275
- Joined: Sat Jun 16, 2012 5:32 am
Re: Question on Falling Damage
minmay wrote:easiest way is to use Champion:damage([amount],"physical")
http://www.grimrock.net/modding_log1/sc ... reference/
Thanks Minway. I've tried exampels from the forum like
Code: Select all
armed = true
function setTrap(set)
if set then
armed = true
else armed = false
end
end
function trap(t)
if armed and t.x ~= nil then
damageTile(t.level, t.x, t.y, 0, 64 , "poison", 1)
local screamer = math.random(3)
party:getChampion(screamer):playDamageSound()
party:getChampion(screamer+1):playDamageSound()
end
end
They dont work. even if set fire or poison to 100 dmg. There is nothing happening.. ( no crash also, nor error code)
However I've I make a new dungeon/mod. Past this code in the new project it does work.
But in my real dungeon it refuse it... I don't know why...In a new project with only 1 level.. so the start. It works....
-
- Posts: 275
- Joined: Sat Jun 16, 2012 5:32 am
Re: Question on Falling Damage
Nevermind I worked on a work arround. It works now. I didn't used any of this code above.trancelistic wrote:minmay wrote:easiest way is to use Champion:damage([amount],"physical")
http://www.grimrock.net/modding_log1/sc ... reference/
Thanks Minway. I've tried exampels from the forum likeCode: Select all
armed = true function setTrap(set) if set then armed = true else armed = false end end function trap(t) if armed and t.x ~= nil then damageTile(t.level, t.x, t.y, 0, 64 , "poison", 1) local screamer = math.random(3) party:getChampion(screamer):playDamageSound() party:getChampion(screamer+1):playDamageSound() end end
They dont work. even if set fire or poison to 100 dmg. There is nothing happening.. ( no crash also, nor error code)
However I've I make a new dungeon/mod. Past this code in the new project it does work.
But in my real dungeon it refuse it... I don't know why...In a new project with only 1 level.. so the start. It works....
THis script is just easy, about a few lines. It works now what I was planning to do,
Thanks anyhows<3