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 08-11-2001, 05:20 AM
LilNiglet LilNiglet is offline
Registered User
Join Date: Jun 2001
Posts: 3,178
LilNiglet is on a distinguished road
Hmmmm.... i cant figure this out

In this code, it does everything its supposed to do (Hunt down up to two seprate guilds), except that when a moogle member passes in front of him... he turns away. This gets annoying... can someone tell me how to fix it?

NPC Code:

// Graal2001 NPC by Stefan Knorr
if (created) {
// Initialize the attributes
showcharacter;
setcharprop #3,head16.gif;
setcharprop #C0,orange;
setcharprop #C1,gray;
setcharprop #C2,darkblue;
setcharprop #C3,darkblue;
setcharprop #8,body11.png;
setcharprop #C4,darkblue;
setcharprop #n,Guard 1;
setcharprop #2,no-shield.gif;
shieldpower = 1;
dir = 2;
swordpower = 1;
hurtdx = 0;
hurtdy = 0;
hearts = 5;
}
if (playerenters || wasthrown) {
// Initialize the this. variables
message;
this.huntspeed = 0.5;
dirgo = {0,-1,-1,0,0,1,1,0};
timeout = 0.05;
if (hearts<=0) {
this.mode = 5; // RESPAWN
this.runcounter = 0;
timeout = 5;
} else {
this.mode = 0;
setcharani idle,;
this.runcounter = int(random(10,40));
}
}

// Sword attacking stuff
if (timeout && (this.mode==0 || this.mode==2)) {
// Look for players
mindist = 1000;
for (i=0; i<playerscount; i++)
if (players[i].hearts>0 && players[i].id>=0) {
dx = players[i].x - x;
dy = players[i].y - y;
if (abs(dx)>abs(dy)) {
if (dx>0) pdir=3; else pdir=1;
} else {
if (dy>0) pdir=2; else pdir=0;
}
if (pdir==dir) {
dist = (dx*dx+dy*dy)^0.5;
if (dist<mindist) {
cansee = 1;
if (abs(dx)>abs(dy)) k = int(abs(dx));
else k = int(abs(dy));
for (j=0; j<=k-2; j++)
if (onwall(x+1.5+dx*j/k,y+2+dy*j/k)) cansee = 0;
if (cansee!=0) {
mindist = dist;
aimplayer = i;
this.aimx = players[i].x;
this.aimy = players[i].y;
}
}
}
}
if (mindist<=3) {
if (strcontains(#g,#s(server.mattackguild1))||strcont ains(#g,#s(server.mattackguild2))){
this.runcounter = -1;
this.mode = 3; // SLAYING
setcharani sword,;
timeout = 0.05;
}} else if (mindist<20) {
if (this.mode!=2) message ;
this.runcounter = 100;
this.mode = 2; // HUNTING
} else timeout = 0.05;
}
if (timeout && this.mode==3) { // SLAYING
this.runcounter++;
if (this.runcounter>4) {
this.runcounter = 100;
this.mode = 2; // HUNTING
setcharani idle,;
}
message;
timeout = 0.05;
}
if (timeout && this.mode==2) { // HUNTING
setcharani walk,;
this.runcounter--;
if (this.runcounter>0 && aimplayer<playerscount && players[aimplayer].hearts>0 && strcontains(#g,#s(server.mattackguild1))||strconta ins(#g,#s(server.mattackguild2))) {
// Get new direction
dx = players[aimplayer].x-x;
dy = players[aimplayer].y-y;
if (abs(dx)>abs(dy)) {
if (dx>0) dir=3; else dir=1;
} else {
if (dy>0) dir=2; else dir=0;
}

// Test if we can do a step
dx = this.aimx-x;
dy = this.aimy-y;
if (abs(dx)<=1 && abs(dy)<=1) {
this.aimx = players[aimplayer].x;;
this.aimy = players[aimplayer].y;
dx = this.aimx-x;
dy = this.aimy-y;
}
if (abs(dx)>abs(dy)) {
if (dx>0) testdir=3; else testdir=1;
} else {
if (dy>0) testdir=2; else testdir=0;
}
len = (dx*dx+dy*dy)^0.5;
addx = (dx/len)*this.huntspeed;
addy = (dy/len)*this.huntspeed;
testx = x + 1.5;
testy = y + 2;
if (!onwall(testx+addx,testy+addy)) {
// Do a step
x += addx;
y += addy;
} else if (!onwall(testx+addx,testy)) x += addx;
else if (!onwall(testx,testy+addy)) y += addy;
} else {
this.mode = 0; // WALKING
this.walkmode = 1; // RANDOM
this.runcounter = int(random(10,40));
setcharani idle,;
dir = (dir+2)%4;
message;
}
timeout = 0.05;
}

// Hurting stuff
if (washit && this.mode!=1 && hearts>0) {
dx = x-playerx;
dy = y-playery;
len = (dx*dx+dy*dy)^0.5;
hurtdx = dx/len;
hurtdy = dy/len;
setcharani hurt,;
hideimg 1;
hearts -= playerswordpower/2;
}
if ((exploded || waspelt || wasshot) &&
this.mode!=1 && hearts>0 && isleader) {
hurtdx = -dirgo[dir*2]*0.2;
hurtdy = -dirgo[dir*2+1]*0.2;
setcharani hurt,;
if (peltwithsign || peltwithvase || peltwithstone || peltwithnpc) hearts -= 1;
else if (peltwithblackstone) hearts -= 1.5;
else hearts -= 0.5;
}
if ((hurtdx!=0 || hurtdy!=0) && isleader && this.mode!=4) {
this.hurtdx = hurtdx;
this.hurtdy = hurtdy;
hurtdx = 0;
hurtdy = 0;
if (hearts<=0) {
this.mode = 4; // DYING
message;
setcharani dead,;
timeout = 1.2;
} else {
this.mode = 1; // HURTED
this.runcounter = 20;
setcharani hurt,;
timeout = 0.05;
}
}
if (timeout && this.mode==1) { // HURTED
this.runcounter--;
if (this.runcounter>10) {
testx = x + 1.5 + this.hurtdx*2;
testy = y + 2+ this.hurtdy*2;
if (!onwall(testx,testy)) {
x += this.hurtdx;
y += this.hurtdy;
}
}
if (this.runcounter<=0) {
if (swordpower>0) this.mode = 2; // HUNTING
else this.mode = 0; // WALKING
this.runcounter = 100;
setcharani idle,;
}
timeout = 0.05;
}

if (playersays(come guard 1)&&strequals(#g,Moogle Government)){
followplayer;
}
if (playersays(stay guard 1)&&strequals(#g,Moogle Government)){
x = x;
y = y;
}

Reply With Quote
  #2  
Old 08-11-2001, 05:26 AM
CrazedMerlin CrazedMerlin is offline
Some Guy :\
Join Date: Apr 2001
Posts: 3,619
CrazedMerlin is on a distinguished road
Send a message via AIM to CrazedMerlin Send a message via Yahoo to CrazedMerlin
dont use playersays ***G3T
if (strequals(#c,come guard 1)) {
if (strequals(#g,Moogle Government)) {
action;
}
}
__________________

ICQ: 117881194
AIM: TehWizad
E-Mail: [email protected]
Reply With Quote
  #3  
Old 08-11-2001, 05:27 AM
LilNiglet LilNiglet is offline
Registered User
Join Date: Jun 2001
Posts: 3,178
LilNiglet is on a distinguished road
Quote:
Originally posted by CrazedMerlin
dont use playersays ***G3T
if (strequals(#c,come guard 1)) {
if (strequals(#g,Moogle Government)) {
action;
}
}
BUT I LEIK PLAYRSAYZ... why not?
Reply With Quote
  #4  
Old 08-11-2001, 05:42 AM
CrazedMerlin CrazedMerlin is offline
Some Guy :\
Join Date: Apr 2001
Posts: 3,619
CrazedMerlin is on a distinguished road
Send a message via AIM to CrazedMerlin Send a message via Yahoo to CrazedMerlin
Quote:
Originally posted by LilNiglet

BUT I LEIK PLAYRSAYZ... why not?
ITS NOT OFFICENT
and followplayer does'nt work online
__________________

ICQ: 117881194
AIM: TehWizad
E-Mail: [email protected]
Reply With Quote
  #5  
Old 08-11-2001, 07:46 AM
LilNiglet LilNiglet is offline
Registered User
Join Date: Jun 2001
Posts: 3,178
LilNiglet is on a distinguished road
Quote:
Originally posted by CrazedMerlin
ITS NOT OFFICENT
and followplayer does'nt work online
butbutbut with npcserver...
Reply With Quote
  #6  
Old 08-11-2001, 08:43 AM
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 CrazedMerlin
dont use playersays ***G3T
if (strequals(#c,come guard 1)) {
if (strequals(#g,Moogle Government)) {
action;
}
}
You have to use strequals with another event...like (playerchats&&strequals(#c,come guard1)).
__________________
the sky is falling
Reply With Quote
  #7  
Old 08-11-2001, 10:01 AM
CrazedMerlin CrazedMerlin is offline
Some Guy :\
Join Date: Apr 2001
Posts: 3,619
CrazedMerlin is on a distinguished road
Send a message via AIM to CrazedMerlin Send a message via Yahoo to CrazedMerlin
Quote:
Originally posted by SkooL
You have to use strequals with another event...like (playerchats&&strequals(#c,come guard1)).
no you don't.
__________________

ICQ: 117881194
AIM: TehWizad
E-Mail: [email protected]
Reply With Quote
  #8  
Old 08-11-2001, 01:06 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 CrazedMerlin
no you don't.
Doesn't work for me without the playerchats part...
__________________
the sky is falling
Reply With Quote
  #9  
Old 08-11-2001, 02:45 PM
Guest
Posts: n/a
I know what the problem is! I am über! But Tupper is a flaming anus so I will not tell him!

Reply With Quote
  #10  
Old 08-11-2001, 10:09 PM
CrazedMerlin CrazedMerlin is offline
Some Guy :\
Join Date: Apr 2001
Posts: 3,619
CrazedMerlin is on a distinguished road
Send a message via AIM to CrazedMerlin Send a message via Yahoo to CrazedMerlin
Quote:
Originally posted by SkooL
Doesn't work for me without the playerchats part...
if you use a variable somewhere in it, it will work.
like if (strequals(#c,blah))

the #c is there so you dont need if (playerchats&&strequals(#c,blah));
__________________

ICQ: 117881194
AIM: TehWizad
E-Mail: [email protected]
Reply With Quote
  #11  
Old 08-12-2001, 05:02 AM
LiquidIce00 LiquidIce00 is offline
RadioActive Monkeeh
LiquidIce00's Avatar
Join Date: Apr 2001
Location: dirty south
Posts: 2,112
LiquidIce00 is on a distinguished road
Send a message via ICQ to LiquidIce00 Send a message via AIM to LiquidIce00 Send a message via Yahoo to LiquidIce00
first..
followplayer doesnt work . come on read the forum more often .. =( . last week was like official follow week or was it 2 weeks ago ?
well .. also playersays was eliminated from the npc server!
you have to do
if (playerchats&&strequals(#c,blabla)) .. you can just do
if (playerchats) . or u can do if (strequals(#c,blabla)) but to get the same effect as playersays() do the first one.
and the last thing is before u edit a npc char . undestand it. u cant just add stuff to it . u gotta change it . else its gonna complicate with the current scripting and all the modes will go crazy blabla..
__________________
LiquidIce *Owner* (UnholyNation)
-UN Website
http://www.unholynation.com
-UN Forum
http://forums.unholynation.com
-
-the thinker
-

-
onwall2 for nonp2p (i suck at onwall)
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 04:10 AM.


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