[Plugin] PathFinder by Pamdex
#1

PathFinder 1.0 MT by Pamdex

Description:
This plugin allows you to calculate a route from point A to B on the San Andreas map.
It uses the built-in MapAndreas 1.2.1 class integration and Djikstra styled algorithm, so you can calculate routes everywhere (not in water).
It also uses separate thread for path calculation.

Dijkstra:

Installation
You must have MapAndreas 1.2.1:
https://sampforum.blast.hk/showthread.php?tid=275492

You have to add PathFinder and MapAndreas to "plugins" line (MapAndreas at the end) in server.cfg. Also you have to put MapAndreas and PathFinder libraries in "plugins" folder.

Callbacks
OnPathCalculated
Code:
OnPathCalculated(routeid, success, Float:nodesX[], Float:nodesY[], Float:nodesZ[], nodesSize)
Parameters:
  • routeid <- ID of calculated path
  • success <- returns true or false
  • nodesX[] <- positions X of nodes
  • nodesY[] <- positions Y of nodes
  • nodesZ[] <- positions Z of nodes
  • nodes_size <- returns amount of nodes
Example usage:
Code:
new text[128];
public OnPathCalculated(routeid, success, Float:nodesX[], Float:nodesY[], Float:nodesZ[], nodesSize)
{
	format(text, sizeof(text), "PATH: route: %d success: %d nodesSize: %d", routeid, success, nodesSize);
	SendClientMessageToAll(-1, text);
	if(success)
	{
		for(new i; i < nodesSize; i++)
	    	{
			CreateDynamicObject(19130, nodesX[i], nodesY[i], nodesZ[i] + 1, 0, 0, 0);
    		}
    		Streamer_Update(0);
	}
	return 1;
}
Warning! When route calculation fails nodesX[], nodesY[], nodesZ[] has only one index with value = -1 (nodes_size is 1).
Warning!
Quote:

The Z return value is accurate to within a few centimetres from the actual ground surface position

If you want to use it to teleport, bots etc. just add 1.0 to Z.

Natives
PathFinder_Init
Code:
PathFinder_Init(mapAndreasAddress, threads = 1);
Parameters:
  • mapAndreasAddress <- mem address of CMapAndreas class (see "Using in PAWN")
  • threads <- number of threads (more threads = more paths are calculated at the same time)
This function setups the plugin (is required).

PathFinder_FindWay
Code:
PathFinder_FindWay(routeid, Float:startX, Float:startY, Float:endX, Float:endY, Float:zDifference = 0.9, stepSize = 1, stepLimit = -1, maxSteps = 2000);
Parameters:
  • routeid <- path ID
  • start_x <- start X position
  • start_y <- start Y position
  • end_x <- end X position
  • end_y <- end Y position
  • zDifference <- maximum Z difference between nodes (used in path calculating)
  • stepSize <- size of step (used in path calculating)
  • stepLimit <- steps limit for path calculation. If you set here -1, plugin works in normal mode (without step limit). If path calculating reaches this limit, calculating stops and plugin returns path (max return path size = limit + 1)
  • maxSteps <- main step limit. If path calculating reaches this limit, calculating fails.
This function starts path calculation from point A to point B.

PathFinder_MapAndreasLock
Code:
PathFinder_MapAndreasLock();
This function freezes path calculation, so you can use normal MapAndreas natives without problems with threads safety.

Example usage:
Code:
new Float:z;
PathFinder_MapAndreasLock(); //Block PathFinder...

//Do MapAndreas command or smth else like RNPC (with MapAndreas class sharing)
for(new i = 0; i < 1000; i++)
{
	MapAndreas_FindZ_For2DCoord(random(6000) - 3000, random(6000) - 3000, z);
	format(text, sizeof(text), "%d -> %f", i, z);
	SendClientMessageToAll(-1, text);
}
PathFinder_MapAndreasUnlock();
PathFinder_MapAndreasUnlock
Code:
PathFinder_MapAndreasUnlock();
This function unlock path calculation.

PathFinder_SetTickRate
Code:
PathFinder_SetTickRate(rate = 5);
Parameters:
  • rate
This function sets tick rate for thread communication. Default value is 10 (10 * 5ms update). Plugin uses tick rate only for outputting calculated ways (not for calculating).

Using in PAWN
New version of PathFinder is based on MapAndreas 1.2.1 class integration code. So initialisation code must looks like that:
Code:
#include <MapAndreas>
#include <PathFinder>
public OnFilterScriptInit()
{
	MapAndreas_Init(MAP_ANDREAS_MODE_FULL);
	PathFinder_Init(MapAndreas_GetAddress());
	return 1;
}
Warning!
Quote:

PathFinder only works with MAP_ANDREAS_MODE_FULL and MAP_ANDREAS_MODE_NOBUFFER !

Video
[ame]http://www.youtube.com/watch?v=VtmWDnRoSSg[/ame]
Description:
  • /path_test - normal path calculation from player location to selected location
  • /path_test_size - normal path calculation from player location to selected location with stepSize = 2
  • /path_test_limit - normal path calculation from player location to selected location with stepLimit = 30
  • /path_test_limit_50 - normal path calculation from player location to random location with stepLimit = 10 repeated 50 times
Tested on Intel Core i7-4790K 4.00GHz and 8GB RAM 2400MHz

Download & Source
PathFinder 1.0 MT:
https://bitbucket.org/Pamdex/pathfinder/downloads

Changelog:
  • 0.11v <- first release
  • 0.12v <- added new "param" to PathFinder_Init and bug-fix
  • 0.13v <- added new "param" to PathFinder_FindWay
  • 0.14v <- added new function PathFinder_SetTickRate and little bug-fix
  • 1.0 RC 2 <- completely rewritten code
  • 1.0 MT <- multi-thread version of PathFinder
Reply


Messages In This Thread
PathFinder by Pamdex - by pamdex - 31.03.2013, 21:28
Re: PathFinder 0.11v by Pamdex - by Pottus - 31.03.2013, 21:34
Re: PathFinder 0.11v by Pamdex - by pamdex - 31.03.2013, 21:50
Re: PathFinder 0.11v by Pamdex - by steki. - 31.03.2013, 21:54
Re: PathFinder 0.11v by Pamdex - by RebeloX - 31.03.2013, 22:42
Re: PathFinder 0.11v by Pamdex - by Pottus - 31.03.2013, 23:12
Respuesta: PathFinder 0.11v by Pamdex - by oOFotherOo - 31.03.2013, 23:19
Re: PathFinder 0.11v by Pamdex - by Lorenc_ - 31.03.2013, 23:34
Re: PathFinder 0.11v by Pamdex - by CoaPsyFactor - 31.03.2013, 23:39
Re: PathFinder 0.11v by Pamdex - by Pottus - 01.04.2013, 00:23
Re: PathFinder 0.11v by Pamdex - by cyber_punk - 01.04.2013, 04:26
Re: PathFinder 0.11v by Pamdex - by Pottus - 01.04.2013, 04:46
Re: PathFinder 0.11v by Pamdex - by pamdex - 01.04.2013, 07:10
Re: PathFinder 0.11v by Pamdex - by RajatPawar - 01.04.2013, 08:09
Re: PathFinder 0.11v by Pamdex - by AIped - 01.04.2013, 08:13
Re: PathFinder 0.12v by Pamdex - by pamdex - 01.04.2013, 08:35
Re: PathFinder 0.11v by Pamdex - by Pottus - 01.04.2013, 09:09
Re: PathFinder 0.11v by Pamdex - by Kyle - 01.04.2013, 09:56
Re: PathFinder 0.11v by Pamdex - by Niko_boy - 01.04.2013, 10:16
Re: PathFinder by Pamdex - by TheArcher - 01.04.2013, 10:44
Re: PathFinder 0.11v by Pamdex - by Lorenc_ - 01.04.2013, 11:42
Re: PathFinder by Pamdex - by Mauzen - 01.04.2013, 13:05
Re: PathFinder by Pamdex - by AIped - 01.04.2013, 15:59
Re: PathFinder by Pamdex - by pamdex - 01.04.2013, 16:38
Re: PathFinder by Pamdex - by AIped - 01.04.2013, 16:52
Re: PathFinder by Pamdex - by pamdex - 01.04.2013, 17:07
Re: PathFinder by Pamdex - by AIped - 02.04.2013, 09:28
Re: PathFinder by Pamdex - by TheArcher - 02.04.2013, 11:57
Re: PathFinder by Pamdex - by pamdex - 02.04.2013, 12:05
Re: PathFinder by Pamdex - by TheArcher - 02.04.2013, 12:13
AW: PathFinder by Pamdex - by Blackazur - 02.04.2013, 12:26
Re: PathFinder by Pamdex - by justinnater - 02.04.2013, 13:02
Re: PathFinder by Pamdex - by DoctorRapist - 02.04.2013, 14:19
Re: PathFinder by Pamdex - by AIped - 02.04.2013, 18:23
Re: PathFinder by Pamdex - by TheArcher - 02.04.2013, 18:57
Re: PathFinder by Pamdex - by pamdex - 02.04.2013, 19:07
Re: PathFinder by Pamdex - by Pottus - 02.04.2013, 23:14
Re: PathFinder by Pamdex - by Gamer_Z - 03.04.2013, 00:15
Re: PathFinder by Pamdex - by Kar - 03.04.2013, 01:11
Re: PathFinder by Pamdex - by Pottus - 03.04.2013, 01:28
Re: PathFinder by Pamdex - by AIped - 03.04.2013, 06:54
Re: PathFinder by Pamdex - by Gamer_Z - 03.04.2013, 07:00
Re: PathFinder by Pamdex - by AIped - 03.04.2013, 08:21
Re: PathFinder by Pamdex - by Babul - 03.04.2013, 10:07
Re: PathFinder by Pamdex - by Pottus - 03.04.2013, 11:23
Re: PathFinder by Pamdex - by TheArcher - 03.04.2013, 11:39
Re: PathFinder by Pamdex - by AIped - 03.04.2013, 12:00
Re: PathFinder by Pamdex - by [FSaF]Jarno - 03.04.2013, 13:00
Re: PathFinder by Pamdex - by AIped - 03.04.2013, 13:05
Re: PathFinder by Pamdex - by AIped - 03.04.2013, 13:09
Re: PathFinder by Pamdex - by Y_Less - 03.04.2013, 13:39
Re: PathFinder by Pamdex - by AIped - 03.04.2013, 13:53
Re: PathFinder by Pamdex - by pamdex - 03.04.2013, 13:58
Re: PathFinder by Pamdex - by Y_Less - 03.04.2013, 14:02
Re: PathFinder by Pamdex - by Pottus - 03.04.2013, 14:23
Re: PathFinder by Pamdex - by smiiir - 03.04.2013, 15:30
Re: PathFinder by Pamdex - by TheArcher - 03.04.2013, 16:49
Re: PathFinder by Pamdex - by pamdex - 18.04.2013, 13:16
Re: PathFinder by Pamdex - by iMads - 23.04.2013, 11:50
Re: PathFinder by Pamdex - by PT - 23.04.2013, 11:54
Re: PathFinder by Pamdex - by Y_Less - 23.04.2013, 12:06
Re: PathFinder by Pamdex - by Gamer_Z - 23.04.2013, 12:51
Re: PathFinder by Pamdex - by pamdex - 28.04.2013, 18:55
Re: PathFinder by Pamdex - by Mauzen - 04.08.2014, 22:16
Re: PathFinder by Pamdex - by pamdex - 05.08.2014, 00:03
Re: PathFinder by Pamdex - by pamdex - 15.10.2014, 20:34
Re: PathFinder by Pamdex - by Pottus - 15.10.2014, 20:36
Re: PathFinder by Pamdex - by RiqueP - 15.10.2014, 23:06
Re: PathFinder by Pamdex - by pamdex - 19.10.2014, 17:23
Re: PathFinder by Pamdex - by iFarbod - 19.10.2014, 17:57
Re: PathFinder by Pamdex - by pamdex - 19.10.2014, 18:00
Re: PathFinder by Pamdex - by iFarbod - 19.10.2014, 18:39
Re: PathFinder by Pamdex - by Mauzen - 19.10.2014, 18:44
Re: PathFinder by Pamdex - by Riddick94 - 19.10.2014, 19:44
Re: PathFinder by Pamdex - by Mauzen - 19.10.2014, 21:33
Re: PathFinder by Pamdex - by Mauzen - 27.10.2014, 21:42
Re: PathFinder by Pamdex - by Mauzen - 28.10.2014, 01:13
Re: PathFinder by Pamdex - by pamdex - 12.11.2014, 09:42
Re: PathFinder by Pamdex - by Mauzen - 17.11.2014, 17:40
Re: PathFinder by Pamdex - by Crayder - 24.11.2014, 23:43
Re: PathFinder by Pamdex - by Pottus - 25.11.2014, 00:21
Re: PathFinder by Pamdex - by juank - 25.11.2014, 05:02
Re: PathFinder by Pamdex - by pamdex - 24.03.2015, 20:47
Re: PathFinder by Pamdex - by KayJ - 25.03.2015, 03:59
Re: PathFinder by Pamdex - by pamdex - 11.05.2015, 13:58
Re: PathFinder by Pamdex - by Pottus - 11.05.2015, 18:06
Re: PathFinder by Pamdex - by AIped - 11.05.2015, 18:15
Re: PathFinder by Pamdex - by pamdex - 17.05.2015, 17:10
Re: PathFinder by Pamdex - by n0minal - 17.05.2015, 17:13
Re: PathFinder by Pamdex - by liinor - 23.12.2015, 21:40
Re: PathFinder by Pamdex - by pamdex - 26.12.2015, 21:59
Re: PathFinder by Pamdex - by Stump - 14.04.2016, 08:44
Re: PathFinder by Pamdex - by pamdex - 15.04.2016, 16:46
Re: PathFinder by Pamdex - by Stump - 15.04.2016, 17:08
Re: PathFinder by Pamdex - by pamdex - 15.04.2016, 17:26
Re: PathFinder by Pamdex - by Stump - 15.04.2016, 17:37
Re: PathFinder by Pamdex - by Stump - 23.04.2016, 07:50
Re: PathFinder by Pamdex - by pamdex - 23.04.2016, 09:42
Re: PathFinder by Pamdex - by Stump - 23.04.2016, 11:54
Re: PathFinder by Pamdex - by pamdex - 23.04.2016, 19:39
Re: PathFinder by Pamdex - by Stump - 24.04.2016, 06:59
Re: PathFinder by Pamdex - by ExTaZZ69 - 24.04.2016, 19:47
Re: PathFinder by Pamdex - by Skream - 26.09.2017, 13:59
Re: PathFinder by Pamdex - by MrStead - 30.07.2018, 19:12
Re: PathFinder by Pamdex - by tandytanz - 26.12.2018, 11:29
Re: PathFinder by Pamdex - by pamdex - 12.01.2019, 14:02
Re: PathFinder by Pamdex - by Pottus - 12.01.2019, 18:54
Re: PathFinder by Pamdex - by Crayder - 12.01.2019, 21:28
Re: PathFinder by Pamdex - by Pottus - 12.01.2019, 23:26
Re: PathFinder by Pamdex - by MrStead - 16.01.2019, 16:53

Forum Jump:


Users browsing this thread: 1 Guest(s)