Trying to understand party hooks. Please help.

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Trying to understand party hooks. Please help.

Post by Ryeath_Greystalk »

Something I was hoping to be simple turns out not to be.

I have a room where I want to monitor the party's facing. So I set up a party hook to check the party.facing whenever they move or turn. The problem that I have is simple, the onTurn() and onMove() check the position and performs any functions before the actual move/turn take place whereas I need it to check after the move/turn occurs.

I read the description of onTurn() and believe I can still make this work (albeit doubling my work load :? ) by using the directional parameter, but this is where my knowledge gets fuzzier than a peach.

Right now I have

onTurn() = function(self)
moveScript.checkPosition()
end,

and then a script entity with

function checkPosition()
if party.facing == 0 then
<severely abuse party here>
end
end

but that works when the party is already facing north and tries to turn east or west. What I need is when the party is facing east or west and tries to turn north.

Code: Select all

onTurn: a hook which is called when the party turns. The function gets two parameters: the party itself and the direction it is turning, -1 for counterclockwise and 1 for clockwise turn. If the function returns false, the turn is cancelled.
So how do I work the -1 for counterclockwise and 1 for clockwise into the equation. If I were to take a guess it would be something like

function checkPosition(direction)
if party.x == 1 and direction == -1 then
<punish party>
elseif party.x == 3 and direction == 1 then
<insult party>
end
end

or would it be checkPosition(self,direction)?

I think a nice tutorial on using hooks, especially with an emphasis on using the various parameters would be an awesome addition to the superthread.

Thanks in advance.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Trying to understand party hooks. Please help.

Post by Komag »

checkPosition(self,direction)

should always include all parameters, even if you don't use them, even if just for clarity

you would first need
onTurn(self,direction)
and then send the parameters to the function
moveScript.checkPosition(self,direction)
Finished Dungeons - complete mods to play
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: Trying to understand party hooks. Please help.

Post by Xanathar »

onTurn: a hook which is called when the party turns. The function gets two parameters: the party itself and the direction it is turning, -1 for counterclockwise and 1 for clockwise turn. If the function returns false, the turn is cancelled.
The description says it all: two parameters in the function, the party and the direction of turn.

So:

Code: Select all

onTurn = function(theparty, direction)
  local oldfacing = theparty.facing
  local newfacing = (theparty.facing + direction + 4) % 4
  .. here do what you want ..
end
That said, if it's just one room I would avoid the hook and:
  • Put an high frequency timer (0.1) calling a function which does everything you want
  • In the function check if the party moved or changed facing since last time, if not return
  • Put pressure plates to ensure the timer is enabled only when you are in the room and is disabled when you get out
The reason I would go this way instead of the hook is that the hook does not detect (or at least it used to not detect unless it got fixed and I didn't notice) if you change facing by free-look with the right mouse key, nor does it detect changing facing because of teleports or other strange things.

I did this exactly yesterday evening and it has no impact in performance whatsoever (but of course keep the timer enabled in check).
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Trying to understand party hooks. Please help.

Post by Ryeath_Greystalk »

Thanks for the replies.

I can confirm that onTurn() does not get triggered by the free look. I never use free look when playing and I had totally forgotten about it. It would have an adverse effect on the theme of the room if players can get around the no look scheme by using it. I think I may re evaluate the plan and come up with something else for that room.

Thanks again.
Post Reply