Page 1 of 2
Is there a way to catch the direction of attempted movement?
Posted: Tue Oct 02, 2012 4:25 am
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.)
Re: Is there a way to catch the direction of attempted movem
Posted: Tue Oct 02, 2012 5:11 am
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,
}
Re: Is there a way to catch the direction of attempted movem
Posted: Tue Oct 02, 2012 8:12 am
by Isaac

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
Posted: Tue Oct 02, 2012 10:48 am
by petri
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
Posted: Tue Oct 02, 2012 12:43 pm
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?
Re: Is there a way to catch the direction of attempted movem
Posted: Tue Oct 02, 2012 12:48 pm
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
Re: Is there a way to catch the direction of attempted movem
Posted: Tue Oct 02, 2012 1:15 pm
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.
Re: Is there a way to catch the direction of attempted movem
Posted: Tue Oct 02, 2012 1:17 pm
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...
Re: Is there a way to catch the direction of attempted movem
Posted: Tue Oct 02, 2012 1:29 pm
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.
I 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.

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

(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
Posted: Tue Oct 02, 2012 3:47 pm
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