[Technique] Trigger a function based on direction traveled
[Technique] Trigger a function based on direction traveled
.............................
Last edited by NutJob on Thu Nov 20, 2014 12:19 am, edited 2 times in total.
Re: [Technique] Trigger a function based on direction travel
This could be very useful for making enemies that respawn when you enter certain areas, or resetting puzzles. Thanks. I'll give it a test when I have time. 

Re: [Technique] Trigger a function based on direction travel
Now that is nice work NutJob! I will definitely be using some variation of this myself. Code copied! 

Re: [Technique] Trigger a function based on direction travel
Thanks, both of you. I'll probably wrap it all up in one easy routine to use eventually. Something like...
...that can be called on level setup (or init)
I know I don't want to hand code it every time I want to use. Keep an eye on this thread.
Code: Select all
oneWayTrigger(
x, y, z, -- for the floor_trigger
int_direction, -- direction *the party is traveling* it triggers on (0 - 3)
"script_id",
"mainFunc",
"resetFunc"
)
I know I don't want to hand code it every time I want to use. Keep an eye on this thread.
.................
...................
Last edited by NutJob on Wed Nov 12, 2014 1:29 am, edited 1 time in total.
-
- Posts: 28
- Joined: Tue Nov 04, 2014 6:53 pm
Re: [Technique] Trigger a function based on direction travel
I needed code like that in my custom dungeon. This was my solution:
in init.lua
I put a script in my map, called it "somescript", and give it this function:
With that code, whenever the party moves north (no matter what direction they're facing), it always prints "0". Whenever they move east, it prints "1", south "2", and west "3".
That was kind of pointless for me, though, so I came up with this code to return the direction the party is moving regardless of facing:
It won't be hard to call this function from a floor_switch to determine which way the party was moving when they crossed it.
in init.lua
Code: Select all
defineObject{
name = "party",
baseObject = "party",
components = {
{
class = "Party",
onMove = function(party,dir,arg1)
somescript.script.printDir(dir)
end,
},
},
}
Code: Select all
function printDir(d)
print(d)
end
That was kind of pointless for me, though, so I came up with this code to return the direction the party is moving regardless of facing:
Code: Select all
function printDir(d)
-- Facing north
if party.facing == 0 then
if d == 0 then
print("forward")
elseif d == 1 then
print("right")
elseif d == 2 then
print("back")
else
print("left")
end
-- Facing east
elseif party.facing == 1 then
if d == 0 then
print("left")
elseif d == 1 then
print("forward")
elseif d == 2 then
print("right")
else
print("back")
end
-- Facing south
elseif party.facing == 2 then
if d == 0 then
print("back")
elseif d == 1 then
print("left")
elseif d == 2 then
print("forward")
else
print("right")
end
-- Facing west
elseif party.facing == 3 then
if d == 0 then
print("right")
elseif d == 1 then
print("back")
elseif d == 2 then
print("left")
else
print("forward")
end
end
end
Re: [Technique] Trigger a function based on direction travel
This may better explain what's happening. As for how to use, that's impossible to describe. You only need to know you need one way firing of several scripts. This is kind of like... hmm, oh! an undo party technique. ~laughs~
So if I used this:
The color-coded dots are where each function (simply named "a", "b", "c" for brevity) would fire.

Great for building a completely different trap every time the party goes into a room or a certain direction in the dungeon (from a crossroads), or building the puzzle completion code dynamically for use elsewhere (not even related to that room).
So if I used this:
Code: Select all
oneWayTrig(5,5,0, {0,1}, "a", "b", "c")

Great for building a completely different trap every time the party goes into a room or a certain direction in the dungeon (from a crossroads), or building the puzzle completion code dynamically for use elsewhere (not even related to that room).