Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 07-10-2001, 09:27 PM
CyanideSR71 CyanideSR71 is offline
Registered User
CyanideSR71's Avatar
Join Date: Jun 2001
Location: Canada
Posts: 460
CyanideSR71 is on a distinguished road
Some advise on a baddy...

I've made my first baddy, a swordsman (not complete) who hunts the closest player down and swings his sword at him, dodges arrows, and explsoions so far. I'd like to know if this would lag, why, and if I can make it not, what you think of it, as well as any aditions you think I should make to it.

NPC Code:

/*=========================================
Swordsman
Intelligent Enemy!
by ~-=Cyanide SR71(TCN)=-~
Vote for Graalian HQ!
=========================================*/
/*~------------~=Updates=~----------------~
Alpha 0.1 Started scripting. Added this
variables. Added script to
find the closest enemy.
Alpha 0.2 Added chase script, facing
player script, walking and
sword attacking.
Alpha 0.3 Added hurting script and
dying script. Basic baddy
fighter completed.
Beta 1.0 Started scripting stradegies
for a 'smart' baddy. W007!
Arrow dodging script completed.
Beta 1.1 Baddy now runs from explosions.
~---------------------------------------~*/
if (created) {
showcharacter;
setcharprop #C0,orange; // Skin/glove color
setcharprop #C1,gray; // Coat color
setcharprop #C2,darkblue; //Sleeve color
setcharprop #C3,darkblue; // Shoe color
setcharprop #C4,darkblue; // Belt color
setcharprop #1,silverblade1-sword.gif; // Sword filename
setcharprop #2,sardonshield.gif; // Shield filename
setcharprop #3,head16.gif; // Head filename
setcharprop #5,; // Horse filename (not equipped for now)
setcharprop #8,body11.png; // Body filename
setcharprop #n,Swordsman; // Name
swordpower=2; // Swordpower
shieldpower=1; // Shieldpower (doesn't do anything)
this.rupees=400; // Starting rupees
this.hearts=10; // Starting hearts
this.darts=10; // Starting darts
this.bombs=15; // Starting bombs
this.mp=25; // Starting MP
this.sx=x;
this.sy=y;
this.speed=.45; // Speed for walking
this.hurtspeed=.75; //Speed to 'bump' when hit
this.sworddist=3; // Distance to start attacking with sword
this.arrowrundist=5; // Distance in proximity to run from arrows
this.explorundist=10; // Same as above except for explosions
dir=2; // Starting directions
hurtdx=0;
hurtdy=0;
}

if (playerenters && isleader) {
hearts=this.hearts;
if (darts<this.darts) darts=this.darts;
if (bombs<this.bombs) bombs=this.bombs;
if (mp<this.mp) mp=this.mp;
if (rupees<this.rupees) rupees=this.rupees;
x=this.sx;
y=this.sy;
dir=2;
this.mindist=64;
this.mode=1;
timereverywhere;
timeout=0.05;
}

if (timeout) {
if (hearts>0) {
if (this.mode==1) {
this.mindist=128;
for (i=0;i<playerscount;i++) {
if (players[i].hearts>0) {
this.dx=abs((players[i].x+1.5)-(x+1.5));
this.dy=abs((players[i].y+1.5)-(y+1.5));
if (this.dx+this.dy<this.mindist) {
this.player=i;
this.mindist=this.dx+this.dy;
}
}
}
// Facing player
this.distx=abs(players[this.player].x-x);
this.disty=abs(players[this.player].y-y);
if (this.distx<=this.disty){
if (players[this.player].y<y)dir=0;
if (players[this.player].y>y)dir=2;
}else{
if (players[this.player].x<x)dir=1;
if (players[this.player].x>x)dir=3;
}
// Chasing Player
this.distx=abs(players[this.player].x-x);
this.disty=abs(players[this.player].y-y);
if (this.distx==0){
this.addy=this.speed;
}else if (this.disty==0){
this.addx=this.speed;
}else if (this.distx>this.disty){
this.ratio=this.disty/this.distx;
this.addx=this.speed;
this.addy=this.speed*this.ratio;
}else if (this.disty>this.distx){
this.ratio=this.distx/this.disty;
this.addy=this.speed;
this.addx=this.speed*this.ratio;
}
if (y>players[this.player].y&&!onwall(x+1.5,y-this.addy)) y-=this.addy;
if (x>players[this.player].x&&!onwall(x-this.addx,y+1.5)) x-=this.addx;
if (y<players[this.player].y&&!onwall(x+1.5,y+3+this.addy)) y+=this.addy;
if (x<players[this.player].x&&!onwall(x+3+this.addx,y+1.5)) x+=this.addx;
// Looks like he's walking
setcharani walk,;
// Sword attacking
this.dist=((this.distx*this.distx)+(this.disty*thi s.disty))^.5;
if (this.dist<=this.sworddist) this.mode=2;
// Searching for arrows to dodge
this.arrowmindist=1000;
for (i=0;i<arrowscount;i++) {
this.adistx=abs(arrows[i].x-x+1.5);
this.adisty=abs(arrows[i].y-y+1.5);
this.adist=((this.adistx*this.adistx)+(this.adisty *this.adisty))^.5;
if (this.adist<=this.arrowrundist && this.adist<=this.arrowmindist) {
this.arrowmindist=this.adist;
i=this.arrow;
this.mode=4;
}
}
// Searching for explosions to dodge
this.explomindist=1000;
for (i=0;i<exploscount;i++) {
this.edistx=abs(explos[i].x-x);
this.edisty=abs(explos[i].y-y);
this.edist=((this.edistx*this.edistx)+(this.edisty *this.edisty))^.5;
if (this.edist<=this.explorundist && this.edist<=this.explomindist) {
this.explomindist=this.edist;
i=this.explo;
this.mode=5;
}
}
}
if (this.mode==2) {
sprite=this.scount+9;
this.scount++;
if (this.scount>5) {
this.mode=1;
this.scount=0;
}
}
if (this.mode==3) {
if (this.hcount==0) setcharani hurt,;
this.hcount++;
if (players[this.player].y+1.5>y && !onwall(x+1.5,y-this.hurtspeed)) y-=this.hurtspeed;
if (players[this.player].x+1.5>x && !onwall(x-this.hurtspeed,y+1.5)) x-=this.hurtspeed;
if (players[this.player].y+1.5<y && !onwall(x+1.5,y+3+this.hurtspeed)) y+=this.hurtspeed;
if (players[this.player].x+1.5<x && !onwall(x+3+this.hurtspeed,y+1.5)) x+=this.hurtspeed;
if (this.hcount>=10) {
this.mode=1;
this.hcount=0;
}
}
if (this.mode==4) {
// Dodging arrows
this.adistx=abs(arrows[this.arrow].x-x);
this.adisty=abs(arrows[this.arrow].y-y);
if (y+1.5<=arrows[this.arrow].y && !onwall(x+1.5,y-this.speed)) y-=this.speed;
if (x+1.5<=arrows[this.arrow].x && !onwall(x-this.speed,y+1.5)) x-=this.speed;
if (y+1.5>arrows[this.arrow].y && !onwall(x+1.5,y+3+this.speed)) y+=this.speed;
if (x+1.5>arrows[this.arrow].x && !onwall(x+3+this.speed,y+1.5)) x+=this.speed;
// Facing away from arrow
if (this.adistx<=this.adisty){
if (arrows[this.arrow].y<y+1.5)dir=2;
if (arrows[this.arrow].y>y+1.5)dir=0;
}else{
if (arrows[this.arrow].x<x+1.5)dir=3;
if (arrows[this.arrow].x>x+1.5)dir=1;
}
// Going back to chase
this.adist=((this.adistx*this.adistx)+(this.adisty *this.adisty))^.5;
if (this.adist>this.arrowrundist) this.mode=1;
}
if (this.mode==5) {
// Dodging explosions
this.edistx=abs(explos[this.explo].x-x);
this.edisty=abs(explos[this.explo].y-y);
if (y+1.5<=explos[this.explo].y && !onwall(x+1.5,y-this.speed)) y-=this.speed;
if (x+1.5<=explos[this.explo].x && !onwall(x-this.speed,y+1.5)) x-=this.speed;
if (y+1.5>explos[this.explo].y && !onwall(x+1.5,y+3+this.speed)) y+=this.speed;
if (x+1.5>explos[this.explo].x && !onwall(x+3+this.speed,y+1.5)) x+=this.speed;
// Facing away from explo
if (this.edistx<=this.edisty){
if (explos[this.explo].y<y+1.5)dir=2;
if (arrows[this.explo].y>y+1.5)dir=0;
}else{
if (explos[this.explo].x<x+1.5)dir=3;
if (explos[this.explo].x>x+1.5)dir=1;
}
// Going back to chase
this.edist=((this.edistx*this.edistx)+(this.edisty *this.edisty))^.5;
if (this.edist>this.explorundist) this.mode=1;

}
}
timeout=0.05;
}

if (washit || wasshot || waspelt || exploded || firedonhorse || hurtdx!=0 || hurtdy!=0 && this.mode!=3 && hearts>0) {
if (washit) hearts-=playerswordpower/2;
if (wasshot) hearts-=1;
if (exploded) hearts-=.5;
if (peltwithbush) hearts-=.5;
if (peltwithsign ||peltwithstone || peltwithvase) hearts-=1;
if (peltwithblackstone || peltwithnpc) hearts-=1.5;
if (hurtdx!=0) hurtdx=0;
if (hurtdy!=0) hurtdy=0;
this.mode=3;
}

if (hearts<=0) {
this.mode=4;
setcharani dead,;
sleep 1;
while(rupees>=100){
lay goldrupee;
rupees-=100;
}
while(rupees>=30){
lay redrupee;
rupees-=30;
}
while(rupees>=5){
lay bluerupee;
rupees-=5;
}
while(rupees>0){
lay greenrupee;
rupees-=1;
}
while(darts>0){
lay darts;
darts-=5;
}
while(bombs>0){
lay bombs;
bombs-=5;
}


__________________
Cyanide SR71
Former Shadow Dragon
Co-Owner of what was Murasamune
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 07:05 PM.


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