View Single Post
  #16  
Old 05-18-2011, 11:08 PM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Fixes, and it wont let me edit my original post.
PHP Code:
function onCreated() {
  
this.outsidetargetmodes = {
    
"targetingup", "targetingdown", "targetingleft", "targetingright", "charge"
  
};
  
showcharacter();
  
swordimg = "sword1.png";
  
this.hp = 10;
  
this.movementSpeed = 1;
  
swordpower = 1;
  
setTimer(0.9);
}

function 
onTimeOut() {
  
this.resettarget++;
  if (
this.resettarget > 30) {
    
this.mode = "waiting";
    
this.resettarget = 0;
  }
  
this.swordfreezetime--;
  if (
players.size() > 0) setTimer(0.1);
  else 
setTimer(0);
  if (
this.hp > 0) {
    
this.ani = "walk";
    
this.closestplayer = findnearestplayer(this.x, this.y);
    
this.plyr = this.closestplayer;
    if (!
getMode) {
      if (
int(random(0, 100)) < 30) {
        
this.mode = "charge";
      } else {
        
temp.wheretoattack = int(random(0, 100));
        if (
temp.wheretoattack >= 50) {
          if (
this.dir = 0 || this.dir = 2) {
            
this.mode = "targetingright";
          }
          if (
this.dir = 1 || this.dir = 3) {
            
this.mode = "targetingdown";
          }
        }
        if (
temp.wheretoattack <= 49) {
          if (
this.dir = 0 || this.dir = 2) {
            
this.mode = "targetingleft";
          }
          if (
this.dir = 1 || this.dir = 3) {
            
this.mode = "targetingup";
          }
        }
      }
    }
    
this.toright = this.plyr.x + 5;
    
this.todown = this.plyr.y + 5;
    
this.toup = this.plyr.y - 5;
    
this.toleft = this.plyr.x - 5;
    switch (
this.mode) {
    case 
"targetingleft":
      
this.targetx = this.toleft;
      
this.targety = this.plyr.y;
      break;
    case 
"targetingright":
      
this.targetx = this.toright;
      
this.targety = this.plyr.y;
      break;
    case 
"targetingdown":
      
this.targety = this.todown;
      
this.targetx = this.plyr.x;
      break;
    case 
"targetingup":
      
this.targety = this.toup;
      
this.targetx = this.plyr.x;
      break;
    case 
"charge":
      
this.targetx = this.plyr.x;
      
this.targety = this.plyr.y;
      break;
    }
    
this.distx = (this.targetx) - this.x;
    
this.disty = this.targety - this.y;
    
this.plyrdistx = this.plyr.x - this.x;
    
this.plyrdisty = this.plyr.y - this.y;
    
this.len = (this.distx * this.distx + this.disty * this.disty) ^ 0.5;
    
this.movex = (this.distx / this.len);
    
this.fixed_x = this.x + 1.5;
    
this.fixed_y = this.y + 2;
    
this.movey = (this.disty / this.len);
    if (!
checkBlockedTile(this.movex + this.fixed_x, this.fixed_y + this.movey)) {
      if (
this.distx < 20 && this.disty < 20) {
        
this.x += this.movex * (this.movementSpeed);
        
this.y += this.movey * (this.movementSpeed);
      }
    } else 
this.ani = "idle";
  }
  if (
abs(this.distx) > abs(this.disty)) {
    if (
this.distx > 0) this.dir = 3;
    else 
this.dir = 1;
  } else {
    if (
this.disty > 0) this.dir = 2;
    else 
this.dir = 0;
  }
  if (
this.swordfreezetime <= 0) {
    if (
abs(this.plyrdistx) < 4 && abs(this.plyrdisty) < 2) {
      
this.scheduleevent(random(0.1, 0.4), "hurtCharacter", 0);
    }
    if (
abs(this.plyrdistx) < 2 && abs(this.plyrdisty) < 4) {
      
this.scheduleevent(random(0.1, 0.4), "hurtCharacter", 0);
    }
  }
}

function 
getMode() {
  if (
this.mode in this.outsidetargetmodes) return true;
  else return 
false;
}

function 
checkBlockedTile(xValue, yValue) {
  if (
onwall(xValue, yValue) || onwater(xValue, yValue)) return true;
  else return 
false;
}

function 
onRespawn(ticker) {
  
this.hp = 10;
  
this.ani = "idle";
  
move(int(random(-0.9999, 0.9999)), int(random(-0.9999, 0.9999)), 0, o);
  
this.chat = this.hp;
}

function 
onhurtCharacter() {
  if (
abs(this.plyrdistx) < 2 && abs(this.plyrdisty) < 4) {
    if (
abs(this.plyrdistx) < 4 && abs(this.plyrdisty) < 2) {
      if (
abs(this.plyrdistx) > abs(this.plyrdisty)) {
        if (
this.plyrdistx > 0) this.dir = 3;
        else 
this.dir = 1;
      } else {
        if (
this.plyrdisty > 0) this.dir = 2;
        else 
this.dir = 0;
      }
      
this.mode = "waiting";
      
this.ani = "sword";
      
this.scheduleevent(0.1, "StopSwinging", 0);
    }
  }
  if (
this.plyr.hearts = 0) {
    
this.ani = "idle";
  }
}

function 
onStopSwinging() {
  
this.ani = "walk";
  
this.swordfreezetime = 10; //stops swinging for 10 timeouts
}

function 
onPlayerEnters() {
  
onTimeOut();
}

function 
onWa****() {
  
this.mode = "waiting";
  if (
this.hp > 0) {
    switch (
player.dir) {
    case 
"2":
      if (!
checkBlockedTile(this.x, this.y + 5)) {
        
this.y = this.y + 5;
      }
      break;
    case 
"3":
      if (!
checkBlockedTile(this.x + 5, this.y)) {
        
this.x += 5;
      }
      break;
    case 
"1":
      if (!
checkBlockedTile(this.x - 5, this.y)) {
        
this.x = this.x - 5;
      }
      break;
    case 
"0":
      if (!
checkBlockedTile(this.x, this.y - 5)) {
        
this.y = this.y - 5;
      }
      break;
    }
  }
  
this.hp--;
  if (
this.hp >= 0) {
    
this.chat = this.hp;
  }
  if (
this.hp == 0) {
    
this.ani = "dead";
  }
  if (
this.hp == 0) {
    
clientr.baddykills++;
    
player.chat = "I have"
    
SPC clientr.baddykills SPC "baddy kills";
    
this.scheduleevent(50, "Respawn", 0);
  }
} 

Last edited by skillmaster19; 05-18-2011 at 11:27 PM..
Reply With Quote