Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-17-2011, 04:20 AM
Tricxta Tricxta is offline
The Muffin Man
Tricxta's Avatar
Join Date: Oct 2010
Location: Australia
Posts: 563
Tricxta is just really niceTricxta is just really nice
you've been scripting for less then a week yet you feel this is code gallery worthy? Uhmmm k bai
__________________
Quote:
Originally Posted by Crono View Post
No look at it, Stefan is totally trolling Thor. Calling Classic a "playerworld" (something it's not supposed to be) is the ultimate subtle insult to a true fan.

It's genius.
Reply With Quote
  #2  
Old 05-17-2011, 04:21 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Quote:
Originally Posted by Tricxta View Post
you've been scripting for less then a week yet you feel this is code gallery worthy? Uhmmm k bai
No, I have been scripting for months. Read. I said the original script was made in my first week. I completely redid it today. btw fixed a huge glitch that caused the npc to target the same direction every time. Also nerfed the npcs reaction speed but improved its strategy.

Last edited by skillmaster19; 05-17-2011 at 04:50 AM..
Reply With Quote
  #3  
Old 05-17-2011, 09:55 AM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Tricxta View Post
you've been scripting for less then a week yet you feel this is code gallery worthy? Uhmmm k bai
Stop being an ass.
Reply With Quote
  #4  
Old 05-18-2011, 02:40 AM
Messiah Messiah is offline
Professional Rebel
Join Date: Mar 2011
Posts: 131
Messiah will become famous soon enough
Quote:
Originally Posted by Tricxta View Post
you've been scripting for less then a week yet you feel this is code gallery worthy? Uhmmm k bai
Who are you to judge others? Hes looking for feedback, not someone to tell him his code isn't "worthy" of posting on a goddamn forum.
Reply With Quote
  #5  
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() > 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 (
this.dir || this.dir 3) {
            
this.mode "targetingup";
          }
        }
      }
    }
    
this.toright this.plyr.5;
    
this.todown this.plyr.5;
    
this.toup this.plyr.5;
    
this.toleft this.plyr.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.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) < 2) {
      
this.scheduleevent(random(0.10.4), "hurtCharacter"0);
    }
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4) {
      
this.scheduleevent(random(0.10.4), "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() {
  if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4) {
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 2) {
      if (
abs(this.plyrdistx) > abs(this.plyrdisty)) {
        if (
this.plyrdistx 0this.dir 3;
        else 
this.dir 1;
      } else {
        if (
this.plyrdisty 0this.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.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);
  }


Last edited by skillmaster19; 05-18-2011 at 11:27 PM..
Reply With Quote
  #6  
Old 05-20-2011, 12:38 AM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
The baddy is now more efficient, by moving some things out of the timeout.I fixed many bugs causing it to keep charging, and it changes targets at the correct time now(when hit, when it hits, etc) I also fixed the styling
btw, how good or bad is this CPU time? 0.073447624 % npcs[2] (in level skills_sample_level.nw at pos (30.9, 6.1)) (skill_insidebaddy)
PHP Code:
function onCreated() {
  
showcharacter();
  
// change these to the attributes that you want
  
headimg "head10.gif";
  
bodyimg "body.png";
  
shieldimg "shield1.png";
  
swordimg "sword1.png";
  
this.maxhp 10;
  
this.movementSpeed 1;
  
colors[0] = "black"//skin color
  
colors[1] = "black"// coat color
  
colors[2] = "black"// sleeves color
  
colors[3] = "black"// shoes color
  
colors[4] = "black"// belt color
  //dont change past this point if you don't know what you are doing
  
this.outsidetargetmodes = {
    
"targetingup""targetingdown""targetingleft""targetingright""charge"
  
};
  
swordpower 1;
  
setTimer(0.1);
  
this.hp this.maxhp;
}

function 
onTimeOut() {
    if (!
getMode) {
    
getTarget();
  }
  
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;
    
this.toright this.plyr.6;
    
this.todown this.plyr.6;
    
this.toup this.plyr.6;
    
this.toleft this.plyr.6;
    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.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) < 2) {
      
this.scheduleevent(random(0.10.4), "hurtCharacter"0);
    }
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4) {
      
this.scheduleevent(random(0.10.4), "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 this.maxhp;
  
this.ani "idle";
  
move(int(random(-0.99990.9999)), int(random(-0.99990.9999)), 0o);
  
this.chat this.hp;
}

function 
onhurtCharacter() {
  if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 4) {
    if (
abs(this.plyrdistx) < && abs(this.plyrdisty) < 2) {
      if (
abs(this.plyrdistx) > abs(this.plyrdisty)) {
        if (
this.plyrdistx 0this.dir 3;
        else 
this.dir 1;
      } else {
        if (
this.plyrdisty 0this.dir 2;
        else 
this.dir 0;
      }
      
this.swordfreezetime 10//stops swinging for 10 timeouts
      
this.mode "waiting";
      
this.ani "sword";
      
this.scheduleevent(0.3"StopSwinging"0);
    }
  }
  if (
this.plyr.hearts == 0) {
    
this.ani "idle";
  }
}

function 
onStopSwinging() {
  
this.ani "idle";
}

function 
onPlayerEnters() {
  
onTimeOut();
}

function 
getTarget() {
  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 (
this.dir || this.dir 3) {
        
this.mode "targetingup";
      }
    }
  }
}

function 
onWa****() {
  
this.mode "waiting";
  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);
  }


Last edited by skillmaster19; 05-20-2011 at 12:51 AM..
Reply With Quote
Reply


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 03:20 AM.


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