Trying to make a walk through walls script

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Trying to make a walk through walls script

Post by Foxley »

I want to have a script where a character's ability lets them walk through hidden passages. Here's how I'd want it done:

Image

Basically the hero finds a hidden passage spot (where the circle is), activates it, and the script has them walk through the hidden passage and out the other side, then resumes player. However as far as how to rig the walking along a specific path to work, I'm not sure what the best way to do that is.

I thought there were hero pathfinding commands, but I just checked plotdict.xml and there aren't any, just NPCs. Was thinking of having hidden passage zone and drawing the path with it, then temporarily writing the wallmap to 0 along those zones and pathfinding the hero, but can't do that apparently.

Any other ideas? I just gotta get this implemented quick, still got a lot of other things to work on.
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

Kylekrack just suggested trying to put in "pathfind hero to" and compiling to see if it'd take, and it did. Huh.
User avatar
Pepsi Ranger
Liquid Metal Slime
Posts: 1457
Joined: Thu Nov 22, 2007 6:25 am
Location: South Florida

Post by Pepsi Ranger »

Can't you just use "walk hero to x" and "walk hero to y" commands when the hero is suspended? It's pretty quick and easy (and accurate) to just tell the script where you want the hero to walk.

As far as wallmaps are concerned, I think you can just use "suspend hero walls" and "resume hero walls" to achieve what you want.

Is what you want to do more complicated than that?
Place Obligatory Signature Here
User avatar
Foxley
Metal Slime
Posts: 832
Joined: Sat Nov 09, 2013 5:54 pm

Post by Foxley »

That would work fine for a one-off sequence, but since I'm having several of these on the map, it would be pretty bad to have to manually put in walk sequences into the .HSS file for each one.

I ended up actually not using pathfinding and instead went with a "breadcrumb" zone method, where the hero looks for an adjacent tile with the breadcrumb, removes the breadcrumb from the current spot, and moves to the adjacent spot.

Here's the working code if anyone's curious.

Code: Select all

global variable (400, raccoon detecting)

plotscript, raccoon detect, begin
	variable (tile x, tile y, radius)
	raccoon detecting := true
	radius := 3
	
	for (tile x, hero x(me)--radius, hero x(me)+radius) do (
		for (tile y, hero y(me)--radius, hero y(me)+radius) do (
			if (read zone (zone:Raccoon path marker, tile x, tile y) &&
			npc at spot (tile x, tile y) == false) then (
				create npc (npc:Path marker, tile x, tile y)
				play sound (3)
				wait (5)
			)
		)
	)
	raccoon detecting := false
end

plotscript, use raccoon path marker, arg, ref, begin
	variable (tile x, tile y)
	delete npc (ref)
	suspend player
	suspend hero walls
	raccoon detecting := true
	
	## Put 'breadcrumbs' on the hidden path
	for (tile x, hero x(me)--9, hero x(me)+9) do (
		for (tile y, hero y(me)--6, hero y(me)+6) do (
			if (read zone (zone:Raccoon path, tile x, tile y)) then (
				write zone (zone:Raccoon breadcrumbs, tile x, tile y, true)
			)
		)
	)
	
	## Follow & remove the breadcrumbs by looking for adjacent zone
	while (true) do (
		if (read zone (zone:Raccoon breadcrumbs, hero x(me), hero y(me)--1)) then (	## Up
			passage step (up)
		) elseif (read zone (zone:Raccoon breadcrumbs, hero x(me)+1, hero y(me))) then (	## Right
			passage step (right)
		) elseif (read zone (zone:Raccoon breadcrumbs, hero x(me), hero y(me)+1)) then (	## Down
			passage step (down)
		) elseif (read zone (zone:Raccoon breadcrumbs, hero x(me)--1, hero y(me))) then (	## Left
			passage step (left)
		) else (	## No more breadcrumbs, step away from the path
			walk hero (me, hero direction(me), 1)
			wait for hero
			resume player
			resume hero walls
			raccoon detecting := false
			exit script
		)
	)
	subscript, passage step, dir, begin
		write zone (zone:Raccoon breadcrumbs, hero x(me), hero y(me), false)
		walk hero (me, dir, 1)
		wait for hero
	end
end
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Wow, that looks like a really complicated solution!

"pathfind hero to" is documented in the plotscripting dictionary, but is new in Fufluns. You must have been looking at the dictionary for Etheldreme. Note that both of them are linked to from the wiki. The version is displayed at the top, and nightly versions have "nightly" as part of the URL.
Last edited by TMC on Sun Dec 02, 2018 12:54 am, edited 1 time in total.
Post Reply