![Old](images/statusicon/post_old.gif)
02-01-2002, 08:38 PM
|
Registered User
|
Join Date: Jan 2002
Posts: 141
|
|
Really Need Help
How do i get this NPC to NOT hit a playerwhit account name
Mosquito online?
// Graal2001 NPC by Stefan Knorr
if (created) {
// Initialize the attributes
showcharacter;
setcharprop #3,head0.png;
setcharprop #C0,orange;
setcharprop #C1,white;
setcharprop #C2,blue;
setcharprop #C3,red;
setcharprop #C4,black;
setcharprop #2,shield1.gif;
shieldpower = 1;
dir = 2;
swordpower = 3;
}
if (playerenters || wasthrown) {
// Initialize the this. variables
message;
this.huntspeed = 0.5;
timeout = 0.05;
this.mode = 0;
setcharani idle,;
this.runcounter = int(random(10,40));
}
// Sword attacking stuff
if (timeout && (this.mode==0 || this.mode==2)) {
// Look for players
mindist = 1000;
for (i=0; i<playerscount; i++)
if (players[i].hearts>0 && players[i].id>=0) {
dx = players[i].x - x;
dy = players[i].y - y;
if (abs(dx)>abs(dy)) {
if (dx>0) pdir=3; else pdir=1;
} else {
if (dy>0) pdir=2; else pdir=0;
}
if (pdir==dir) {
dist = (dx*dx+dy*dy)^0.5;
if (dist<mindist) {
cansee = 1;
if (abs(dx)>abs(dy)) k = int(abs(dx));
else k = int(abs(dy));
for (j=0; j<=k-2; j++)
if (onwall(x+1.5+dx*j/k,y+2+dy*j/k)) cansee = 0;
if (cansee!=0) {
mindist = dist;
aimplayer = i;
this.aimx = players[i].x;
this.aimy = players[i].y;
}
}
}
}
if (mindist<=3) {
this.runcounter = -1;
this.mode = 3; // SLAYING
setcharani sword,;
timeout = 0.05;
} else if (mindist<20) {
if (this.mode!=2) message Stop!;
this.runcounter = 100;
this.mode = 2; // HUNTING
} else timeout = 0.05;
}
if (timeout && this.mode==3) { // SLAYING
this.runcounter++;
if (this.runcounter>4) {
this.runcounter = 100;
this.mode = 2; // HUNTING
setcharani idle,;
}
message;
timeout = 0.05;
}
if (timeout && this.mode==2) { // HUNTING
setcharani walk,;
this.runcounter--;
if (this.runcounter>0 && aimplayer<playerscount && players[aimplayer].hearts>0) {
// Get new direction
dx = players[aimplayer].x-x;
dy = players[aimplayer].y-y;
if (abs(dx)>abs(dy)) {
if (dx>0) dir=3; else dir=1;
} else {
if (dy>0) dir=2; else dir=0;
}
// Test if we can do a step
dx = this.aimx-x;
dy = this.aimy-y;
if (abs(dx)<=1 && abs(dy)<=1) {
this.aimx = players[aimplayer].x;;
this.aimy = players[aimplayer].y;
dx = this.aimx-x;
dy = this.aimy-y;
}
if (abs(dx)>abs(dy)) {
if (dx>0) testdir=3; else testdir=1;
} else {
if (dy>0) testdir=2; else testdir=0;
}
len = (dx*dx+dy*dy)^0.5;
addx = (dx/len)*this.huntspeed;
addy = (dy/len)*this.huntspeed;
testx = x + 1.5;
testy = y + 2;
if (!onwall(testx+addx,testy+addy)) {
// Do a step
x += addx;
y += addy;
} else if (!onwall(testx+addx,testy)) x += addx;
else if (!onwall(testx,testy+addy)) y += addy;
} else {
this.mode = 0; // WALKING
this.walkmode = 1; // RANDOM
this.runcounter = int(random(10,40));
setcharani idle,;
dir = (dir+2)%4;
message;
}
timeout = 0.05;
} |
|
|