SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 31/03/2013, 09:28 PM   #1
pamdex
Little Clucker
 
pamdex's Avatar
 
Join Date: Jan 2010
Location: Poland
Posts: 40
Reputation: 79
Cool PathFinder by Pamdex

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:
http://forum.sa-mp.com/showthread.php?t=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.*******.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

Last edited by pamdex; 26/12/2015 at 10:04 PM.
pamdex is offline   Reply With Quote
Old 31/03/2013, 09:34 PM   #2
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,857
Reputation: 1292
Default Re: PathFinder 0.11v by Pamdex

Those RNPC bots look pretty crappy, is there anyway to improve their movement?
Pottus is offline   Reply With Quote
Old 31/03/2013, 09:50 PM   #3
pamdex
Little Clucker
 
pamdex's Avatar
 
Join Date: Jan 2010
Location: Poland
Posts: 40
Reputation: 79
Default Re: PathFinder 0.11v by Pamdex

You can improve the movement when you "clear" the route e.g. remove unnecessary points.
First video shows the bot without "clear".
__________________
...
pamdex is offline   Reply With Quote
Old 31/03/2013, 09:54 PM   #4
steki.
High-roller
 
steki.'s Avatar
 
Join Date: Nov 2010
Location: São Paulo, Brasil
Posts: 2,558
Reputation: 315
Default Re: PathFinder 0.11v by Pamdex

Oh, you. Sweet!
__________________
Rio
steki. is offline   Reply With Quote
Old 31/03/2013, 10:42 PM   #5
RebeloX
High-roller
 
RebeloX's Avatar
 
Join Date: Jul 2011
Location: Portugal
Posts: 2,173
Reputation: 442
Default Re: PathFinder 0.11v by Pamdex

Very nice
__________________
RebeloX is offline   Reply With Quote
Old 31/03/2013, 11:12 PM   #6
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,857
Reputation: 1292
Default Re: PathFinder 0.11v by Pamdex

Tried this out, but my zombies keep getting stuck on roofs, since I need to continually update the path to the player when that happens the path calculation keeps calculating the same position. It's a cool plugin but still really buggy for zombies.
Pottus is offline   Reply With Quote
Old 31/03/2013, 11:19 PM   #7
oOFotherOo
Gangsta
 
oOFotherOo's Avatar
 
Join Date: May 2012
Location: Tokyo
Posts: 638
Reputation: 49
Default Respuesta: PathFinder 0.11v by Pamdex

Very nice.
oOFotherOo is offline   Reply With Quote
Old 31/03/2013, 11:34 PM   #8
Lorenc_
High-roller
 
Lorenc_'s Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 3,804
Reputation: 1160
Default Re: PathFinder 0.11v by Pamdex

You're the best. Thanks!
__________________
Join the best Cops And Robbers in SA-MP, today. svr.sfcnr.com:7777

Lorenc_ is offline   Reply With Quote
Old 31/03/2013, 11:39 PM   #9
CoaPsyFactor
Gangsta
 
Join Date: Jul 2010
Location: Belgrade, Serbia
Posts: 867
Reputation: 52
Default Re: PathFinder 0.11v by Pamdex

well, this doesn't looks like real path finder, how does it works with SAMP Nodes?
__________________
Quote:
Originally Posted by ThaiLuan View Post
Code:
C:\Users\Administrator\Downloads\Viet-RP\gamemodes\3mien.pwn(112016) : fatal error 101: cannot write to file: "disk full"

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
Help me! How to fix error
CoaPsyFactor is offline   Reply With Quote
Old 01/04/2013, 12:23 AM   #10
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,857
Reputation: 1292
Default Re: PathFinder 0.11v by Pamdex

Ok, some updates on the problem it would seem OnPathCalculated() doesn't even get called in some instances when attempting to calculate a path check out this output.


Update #1
[20:39:49] Iteration: 0 NodeID: 4688619 czyli X = -381.000000 Y = 2219.000000 Z = 41.090000
[20:39:49] Iteration: 1 NodeID: 4694620 czyli X = -380.000000 Y = 2218.000000 Z = 41.090000
[20:39:49] Iteration: 2 NodeID: 4700620 czyli X = -380.000000 Y = 2217.000000 Z = 41.090000
[20:39:49] Iteration: 3 NodeID: 4706620 czyli X = -380.000000 Y = 2216.000000 Z = 41.090000
[20:39:49] Iteration: 4 NodeID: 4712620 czyli X = -380.000000 Y = 2215.000000 Z = 41.090000
[20:39:49] Iteration: 5 NodeID: 4718620 czyli X = -380.000000 Y = 2214.000000 Z = 41.090000
[20:39:49] Iteration: 6 NodeID: 4724620 czyli X = -380.000000 Y = 2213.000000 Z = 41.090000
[20:39:49] X:-380.000000 Y:2216.000000 Z:41.090000 <---- Used Path Node

Update #2
[20:39:50] Iteration: 0 NodeID: 4700619 czyli X = -381.000000 Y = 2217.000000 Z = 41.090000
[20:39:50] Iteration: 1 NodeID: 4706618 czyli X = -382.000000 Y = 2216.000000 Z = 41.279998
[20:39:50] Iteration: 2 NodeID: 4712617 czyli X = -383.000000 Y = 2215.000000 Z = 41.369998
[20:39:50] Iteration: 3 NodeID: 4718616 czyli X = -384.000000 Y = 2214.000000 Z = 41.409999
[20:39:50] Iteration: 4 NodeID: 4724616 czyli X = -384.000000 Y = 2213.000000 Z = 41.419998
[20:39:50] X:-384.000000 Y:2214.000000 Z:41.409999 <---- Used Path Node
----------------------------------------------------- <---- No paths here PathFinder_FindWay() failed
[20:39:50] X:-384.000000 Y:2214.000000 Z:41.409999 <---- Keeps returning the same values since there is no new
[20:39:51] X:-384.000000 Y:2214.000000 Z:41.409999 path updates ("Failed") would be printed if
[20:39:51] X:-384.000000 Y:2214.000000 Z:41.409999 OnPathCalculated() was actually called
[20:39:52] X:-384.000000 Y:2214.000000 Z:41.409999
[20:39:52] X:-384.000000 Y:2214.000000 Z:41.409999
[20:39:52] X:-384.000000 Y:2214.000000 Z:41.409999
[20:39:53] X:-384.000000 Y:2214.000000 Z:41.409999
[20:39:53] X:-384.000000 Y:2214.000000 Z:41.409999

Paths stop being calculated, I'm guessing something is failing inside PathFinder_FindWay(); resulting in OnPathCalculated() not being called.

Edit - Continued doing tests and still the same problem keeps surfacing it's not calculating when using PathFinder_FindWay(); and isn't even calling OnPathCalculated() with a failed success obviously a bug.

Also noticed once nodes stop being calculated properly the plugin then fails completely and won't calculate any paths regardless of the values passed to PathFinder_FindWay();

Some more information:

This part of the code is on a 400 ms timer which keeps the Zombie following the player.

Code:
PathFinder_FindWay(zombie, zx, zy, x, y);
printf("X:%f Y:%f Z:%f", ZombieNextPos[zombie][0],ZombieNextPos[zombie][1],ZombieNextPos[zombie][2]);
Here is OnPathCalculated()

Code:
public OnPathCalculated(routeid,success,nodes[],nodes_size)
{
	if(success)
	{
		new Float:x,Float:y,Float:z;
		for(new i; i < nodes_size; i++)
		{
			PathFinder_GetNodePos(nodes[i],x,y,z);
			printf("Iteration: %d NodeID: %d Position X: %f Y: %f Z: %f",i,nodes[i],x,y,z);
		}

		if(nodes_size > 2) PathFinder_GetNodePos(nodes[2], ZombieNextPos[routeid][0], ZombieNextPos[routeid][1], ZombieNextPos[routeid][2]);
		else if(nodes_size > 1) PathFinder_GetNodePos(nodes[1], ZombieNextPos[routeid][0], ZombieNextPos[routeid][1], ZombieNextPos[routeid][2]);
		else PathFinder_GetNodePos(nodes[0], ZombieNextPos[routeid][0], ZombieNextPos[routeid][1], ZombieNextPos[routeid][2]);
	}
	else
	{
		print("Failed");
		GetPlayerPos(ZombieInfo[routeid][zplayerid], ZombieNextPos[routeid][0], ZombieNextPos[routeid][1], ZombieNextPos[routeid][2]);
	}
}

Last edited by Pottus; 01/04/2013 at 04:10 AM.
Pottus is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 01:05 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.