Is there a way to catch the direction of attempted movement?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Is there a way to catch the direction of attempted movement?

Post by Isaac »

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.)
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: Is there a way to catch the direction of attempted movem

Post by Batty »

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,
}
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is there a way to catch the direction of attempted movem

Post by Isaac »

Image
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. :cry:
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Is there a way to catch the direction of attempted movem

Post by petri »

Yep, all the hooks and object definitions have to be in init.lua or one of the files loaded by init.lua.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is there a way to catch the direction of attempted movem

Post by Isaac »

petri wrote:Yep, all the hooks and object definitions have to be in init.lua or one of the files loaded by init.lua.
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?
Last edited by Isaac on Tue Oct 02, 2012 12:48 pm, edited 1 time in total.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Is there a way to catch the direction of attempted movem

Post by Komag »

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...

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
}
... 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:

Code: Select all

function snaildie()
     diescounter:decrement()
     print("You got 'em")
end
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
Finished Dungeons - complete mods to play
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is there a way to catch the direction of attempted movem

Post by Isaac »

Komag wrote:...
That helps. :)
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.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Is there a way to catch the direction of attempted movem

Post by Grimwold »

I'm a bit slow, but this might help:

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
end
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...
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Is there a way to catch the direction of attempted movem

Post by Isaac »

Grimwold wrote:I'm a bit slow, but this might help:
That helped a lot; I did alter it slightly.

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)
end
This prints the direction, and that's more than I managed in two hours. :oops:
I will see if I can get the If block to work.

Thank you. 8-)

** Update: This now works. I have a teleporter that turns on anytime the party ever moves West. :lol: (Turns off when they move any other direction.)
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.
Image
(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. 8-)
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Is there a way to catch the direction of attempted movem

Post by Komag »

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
Finished Dungeons - complete mods to play
Post Reply