31.03.2013, 21:28
(
Last edited by pamdex; 26/12/2015 at 10:04 PM.
)
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.
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
Parameters:
Warning! When route calculation fails nodesX[], nodesY[], nodesZ[] has only one index with value = -1 (nodes_size is 1).
Warning!
If you want to use it to teleport, bots etc. just add 1.0 to Z.
Natives
PathFinder_Init
Parameters:
PathFinder_FindWay
Parameters:
PathFinder_MapAndreasLock
This function freezes path calculation, so you can use normal MapAndreas natives without problems with threads safety.
Example usage:
PathFinder_MapAndreasUnlock
This function unlock path calculation.
PathFinder_SetTickRate
Parameters:
Using in PAWN
New version of PathFinder is based on MapAndreas 1.2.1 class integration code. So initialisation code must looks like that:
Warning!
Video
[ame]http://www.youtube.com/watch?v=VtmWDnRoSSg[/ame]
Description:
Download & Source
PathFinder 1.0 MT:
https://bitbucket.org/Pamdex/pathfinder/downloads
Changelog:
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:
InstallationYou 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)
- 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
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!
Quote:
The Z return value is accurate to within a few centimetres from the actual ground surface position |
Natives
PathFinder_Init
Code:
PathFinder_Init(mapAndreasAddress, threads = 1);
- mapAndreasAddress <- mem address of CMapAndreas class (see "Using in PAWN")
- threads <- number of threads (more threads = more paths are calculated at the same time)
PathFinder_FindWay
Code:
PathFinder_FindWay(routeid, Float:startX, Float:startY, Float:endX, Float:endY, Float:zDifference = 0.9, stepSize = 1, stepLimit = -1, maxSteps = 2000);
- 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.
PathFinder_MapAndreasLock
Code:
PathFinder_MapAndreasLock();
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();
Code:
PathFinder_MapAndreasUnlock();
PathFinder_SetTickRate
Code:
PathFinder_SetTickRate(rate = 5);
- rate
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; }
Quote:
PathFinder only works with MAP_ANDREAS_MODE_FULL and MAP_ANDREAS_MODE_NOBUFFER ! |
[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
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