Is there a way to catch the direction of attempted movement?
Is there a way to catch the direction of attempted movement?
Is there a way to catch the direction of attempted movement?
What I mean is... Say the party was standing in a 1 cell room with no doors. Is there a way to detect if they push against a wall... (that returns what direction the tried to move)?
I've been tinkering around with pressure plates, but they don't seem to trigger unless you actually step off of them; this is not possible in a 1 cell room.
** Also: I'd greatly appreciate an example of the use of hooks; especially the onMove() hook. (I did read the Scripting hooks and script reference pages).
Is there a way to make that a condition for an IF block?
(When I tried I got a Nil value error.)
What I mean is... Say the party was standing in a 1 cell room with no doors. Is there a way to detect if they push against a wall... (that returns what direction the tried to move)?
I've been tinkering around with pressure plates, but they don't seem to trigger unless you actually step off of them; this is not possible in a 1 cell room.
** Also: I'd greatly appreciate an example of the use of hooks; especially the onMove() hook. (I did read the Scripting hooks and script reference pages).
Is there a way to make that a condition for an IF block?
(When I tried I got a Nil value error.)
Re: Is there a way to catch the direction of attempted movem
Pretty sure you'd use the onMove hook. An if statement could check for the direction (0,1,2,3) you're looking for and then do what it is you want to do.
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onMove = function(self, dir)
print("party moves in direction", dir)
if dir == 3 then
do this
end
end,
}Re: Is there a way to catch the direction of attempted movem

I got it to where the engine prints the Party's direction each time they move; and it's cool that it does list the intended direction even if the path is blocked ~that's what I'm looking for... but I have been unable to check (or otherwise use) this code in a triggered script, it only seems to work in the Init.lua; otherwise I just get Nil Value errors.
Re: Is there a way to catch the direction of attempted movem
Yep, all the hooks and object definitions have to be in init.lua or one of the files loaded by init.lua.
Re: Is there a way to catch the direction of attempted movem
I think I am missing something very basic, but... How does one check/or test the onMove dir value in a Lua script object triggered by a pressure plate on the map?petri wrote:Yep, all the hooks and object definitions have to be in init.lua or one of the files loaded by init.lua.
Last edited by Isaac on Tue Oct 02, 2012 12:48 pm, edited 1 time in total.
Re: Is there a way to catch the direction of attempted movem
I don't really understand the relationship between the hooks in the init.lua (and other .lua files) and the scripts in the editor. In my sick_snail example...
... I added the onDie hook which, upon the snail's death, triggers a script in the editor named "sickscript"which contains a function called "snaildie" which makes certain things happen:
Soooooooooo, maybe you could set something up in your .lua files to trigger various functions within scripts in the editor, but I'm not sure how you would exactly do it
Code: Select all
cloneObject{
model = "mod_assets/models/monsters/snail_ben.fbx",
name = "sick_snail",
baseObject = "snail",
health = 2,
sight = 1,
attackPower = 1,
onDie = function(monster)
return sickscript.snaildie()
end
}Code: Select all
function snaildie()
diescounter:decrement()
print("You got 'em")
endFinished Dungeons - complete mods to play
Re: Is there a way to catch the direction of attempted movem
That helps.Komag wrote:...
Now I can understand the hook for onDie... if the creature dies, then the hook event code runs... and I can do the same for onMove... but what I'm really trying to do is trigger an even if (and only if) the party moves is the intended direction... Say East, but not North, West, or South. I can see the hook code printing out the party's direction ~even when bumping into walls ~it still triggers. I just want to trigger code based on what direction the party just moved ~even if their path is blocked. ** I keep getting nil value errors. I'll work around this for a while, and come back to it.
Last edited by Isaac on Tue Oct 02, 2012 1:18 pm, edited 1 time in total.
Re: Is there a way to catch the direction of attempted movem
I'm a bit slow, but this might help:
entry in init.lua
script entity called "direction_script"
which prints whether the party moved west or did not move west... (assuming direction 3 is west!?!)
So you could change the outcome of the if statement to whatever you want... and in particular you could put in a test to see if direction_plate:isDown() to see if the party moved west ONTO the plate named direction_plate...
entry in init.lua
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onMove = function(self, dir)
return direction_script.moveCheck(dir)
end,
}script entity called "direction_script"
Code: Select all
function moveCheck(dir)
if dir == 3
then hudPrint("You moved west")
else hudPrint("You did not move west")
end
endSo you could change the outcome of the if statement to whatever you want... and in particular you could put in a test to see if direction_plate:isDown() to see if the party moved west ONTO the plate named direction_plate...
Puzzle Frameworks - http://www.grimrock.net/forum/viewtopic.php?f=14&t=4564
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Re: Is there a way to catch the direction of attempted movem
That helped a lot; I did alter it slightly.Grimwold wrote:I'm a bit slow, but this might help:
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onMove = function(self, dir)
direction_script.moveCheck(dir)
end,
}Code: Select all
function moveCheck(dir)
print(dir)
endI will see if I can get the If block to work.
Thank you.
** Update: This now works. I have a teleporter that turns on anytime the party ever moves West.
This is a dead end hall with a deactivated teleporter at the end. moving into/bumping into the walls does nothing until you bump into the West Was, and the teleporter activates.

(I just need to figure out how to get it to only happen on the pressure plate.)
*** Update: Okay... I have it working that I can place a pressure plate in front of an illusionary wall and check the Party's movement; it becomes passable only if they directly push against it; otherwise it looks like a wall on the map.
Re: Is there a way to catch the direction of attempted movem
Wow, that's quite an interesting puzzle! You'll want to do two things:
- decent hint that this is a place we'll need to push the wall
- some way to let us relax and not have to try pushing every other wall on the map
- decent hint that this is a place we'll need to push the wall
- some way to let us relax and not have to try pushing every other wall on the map
Finished Dungeons - complete mods to play
