Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #10  
Old 05-17-2011, 04:55 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
How to style your script properly with jsbeautifer.org

Copy-paste your code into the code text area.

Settings:
- Indent with 2 spaces
- Braces with control statement
- Un-check all Checkboxes

Click 'Beautify'

Result:

PHP Code:
// Scripted by Skill 

function onActionhit() {
  if (
this.hp 0) {
    switch (
player.dir) {
    case 
"2":
      if (!
checkBlockedTile(this.xthis.5)) {
        
this.this.5;
      }
      break;
    case 
"3":
      if (!
checkBlockedTile(this.5this.y)) {
        
this.+= 5;
      }
      break;
    case 
"1":
      if (!
checkBlockedTile(this.5this.y)) {
        
this.this.5;
      }
      break;
    case 
"0":
      if (!
checkBlockedTile(this.xthis.5)) {
        
this.this.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);
  }
}

function 
onCreated() {
  
this.outsidetargetmodes = {
    
"targetingup""targetingdown""targetingleft""targetingright""charge"
  
};
  
setshape(16464);
  
showcharacter();
  
swordimg "sword1.png";
  
this.hp 10;
  
this.movementSpeed 1;
  
swordpower 1;
  
setTimer(0.1);
}

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

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

  function 
checkBlockedTile(xValueyValue) {
    if (
onwall(xValueyValue) || onwater(xValueyValue)) return true;
    else return 
false;
  }

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

  function 
onhurtCharacter() {
    
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();
}
//#CLIENTSIDE 

function onWa****() {
  
triggeraction(player.1.5 + (vecx(playerdir) * 2), player.1.5"hit");
}

function 
onCreated() {
  
setshape(16464);

When your code is styled properly, it's now possible to see that you have other functions nested in your timeout function.
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:37 AM.


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