pawn Код:
// This is a proof conception (possibly algorithm to find path !!)
enum info { Float:nX, Float:nY, Float:nZ };
new pathFind[MAX_ZUMBIS][info];
OnUpdate(playerid, npcid);
public OnUpdate(playerid, npcid) {
static
Float:p_X,
Float:p_Y,
Float:p_Z,
Float:n_X,
Float:n_Y,
Float:n_Z,
Float:n_A,
Float:p_mapAndreas,
Float:n_mapAndreas;
GetPlayerPos(playerid, p_X, p_Y, p_Z);
GetPlayerPos(npcid, n_X, n_Y, n_Z);
GetPlayerFacingAngle(npcid, n_A);
if(pathFind[npcid][nX] == 0.0 && pathFind[npcid][nY] == 0.0) {
MoveRNPC(npcid, p_X, p_Y, p_Z, 0.0115);
n_X += (5.0 * floatsin(-n_A, degrees)),
n_Y += (5.0 * floatcos(-n_A, degrees));
MapAndreas_FindZ_For2DCoord(p_X, p_Y, p_mapAndreas);
MapAndreas_FindZ_For2DCoord(n_X, n_Y, n_mapAndreas);
if(n_mapAndreas - n_Z > 2.5) {
// possibility of have building on front off npcid
if(p_Z != n_mapAndreas && p_mapAndreas - n_mapAndreas > 1.5) {
SendClientMessageToAll(-1, "I FIND BUILDING OF FRONT NPC"); //debug
// have building in front off player ..
static
Float:n_Deg, Float:b_X, Float:b_Y, Float:b_Z;
n_Deg = 0;
// round for find alternative path (right side) (made you left side :mrgreen:)
n_X -= (5.0 * floatsin(-n_A, degrees)),
n_Y -= (5.0 * floatcos(-n_A, degrees));
while(n_Deg < 90.0) {
n_Deg += 5.0;
b_X = n_X + (10.0 * floatsin(-n_A+n_Deg, degrees)),
b_Y = n_Y + (10.0 * floatcos(-n_A+n_Deg, degrees));
MapAndreas_FindZ_For2DCoord(b_X, b_Y, b_Z);
b_Z = p_Z;
if(p_mapAndreas != n_mapAndreas) {
SendClientMessageToAll(-1, "I FIND ALTERNATIVE PATH IN RIGHT SIDE"); //debug
MoveRNPC(npcid, b_X, b_Y, p_mapAndreas, 0.0115);
pathFind[npcid][nX] = b_X;
pathFind[npcid][nY] = b_Y;
pathFind[npcid][nZ] = b_Z;
}
}
}
}
}
else {
if(IsPlayerInRangeOfPoint(npcid, 1.0, pathFind[npcid][nX], pathFind[npcid][nY], pathFind[npcid][nZ])) {
pathFind[npcid][nX] = 0.0;
pathFind[npcid][nY] = 0.0;
pathFind[npcid][nZ] = 0.0;
MoveRNPC(npcid, p_X, p_Y, p_Z, 0.0115);
}
}
return true;
}