PDA

View Full Version : Some advise on a baddy...


CyanideSR71
07-10-2001, 09:27 PM
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.


/*=========================================
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;
}

ownerofbabylon
07-10-2001, 09:35 PM
wow thats nice :D Good Job

Shard_IceFire
07-11-2001, 12:42 AM
I tried it out offline and it sorta lagged, so chances are that it may online too.

CyanideSR71
07-11-2001, 06:09 AM
When did it lag?
=/ My comp has a gigahert, so I can't see lag at all.

Slaktmaster
07-11-2001, 06:22 AM
C00L, real high w00tage there!

Knightoffrost
07-11-2001, 09:18 AM
I have a feeling we're going to see this baddie on delteria

07-11-2001, 04:50 PM
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 ****!

Knightoffrost
07-11-2001, 08:13 PM
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.

ownerofbabylon
07-11-2001, 08:17 PM
LOL

Knightoffrost
07-11-2001, 08:19 PM
Originally posted by ownerofbabylon
LOL

heh

CyanideSR71
07-11-2001, 09:05 PM
Knightoffrost, you're my new friend!

Knightoffrost
07-11-2001, 09:15 PM
Originally posted by CyanideSR71
Knightoffrost, you're my new friend!

:) :D ;)

SkooL
07-11-2001, 09:17 PM
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! :eek: :eek: :eek:

Knightoffrost
07-11-2001, 09:19 PM
Originally posted by SkooL

You used the word 'and' twice in your series of items! :eek: :eek: :eek:

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

SkooL
07-11-2001, 09:22 PM
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
:eek:

Knightoffrost
07-11-2001, 09:29 PM
Originally posted by SkooL

:eek:
Ya learn something new everyday LoL

manton
07-11-2001, 09:49 PM
Originally posted by IcePick_2001


Shut up! I can script very good and script my own ****!

Go away,We hate you.

Slaktmaster
07-11-2001, 10:03 PM
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.

ownerofbabylon
07-11-2001, 10:06 PM
LOL, IcePick is 12 HAHA :D Poor wittle baby

Knightoffrost
07-11-2001, 10:11 PM
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