Jump to content

[RELEASE] MTA:SA Pathfinding Module


StiviK

Recommended Posts

  • 1 month later...
Posted

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
Posted

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.

Posted

I see the message in console.

I tried to add mtaconf. Start server and the module is loaded, and tried the loadmodule command but nothing changes. The functions dont work.

Posted (edited)

I've managed to generate the path and get the shortest route to your destination.Now my question is how to seperate those in x,y,z coordinates since i'm going to use the draw lines function

Edited by Syntrax#
Posted (edited)

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
Posted (edited)
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#
Posted
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?

Posted (edited)

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
Posted

I'm using it in client side, but tried it in server side. Every side return the "attempt to call" :/

I don't know what the problem. I'm using Windows 10 Pro 64 bit, MTA SA server 1.5.4. The console show the module successfully loaded.

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...