Spoiler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
function table.empty(tab) 	for k, v in pairs(tab) do 		return false 	end 	return true end function FindPath(Map,fx,fy,tx,ty) 	local Node = {} 	local sizex = #Map 	local sizey = #Map[1] 	local curbase = {x = fx,y = fy} 	 	local function Euclidean(fx,fy,tx,ty) 		return math.sqrt((fx-tx)^2 + (fy-ty)^2) 	end 	 	local function Manhattan(fx,fy,tx,ty) 		return math.abs(fx-tx) + math.abs(fy-ty) 	end 	 	-- To get the openlist 	local function openlist() 		local open = {} 		for x = 0, sizex do 			for y = 0, sizey do 				if Node[x][y].Open then 					table.insert(open,{x = x,y = y}) 				end 			end 		end 		return open 	end 	 	-- To get the closedlist 	local function closedlist() 		local closed = {} 		for x = 0, sizex do 			for y = 0, sizey do 				if Node[x][y].Closed then 					table.insert(closed,{x = x,y = y}) 				end 			end 		end 		return closed 	end 	 	-- Configurate Nodes 	for x = 0, sizex do 		Node[x] = {} 		for y = 0, sizey do 			NodeInfo = { 				Open = false, 				Closed = false, 				G = 0, 				H = Euclidean(x,y,tx,ty), 				parent = {} 			} 			function NodeInfo.F() 				return NodeInfo.G + NodeInfo.H 			end 			Node[x][y] = NodeInfo 		end 	end 	Node[fx][fy].Open = true 	 	local function FixedPath() 		local i = {x = tx,y = ty} 		local path = {} 		while Node[i.x][i.y].parent.x and Node[i.x][i.y].parent.y do 			local Details = { 				x = i.x, 				y = i.y, 				F = Node[i.x][i.y].F(), 				G = Node[i.x][i.y].G, 				H = Node[i.x][i.y].H 			} 			table.insert(path,Details) 			i = Node[i.x][i.y].parent 		end 		return path 	end 	 	while not table.empty(openlist()) do 		local lF = nil -- Lowest F node 		for k, v in pairs(openlist()) do 			if not lF or Node[v.x][v.y].F() < Node[lF.x][lF.y].F() then 				lF = v 				msg("F: "..Node[v.x][v.y].F().." - "..v.x.." "..v.y) 			end 		end 		msg("Lowest F: "..Node[lF.x][lF.y].F().." - "..lF.x.." "..lF.y) 		Node[lF.x][lF.y].Closed = true 		Node[lF.x][lF.y].Open = false 		curbase = lF 		 		if curbase.x == tx and curbase.y == ty then 			return FixedPath() 		end 		 		local NearNodes = {} 		local function AddNode(x,y) 			if not Node[x][y].Closed and Map[x][y] == 0 then 				table.insert(NearNodes,{x = x,y = y}) 			end 		end 		AddNode(curbase.x,curbase.y+1); AddNode(curbase.x+1,curbase.y) 		AddNode(curbase.x,curbase.y-1); AddNode(curbase.x-1,curbase.y) 		for k, v in pairs(NearNodes) do 			local score = Node[curbase.x][curbase.y].G + Euclidean(curbase.x,curbase.y,v.x,v.y) 			if not Node[v.x][v.y].Open then 				Node[v.x][v.y].Open = true 				Node[v.x][v.y].parent = curbase 				Node[v.x][v.y].G = score 				msg("Added Element: "..v.x.." "..v.y.." "..Node[v.x][v.y].F()) 			elseif score < Node[v.x][v.y].G then 				Node[v.x][v.y].parent = curbase 				Node[v.x][v.y].G = score 				msg("Added Element: "..v.x.." "..v.y.." "..Node[v.x][v.y].F()) 			end 		end 	end 	return nil, "Couldn't find the path" end
I tested it using this other part.
Spoiler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function string:split(b) 	local cmd = {} 	if type(self) == "string" then 	if not b then match = "[^%s]+" else match = "[^"..b.."]+" end 	for word in string.gmatch(self,match) do 			table.insert(cmd,word) 		end 	end 	return cmd end PathSprites = {} addhook("say","onSay") function onSay(id,txt) 	local s = txt:split() 	if s[1] == "mypos" then 		msg2(id,"X: "..player(id,"tilex").." Y: "..player(id,"tiley")) 	elseif s[1] == "path" then 		local fx,fy,tx,ty = tonumber(s[2]),tonumber(s[3]),tonumber(s[4]),tonumber(s[5]) 		if not fx or not fy or not tx or not ty then return 0 end 		local Map = {} 		for x = 0, map("xsize")+1 do 			Map[x] = {} 			for y = 0, map("ysize")+1 do 				if tile(x,y,"walkable") then 					Map[x][y] = 0 				else 					Map[x][y] = 1 				end 			end 		end 		local p,err = FindPath(Map,fx,fy,tx,ty) 		if p == nil or err then 			msg(err) 			if p == nil then 				return 0 			end 		end 		for k, img in pairs(PathSprites) do 			freeimage(img) 		end 		PathSprites = {} 		for k, v in pairs(p) do 			local img = image("gfx/sprites/block.bmp",0,1,1) 			imagepos(img,(v.x*32)+16,(v.y*32)+16,0) 			table.insert(PathSprites,img) 		end 	end end
Try to use it in de_dust, with the coords:
1
X: 37 Y: 4
1
X: 37 Y: 6
It will give you a wrong path, anyways its a walkable path.
My Opinion: I think at the part you search a low G cost, I made something wrong.