Jump to content

[RELEASE] MTA:SA Pathfinding Module


StiviK

Recommended Posts

  • 1 month later...

An example script directly not, but here is it how i use it in my Gamemode:

function GPS:constructor()
	-- Check if module is loaded
	if not loadPathGraph then
		outputDebugString("GPS module not loaded. Continuing without...", 2)
		return
	end

	-- Load path graph
	self.m_GraphId = loadPathGraph("files/paths/sa_nodes.json")
end

function GPS:destructor()
	if unloadPathGraph then
		unloadPathGraph()
	end
end

function GPS:getRoute(callback, from, to)
	if not findShortestPathBetween then
		return false
	end
	return findShortestPathBetween(self.m_GraphId, from.x, from.y, from.z, to.x, to.y, to.z, callback)
end

 

  • Like 1
Link to comment

You should see a message like 'MODULE: Loaded "Pathfind Module" (1.00) by "Jusonex, StiviK"' in the console, otherwise it was not loaded!

Did you add it to your mtaserver.conf! Or try 'loadmodule ml_pathfind_TYPE.dll' in the console.

Link to comment

The return value of the function is a table with this structure: { { x1, y1, z1 }, { x2, y2, z2 }, ..., { xN, yN, zN } } (where N is the count of the used nodes in the Route)

 

@Jayceon are you trying to use the functions server-side or client-side?

Edited by StiviK
Link to comment
51 minutes ago, StiviK said:

The return value of the function is a table with this structure: { { x1, y1, z1 }, { x2, y2, z2 }, ..., { xN, yN, zN } } (where N is the count of the used nodes in the Route)

 

@Jayceon are you trying to use the functions server-side or client-side?

Already got it working but i've to say the test nodes are seriously messed up they literally take the shortest route which means for example at the greenwood hospital to the highway they will decide to directly jump of the edge to to highway and visa versa

This is what i've managed to create thanks to the module :D, i've to say that it isn't completed yet and is for from stable. I've to find a way to update the route without requesting too much peformance from the server or client. for example when someone doesn't follow the path.

6yozkh.png

Edited by Syntrax#
Link to comment
Just now, StiviK said:

Which graph did you use? You'r own? Or the sa_nodes from the repo? Ich think you messed up the edges.

i've used the sa_nodes one but i've to say i'm just looping most of the values not considering the edges etc what is  the meaning of those edges btw?

Link to comment

I mean the modules find's the neighbour node of a node by looking at the edges of a node. The edges of a node are defined in the graph, the defined edges are only realistic reachable nodes.

Which means if the Input graph (sa_nodes) is correct, what you described should not happen.

Edited by StiviK
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...