Code-x

Code-x Private Server
 
HomeHome  PortalPortal  SearchSearch  RegisterRegister  Log inLog in  

 

 follow player npc

Go down 
AuthorMessage
Evil Mage
Admin
Admin
Evil Mage

Number of posts : 432
Age : 28
Registration date : 2008-05-08

follow player npc Empty
PostSubject: follow player npc   follow player npc Icon_minitimeFri Aug 08, 2008 2:46 pm

public void FollowPlayer(int NPCID) {
int follow = npcs[NPCID].followPlayer;
int playerX = server.playerHandler.players[follow].absX;
int playerY = server.playerHandler.players[follow].absY;
npcs[NPCID].RandomWalk = false;
if(server.playerHandler.players[follow] != null)
{
if(playerY < npcs[NPCID].absY) {
npcs[NPCID].moveX = GetMove(npcs[NPCID].absX, playerX);
npcs[NPCID].moveY = GetMove(npcs[NPCID].absY, playerY+1);
}
else if(playerY > npcs[NPCID].absY) {
npcs[NPCID].moveX = GetMove(npcs[NPCID].absX, playerX);
npcs[NPCID].moveY = GetMove(npcs[NPCID].absY, playerY-1);
}
else if(playerX < npcs[NPCID].absX) {
npcs[NPCID].moveX = GetMove(npcs[NPCID].absX, playerX+1);
npcs[NPCID].moveY = GetMove(npcs[NPCID].absY, playerY);
}
else if(playerX > npcs[NPCID].absX) {
npcs[NPCID].moveX = GetMove(npcs[NPCID].absX, playerX-1);
npcs[NPCID].moveY = GetMove(npcs[NPCID].absY, playerY);
}
npcs[NPCID].getNextNPCMovement();
npcs[NPCID].updateRequired = true;
}
}
public void FollowPlayerCB(int NPCID, int playerID) {
int playerX = server.playerHandler.players[playerID].absX;
int playerY = server.playerHandler.players[playerID].absY;
npcs[NPCID].RandomWalk = false;
if(server.playerHandler.players[playerID] != null)
{
if(playerY < npcs[NPCID].absY) {
npcs[NPCID].moveX = GetMove(npcs[NPCID].absX, playerX);
npcs[NPCID].moveY = GetMove(npcs[NPCID].absY, playerY+1);
}
else if(playerY > npcs[NPCID].absY) {
npcs[NPCID].moveX = GetMove(npcs[NPCID].absX, playerX);
npcs[NPCID].moveY = GetMove(npcs[NPCID].absY, playerY-1);
}
else if(playerX < npcs[NPCID].absX) {
npcs[NPCID].moveX = GetMove(npcs[NPCID].absX, playerX+1);
npcs[NPCID].moveY = GetMove(npcs[NPCID].absY, playerY);
}
else if(playerX > npcs[NPCID].absX) {
npcs[NPCID].moveX = GetMove(npcs[NPCID].absX, playerX-1);
npcs[NPCID].moveY = GetMove(npcs[NPCID].absY, playerY);
}
npcs[NPCID].getNextNPCMovement();
npcs[NPCID].updateRequired = true;
}
}
public boolean IsInWorldMap(int coordX, int coordY) {
for (int i = 0; i < worldmap[0].length; i++) {
//if (worldmap[0][i] == coordX && worldmap[1][i] == coordY) {
return true;
//}
}
return false;
}
public boolean IsInWorldMap2(int coordX, int coordY) {
for (int i = 0; i < worldmap2[0].length; i++) {
if (worldmap2[0][i] == coordX && worldmap2[1][i] == coordY) {
return true;
}
}
return false;
}

public boolean IsInRange(int NPCID, int MoveX, int MoveY) {
int NewMoveX = (npcs[NPCID].absX + MoveX);
int NewMoveY = (npcs[NPCID].absY + MoveY);
if (NewMoveX <= npcs[NPCID].moverangeX1 && NewMoveX >= npcs[NPCID].moverangeX2 && NewMoveY <= npcs[NPCID].moverangeY1 && NewMoveY >= npcs[NPCID].moverangeY2) {
if ((npcs[NPCID].walkingType == 1 && IsInWorldMap(NewMoveX, NewMoveY) == true) || (npcs[NPCID].walkingType == 2 && IsInWorldMap2(NewMoveX, NewMoveY) == false)) {
if (MoveX == MoveY) {
if ((IsInWorldMap(NewMoveX, npcs[NPCID].absY) == true && IsInWorldMap(npcs[NPCID].absX, NewMoveY) == true) || (IsInWorldMap2(NewMoveX, npcs[NPCID].absY) == false && IsInWorldMap2(npcs[NPCID].absX, NewMoveY) == false)) {
return true;
}
return false;
}
return true;
}
}
return false;
Back to top Go down
 
follow player npc
Back to top 
Page 1 of 1
 Similar topics
-
» looking for Soundwave MP3 Player Sonic White Version
» Which chess player beat the most World Champions?
» Play Three Chess for Three player
» 2 player game idea for fantage
» How many Mybrute Members

Permissions in this forum:You cannot reply to topics in this forum
Code-x :: General Chat :: runescape private [TUT] section-
Jump to: