Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 07-10-2001, 09:35 PM
ownerofbabylon ownerofbabylon is offline
Lord Helmut
ownerofbabylon's Avatar
Join Date: Jun 2001
Location: Gainesville FL
Posts: 1,763
ownerofbabylon is on a distinguished road
Send a message via ICQ to ownerofbabylon Send a message via AIM to ownerofbabylon
wow thats nice Good Job
__________________


Warrior of Light

WWW.BABYLONSERVER.COM
Reply With Quote
  #3  
Old 07-11-2001, 12:42 AM
Shard_IceFire Shard_IceFire is offline
Registered User
Shard_IceFire's Avatar
Join Date: Jun 2001
Location: Eastern Harkoonia
Posts: 861
Shard_IceFire is on a distinguished road
I tried it out offline and it sorta lagged, so chances are that it may online too.
__________________

-=Shard IceFire=-
Reply With Quote
  #4  
Old 07-11-2001, 06:09 AM
CyanideSR71 CyanideSR71 is offline
Registered User
CyanideSR71's Avatar
Join Date: Jun 2001
Location: Canada
Posts: 460
CyanideSR71 is on a distinguished road
When did it lag?
=/ My comp has a gigahert, so I can't see lag at all.
__________________
Cyanide SR71
Former Shadow Dragon
Co-Owner of what was Murasamune
Reply With Quote
  #5  
Old 07-11-2001, 06:22 AM
Slaktmaster Slaktmaster is offline
man with the mastahplan
Slaktmaster's Avatar
Join Date: Apr 2001
Location: Half-way over the river styx
Posts: 4,422
Slaktmaster is an unknown quantity at this point
Send a message via ICQ to Slaktmaster Send a message via AIM to Slaktmaster
C00L, real high w00tage there!
Reply With Quote
  #6  
Old 07-11-2001, 09:18 AM
Knightoffrost Knightoffrost is offline
and Delph Inc.
Knightoffrost's Avatar
Join Date: Jul 2001
Location: Canada
Posts: 1,162
Knightoffrost is on a distinguished road
Send a message via ICQ to Knightoffrost Send a message via AIM to Knightoffrost Send a message via Yahoo to Knightoffrost
I have a feeling we're going to see this baddie on delteria
__________________
Xerphier Dintch
Featuring
Reply With Quote
  #7  
Old 07-11-2001, 04:50 PM
Guest
Posts: n/a
Quote:
Originally posted by Knightoffrost
I have a feeling we're going to see this baddie on delteria
Shut up! I can script very good and script my own ****!
Reply With Quote
  #8  
Old 07-11-2001, 08:13 PM
Knightoffrost Knightoffrost is offline
and Delph Inc.
Knightoffrost's Avatar
Join Date: Jul 2001
Location: Canada
Posts: 1,162
Knightoffrost is on a distinguished road
Send a message via ICQ to Knightoffrost Send a message via AIM to Knightoffrost Send a message via Yahoo to Knightoffrost
Quote:
Originally posted by IcePick_2001


Shut up! I can script very good and script my own ****!
No you cannot,because your 12,and your a liar,and your an idiot.
__________________
Xerphier Dintch
Featuring
Reply With Quote
  #9  
Old 07-11-2001, 08:17 PM
ownerofbabylon ownerofbabylon is offline
Lord Helmut
ownerofbabylon's Avatar
Join Date: Jun 2001
Location: Gainesville FL
Posts: 1,763
ownerofbabylon is on a distinguished road
Send a message via ICQ to ownerofbabylon Send a message via AIM to ownerofbabylon
LOL
__________________


Warrior of Light

WWW.BABYLONSERVER.COM
Reply With Quote
  #10  
Old 07-11-2001, 08:19 PM
Knightoffrost Knightoffrost is offline
and Delph Inc.
Knightoffrost's Avatar
Join Date: Jul 2001
Location: Canada
Posts: 1,162
Knightoffrost is on a distinguished road
Send a message via ICQ to Knightoffrost Send a message via AIM to Knightoffrost Send a message via Yahoo to Knightoffrost
Quote:
Originally posted by ownerofbabylon
LOL
heh
__________________
Xerphier Dintch
Featuring
Reply With Quote
  #11  
Old 07-11-2001, 09:05 PM
CyanideSR71 CyanideSR71 is offline
Registered User
CyanideSR71's Avatar
Join Date: Jun 2001
Location: Canada
Posts: 460
CyanideSR71 is on a distinguished road
Knightoffrost, you're my new friend!
__________________
Cyanide SR71
Former Shadow Dragon
Co-Owner of what was Murasamune
Reply With Quote
  #12  
Old 07-11-2001, 09:15 PM
Knightoffrost Knightoffrost is offline
and Delph Inc.
Knightoffrost's Avatar
Join Date: Jul 2001
Location: Canada
Posts: 1,162
Knightoffrost is on a distinguished road
Send a message via ICQ to Knightoffrost Send a message via AIM to Knightoffrost Send a message via Yahoo to Knightoffrost
Quote:
Originally posted by CyanideSR71
Knightoffrost, you're my new friend!
__________________
Xerphier Dintch
Featuring
Reply With Quote
  #13  
Old 07-11-2001, 09:17 PM
SkooL SkooL is offline
somebody to love
Join Date: Jun 2001
Location: bat country.
Posts: 3,446
SkooL is on a distinguished road
Send a message via AIM to SkooL
Quote:
Originally posted by Knightoffrost
No you cannot,because your 12,and your a liar,and your an idiot.
You used the word 'and' twice in your series of items!
__________________
the sky is falling
Reply With Quote
  #14  
Old 07-11-2001, 09:19 PM
Knightoffrost Knightoffrost is offline
and Delph Inc.
Knightoffrost's Avatar
Join Date: Jul 2001
Location: Canada
Posts: 1,162
Knightoffrost is on a distinguished road
Send a message via ICQ to Knightoffrost Send a message via AIM to Knightoffrost Send a message via Yahoo to Knightoffrost
Quote:
Originally posted by SkooL

You used the word 'and' twice in your series of items!
IT's acceptable to put and after a comma as many times as you want..if you do so it means something different though,it means equal importance between the items..if you do it without the "and's" it means that the first item you mention is more important then the others =D
__________________
Xerphier Dintch
Featuring
Reply With Quote
  #15  
Old 07-11-2001, 09:22 PM
SkooL SkooL is offline
somebody to love
Join Date: Jun 2001
Location: bat country.
Posts: 3,446
SkooL is on a distinguished road
Send a message via AIM to SkooL
Quote:
Originally posted by Knightoffrost
IT's acceptable to put and after a comma as many times as you want..if you do so it means something different though,it means equal importance between the items..if you do it without the "and's" it means that the first item you mention is more important then the others =D
__________________
the sky is falling
Reply With Quote
  #16  
Old 07-11-2001, 09:29 PM
Knightoffrost Knightoffrost is offline
and Delph Inc.
Knightoffrost's Avatar
Join Date: Jul 2001
Location: Canada
Posts: 1,162
Knightoffrost is on a distinguished road
Send a message via ICQ to Knightoffrost Send a message via AIM to Knightoffrost Send a message via Yahoo to Knightoffrost
Quote:
Originally posted by SkooL

Ya learn something new everyday LoL
__________________
Xerphier Dintch
Featuring
Reply With Quote
  #17  
Old 07-11-2001, 09:49 PM
manton manton is offline
Raise Your Fist
Join Date: Mar 2001
Location: California
Posts: 2,318
manton will become famous soon enough
Send a message via AIM to manton
Quote:
Originally posted by IcePick_2001


Shut up! I can script very good and script my own ****!
Go away,We hate you.
__________________
-Nastazio
Reply With Quote
  #18  
Old 07-11-2001, 10:03 PM
Slaktmaster Slaktmaster is offline
man with the mastahplan
Slaktmaster's Avatar
Join Date: Apr 2001
Location: Half-way over the river styx
Posts: 4,422
Slaktmaster is an unknown quantity at this point
Send a message via ICQ to Slaktmaster Send a message via AIM to Slaktmaster
Quote:
Originally posted by manton


Go away,We hate you.
I believe you worship him since the guy on your sig has the same head as Ice Pick.
Reply With Quote
  #19  
Old 07-11-2001, 10:06 PM
ownerofbabylon ownerofbabylon is offline
Lord Helmut
ownerofbabylon's Avatar
Join Date: Jun 2001
Location: Gainesville FL
Posts: 1,763
ownerofbabylon is on a distinguished road
Send a message via ICQ to ownerofbabylon Send a message via AIM to ownerofbabylon
LOL, IcePick is 12 HAHA Poor wittle baby
__________________


Warrior of Light

WWW.BABYLONSERVER.COM
Reply With Quote
  #20  
Old 07-11-2001, 10:11 PM
Knightoffrost Knightoffrost is offline
and Delph Inc.
Knightoffrost's Avatar
Join Date: Jul 2001
Location: Canada
Posts: 1,162
Knightoffrost is on a distinguished road
Send a message via ICQ to Knightoffrost Send a message via AIM to Knightoffrost Send a message via Yahoo to Knightoffrost
Quote:
Originally posted by Slaktmaster


I believe you worship him since the guy on your sig has the same head as Ice Pick.
ROFL , true,true
__________________
Xerphier Dintch
Featuring
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 10:25 PM.


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