PDA

View Full Version : [508] Proper NPC Following - Converted (64base string)



Faab234
June 18th, 2010, 11:26
NPC Following, 64base string.


Video(also shows my noclip filter for NPCs):View My Video (Only the registered members can see the link.)

Add this in NPC:


public void followPlayer(Player p)
{
if (p == null) return;
NPC n = this;
if (n == null) return;
int j = p.absX, k = p.absY, l = n.absX, m = n.absY;
NPCMovement o = Engine.npcMovement;
int followType = 0;
boolean equalX = (j == l), equalY = (k == m), lowerX = (j < l), lowerY = (k < m), higherX = (j > l), higherY = (k > m);
if (followType <= 0)
{
if (equalX) n.moveX = 0;
else if (lowerX) n.moveX = getWalkDir(l, j + 1 + n.getSize());
else if (higherX) n.moveX = getWalkDir(l, j - 1 + n.getSize());
if (equalY && (equalX || lowerX || higherX)) n.moveY = 0;
else if (lowerY && (equalX || lowerX || higherX)) n.moveY = getWalkDir(k, m + 1 + n.getSize());
else if (higherY && (equalX || lowerX || higherX)) n.moveY = getWalkDir(k, m - 1 + n.getSize());
long totalX = Math.round(Math.pow(difference(j, l), 2)), totalY = Math.round(Math.pow(difference(k, m), 2));
if (lowerY) n.moveY = -1 + (n.getSize());
if (higherY) n.moveY = 1 + (n.getSize());
requestFaceCoords(j, k);
}
o.getNextNPCMovement(n);
}
public int getSize()
{
switch (npcType)
{
case 6830 :
case 6832 :
return 1;
default :
return 0;
}
}
public boolean followingPlayer = false;
public int followPlayer = 0;
public int difference(int x, int x1)
{
return (x - x1);
}
private int getWalkDir(int pos, int pos2)
{
if ((pos - pos2) == 0) return 0;
if ((pos - pos2) < 0) return 1;
return (pos - pos2 > 0 ? -1 : 0);
}
/**
* Starts following a player..
* @param p The player to start following..
*/
public void startFollowing(Player p)
{
if (p == null || p.isDead || !p.online) return;
followPlayer = p.playerId;
followingPlayer = true;
}


In process:


if (followingPlayer)
{
/* Catch FireFox connection probs
* Still catching..
*Proxy-Connection: keep-alive
%Proxy-Connection: keep-alive
Cache-Control: max-age=0

Cache-Control: max-age=0

caught it?
*/
if (Engine.players[followPlayer] != null) followPlayer(Engine.players[followPlayer]);
}


There you go NPC Following..


Usage:


n.startFollowing(p);/* W/e I don't know how your crap servers are :P */

jamie
June 19th, 2010, 05:26
Merci Faab. as they say in france.

Nathan'
June 19th, 2010, 05:34
muchos gracias as they say in spain

Faab234
June 19th, 2010, 09:29
"Goed gedaan" as they said in the netherlands.

Canownueasy`
June 19th, 2010, 10:20
Very, very, very good job! Used for my 474 :p

Faab234
June 19th, 2010, 10:35
Very, very, very good job! Used for my 474 :p

Do you release it?

on Topic:

Thanks.