Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   NPC not dieing at 0.5 (https://forums.graalonline.com/forums/showthread.php?t=134267041)

VeriApplez 08-26-2012 06:35 PM

NPC not dieing at 0.5
 
Um, Ive been trying to figure out when ever I make an NPC to fight I hit it and its health goes down, but at 0.5 it just stays there even when I hit it does not do anything. So I wanted to come here and see if you guys know why:confused:
PHP Code:

// Graal2002 NPC by Stefan Knorr
if (created) {
  
// Initialize the attributes
  
showcharacter;
  
setcharprop #3,head20.png;
  
setcharprop #C0,yellow;
  
setcharprop #C1,yellow;
  
setcharprop #C2,white;
  
setcharprop #C3,brown;
  
setcharprop #C4,black;
  
setcharprop #n,London;
  
dir 2;
  
swordpower 1;
  
hurtdx 0;
  
hurtdy 0;
  
hearts 3;
}
if (
playerenters || wasthrown) {
  
// Initialize the this. variables
  
message;
  
this.huntspeed 0.4;
  
timeout 0.05;
  
this.walkmode 1;
  if (
wasthrown && this.walkmode>1this.walkmode 1;
  
this.x1 0;
  
this.x2 63;
  
this.y1 0;
  
this.y2 63;
  
this.speed 0.3;
  if (
hearts<=0) {
    
this.mode 5// RESPAWN
    
this.runcounter 0;
    
timeout 5;
  } else {
    
this.mode 0;
    
setcharani idle,;
    
this.runcounter int(random(10,40));
  }
}

// Walking stuff
if (timeout && this.mode==0) { // WALKING
  
setcharani walk,;
  
newx vecx(dir)*this.speed;
  
newy vecy(dir)*this.speed;
  
this.runcounter--;
  if (
this.walkmode==1) { // RANDOM
    
if (this.runcounter>0) {
      
testx newx 1.5 vecx(dir);
      
testy newy vecy(dir);
      if (
onwall(testx,testy)) {
        
dir = (dir+2)%4;
        
this.runcounter int(random(0,60));
      } else {
        
newx;
        
newy;
      }
    } else {
      
this.runcounter int(random(10,40));
      
dir = (dir+1+int(random(0,2))*2)%4;
    }
  } else if (
this.walkmode==2) { // LEFTRIGHT
    
if (dir!=&& dir!=3dir 3;
    else {
      
newx;
      
newy;
      if ((
dir==&& x<=this.x1) || (dir==&& x>=this.x2))
        
dir = (dir+2)%4;
    }
  } else if (
this.walkmode==3) { // UPDOWN
    
if (dir!=&& dir!=2dir 2;
    else {
      
newx;
      
newy;
      if ((
dir==&& y<=this.y1) || (dir==&& y>=this.y2))
        
dir = (dir+2)%4;
    }
  } else if (
this.walkmode==4) { // RECTANGLE
    
newx;
    
newy;
    if ((
dir==&& y<=this.y1) || (dir==&& x<=this.x1) ||
        (
dir==&& y>=this.y2) || (dir==&& x>=this.x2))
      
dir = (dir+3)%4;
  }
  if (
this.walkmode>&& this.runcounter<=0)
    
this.runcounter 20;
  
message;
  
timeout 0.05;
}

// Sword attacking stuff
if (timeout && (this.mode==|| this.mode==2)) {
  
// Look for players
  
mindist 1000;
  for (
i=0i<playerscounti++)
      if (
players[i].hearts>&& players[i].id>=0) {
    
dx players[i].x;
    
dy players[i].y;
    if (
abs(dx)>abs(dy)) {
      if (
dx>0pdir=3; else pdir=1;
    } else {
      if (
dy>0pdir=2; else pdir=0;
    }
    if (
pdir==dir) {
      
dist = (dx*dx+dy*dy)^0.5;
      if (
dist<mindist) {
        
cansee 1;
        if (
abs(dx)>abs(dy)) int(abs(dx));
        else 
int(abs(dy));
        for (
j=0j<=k-2j++)
          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!=2message 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>&& 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>0dir=3; else dir=1;
    } else {
      if (
dy>0dir=2; else dir=0;
    }

    
// Test if we can do a step
    
dx this.aimx-x;
    
dy this.aimy-y;
    if (
abs(dx)<=&& 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>0testdir=3; else testdir=1;
    } else {
      if (
dy>0testdir=2; else testdir=0;
    }
    
len = (dx*dx+dy*dy)^0.5;
    
addx = (dx/len)*this.huntspeed;
    
addy = (dy/len)*this.huntspeed;
    
testx 1.5;
    
testy 2;
    if (!
onwall(testx+addx,testy+addy)) {
      
// Do a step
      
+= addx;
      
+= addy;
   } else if (!
onwall(testx+addx,testy)) += addx;
   else if (!
onwall(testx,testy+addy)) += 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;
}

// Hurting stuff
if (washit && this.mode!=&& hearts>0) {
  
dx x-playerx;
  
dy y-playery;
  
len = (dx*dx+dy*dy)^0.5;
  
hurtdx dx/len;
  
hurtdy dy/len;
  
setcharani hurt,;
  
hideimg 1;
  
hearts -= playerswordpower/2;
}
if ((
hurtdx!=|| hurtdy!=0) && isleader && this.mode!=4) {
  
this.hurtdx hurtdx;
  
this.hurtdy hurtdy;
  
hurtdx 0;
  
hurtdy 0;
  if (
hearts<=0) {
    
this.mode 4// DYING
    
message;
    
setcharani dead,;
    
timeout 1.2;
  } else {
    
this.mode 1// HURTED
    
this.runcounter 20;
    
setcharani hurt,;
    
timeout 0.05;
  }
}
if (
timeout && this.mode==1) { // HURTED
  
this.runcounter--;
  if (
this.runcounter>10) {
    
testx 1.5 this.hurtdx*2;
    
testy this.hurtdy*2;
    if (!
onwall(testx,testy)) {
      
+= this.hurtdx;
      
+= this.hurtdy;
    }
  }
  if (
this.runcounter<=0) {
    if (
swordpower>0this.mode 2// HUNTING
    
else this.mode 0// WALKING
    
this.runcounter 100;
    
setcharani idle,;
  }
  
timeout 0.05;
}
if (
timeout && this.mode==4) { // DYING
  
random(0,100);
  if (
i<10lay greenrupee;
  else if (
i<15lay bluerupee;
  else if (
i<30lay heart;



fowlplay4 08-26-2012 07:02 PM

You might want to consider learning how to script, and then maybe one day you will be able to fix that old pre-made script from the level editor.

It wasn't made to work online if that's where you're trying to use it.

VeriApplez 08-26-2012 07:05 PM

Yes I was trying to use it online, and ok. Thanks

ffcmike 08-26-2012 07:15 PM

At the very minimum it should be Clientside, as to be more specific it was designed for a much older version of Graal, where there was no such thing as Serverside in the way we know it today.

Gunderak 08-27-2012 11:23 AM

"Dieing"...?


All times are GMT +2. The time now is 07:09 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.