View Single Post
  #4  
Old 07-28-2004, 08:46 PM
Dach Dach is offline
call me Chad, it's cooler
Dach's Avatar
Join Date: Aug 2002
Posts: 1,899
Dach is on a distinguished road
red text added by Chad
Quote:
Originally Posted by sparkers
NPC Code:


if (created) {
setcharani popie,;
initialize();
setcharprop #P(1),hat#v(int(random(0,100))).png;//this should be done before calling the initialize function
}
if (timeout) {
if (this.found==0) {
for (i=-1;this.found==0;i+=1) {
this.found=1;
if (i>playerscount) i=-1;
}
}
if (this.found==1) {//don't make two separate timeout checks, redundancy is bad in scripts

if (abs(players[i].x-x)<=20&&abs(players[i].y-y)<=20) {
dir=getdir(players[i].x-x,players[i].y-y);
setcharani podies-walk,;
tx=players[i].x - x;
ty=players[i].y - y;
dist= (tx*tx+ty*ty)^0.5;
nx= (tx/dist)*1.2;
ny= (ty/dist)*1.2;
move nx,ny,1.2,4;
} else {setcharani podies,;message;this.found=0;timeout=.1}
if (players[i].x in |x-2,x+2|&&players[i].y in |y-2,y+2|) {
setcharani podies-attack,;
with(players[i]) {
setani hurt,;
playerhearts-=.5;
}
sleep .5;//sleep has been known to interrupt timeout loops
timeout=1;
}
}
timeout=.3;
}

if (waS**t) {
message;
setcharani podies,;
hearts-=.5;
message #v(hearts);
sleep 1;
checkdead();
}

if (actionprojectile&&!hearts<=0) {
message;setcharani podies-hurt,;
hearts-=strtofloat(#p(1))*2;
this.number=strtofloat(#p(1))*2;
if (this.number != 0) {
this.temp ++;
showtext 13,x,y-2*this.temp,veranda,r,#v(this.number);
if (this.temp = 4) this.number = 0;
}else{
hideimg 13;
this.temp = 0;
}
sleep 1;
checkdead();
}
function initialize() {
setcharani podies,;
setshape 1,50,50;
this.found=0;
hearts=30;
setcharani podies,;
timeout=.3;
}
function checkdead() {
if (hearts<=0) {
setcharani podies-dead,;
for(a=i;a<i+3;a++) {
with (players[a]) {//use a for loop with like operations
setplayerprop#c, I got some experience, yay!;
setstring client.playerexp,#v(strtofloat(#s(client.playerexp ))+3);
}
}
timeout = 0;
setcharani podies-dead,;
sleep 2;
hide;
sleep 30;
show;
initialize();
}
else timeout=.3;

}

as for the ani not showing, you are setting it over in the script, check to see if the ani is already set before resetting it

and please do follow the rules
edit: I didn't see that ! by the =, my bad
__________________
Scripting Documents:Old Script Documentation-Movement Tutorial

Last edited by Dach; 07-28-2004 at 09:32 PM..
Reply With Quote