Quote:
why not if(n_mapAndreas > n_Z) ?
|
For does not bug occur with small increases!
Quote:
Problems with this
pawn Code:
MapAndreas_FindZ_For2DCoord(p_X, p_Y, p_mapAndreas);
that is called pretty early in the movie... (should be called after the height check)
|
Oh Yeap, thanks !! (I had not noticed haha
)
pawn Код:
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:b_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);
b_A = atan2(n_Y - p_Y, n_X - p_X);
if(pathFind[npcid][nX] == 0.0 && pathFind[npcid][nY] == 0.0) {
MoveRNPC(npcid, p_X, p_Y, p_Z, 0.0065);
n_X += (5.0 * floatsin(-n_A, degrees)),
n_Y += (5.0 * floatcos(-n_A, degrees));
MapAndreas_FindZ_For2DCoord(n_X, n_Y, n_mapAndreas);
if(n_mapAndreas - n_Z > 2.5) {
MapAndreas_FindZ_For2DCoord(p_X, p_Y, p_mapAndreas);
// possibility of have building on front off npcid
if( (p_Z != n_mapAndreas) && (n_mapAndreas != p_mapAndreas ) ) {
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 += 4.5;
// here right, left side.
// need fix (working +- haha :p)
if(b_A > 180.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));
}
else {
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);
if(p_mapAndreas != b_Z) {
SendClientMessageToAll(-1, "I FIND ALTERNATIVE PATH");
MoveRNPC(npcid, b_X, b_Y, p_mapAndreas, 0.0065);
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;
}
I'm thinking of something interesting. On putting +90-90 it create a triangle:
The invalid path is hypotenuse and the "adjacent" side will always be the new path (interestingly, it is this part, is the size of the construction ..
)
I tested a lot, it works with buildings. The problem is that if the NPC is under one roof and the player not. The NPC BUG, or stairs for example
The algorithm is correct, but there are exceptions in San Andreas. I think one way to deal with these exceptions, is to check a given area is a building.
For checking a point is a building. I think we do four points and check MapAndreas Z POS, if the same Z POS in four points. Yes, is a building
Example:
PHP код:
static
Float:4points,
i,
Float:zPoint;
for(i = 0; i != 4; i++) {
pontoX = edificioX + (5.0 * floatsin(-90.0 * i, degrees)),
pontoY = edificioY +(5.0 * floatcos(-90.0 * i, degrees));
MapAndreas_FindZ_For2DCoord(pontoX, pontoY, zPoint);
4points += zPoint;
}
if(floatround(4points) % 90 == 0) {
// 4 points have the same MapAndreas Z Pos
// x
// x x
// x
// 5 * 4 = 20 metters
}