View Single Post
  #1  
Old 07-25-2003, 02:54 AM
Chris1Polly Chris1Polly is offline
Registered User
Chris1Polly's Avatar
Join Date: Feb 2002
Location: A place without hate
Posts: 44
Chris1Polly is on a distinguished road
Send a message via AIM to Chris1Polly
Exclamation Artificial Intellegence!

Well now that Ive finished my systems and debugged them Ive moved onto npcs that will actually do some thinking instead of randomly running around and killing things. Well Ive got a simple guard who has a 10 tile field of vision, all of it works except when he resets after going after someone who has a low alignment rating (its a string on the player created by my system not the regular graal AP) After he gets done chasing someone he should go back to his idle mode, which he does. Problem is once thats done he wont return to attack mode if he needs to attack someone again. Heres the script, tiny bit messy I have yet to refine it. Lets see if any of you can understand why he doesnt reset. Thanks -

NOTE: He doesnt have any customized appearance yet, this shouldnt cause a problem. (being scripted to be made into a class summoned by putnpc2)!

NPC Code:

// NPC made by Aeglos
if (created){
setstring this.hp,100;
setstring this.damHP,10;
setstring this.damBP,5;
setstring this.damEP,5;
setstring this.speed,0.3;
setstring this.walk,walk;
setstring this.attack,sword;
setstring this.idle,idle;
//
setstring this.mode,0;
showcharacter;
}
function reset(){
setstring this.mode,0;
}
//Checking Target Alignment
if (actioncheck){
setstring this.target,#p(0);
check();
}
if (actionalign){
setstring this.align,#p(0);
check2();
}
function check(){
with(getplayer(#s(this.target))){
triggeraction x+1,y+1,align,#s(client.align);
}
}
function check2(){
if (strtofloat(#s(this.align))=>50){message Goodday fine citizen!;}
else if (strtofloat(#s(this.align))<50){setstring this.target2,#s(this.target);message HALT!;setstring this.mode,1;}
}
//Guard Mode
if (strequals(#s(this.mode),0)){
setcharani #s(this.idle),;
if (this.b=<50){this.b++}
else if (this.b>50){changecomment();}
if (this.a=<100){this.a++}
else if (this.a>100){changedir();}
}
//Following
else if (strequals(#s(this.mode),1)){
if (this.d=<200){this.d++}
else if (this.d>200){reset();}
with(getplayer(#s(this.target2))){
this.newx=playerx;
this.newy=playery;
if (playerhearts=0){reset();}
}
if (this.newy<y){y-=strtofloat(#s(this.speed));setcharani #s(this.walk),;getdir()}
if (this.newx<x){x-=strtofloat(#s(this.speed));setcharani #s(this.walk),;getdir()}
if (this.newy>y){y+=strtofloat(#s(this.speed));setcha rani #s(this.walk),;getdir()}
if (this.newx>x){x+=strtofloat(#s(this.speed));setcha rani #s(this.walk),;getdir()}
if (x in |this.newx-1,this.newx+4| && y in |this.newy-1,this.newy+4|){
setcharani #s(this.attack),;
}
}
function getdir(){
if (this.newy<y){dir=2;}
else if (this.newx<x){dir=1;}
else if (this.newy>y){dir=2;}
else if (this.newx>x){dir=3;}
}
function changecomment(){
this.b=0;
this.c=int(random(0,12));
if (this.c=1){message ::grumbles::;}
if (this.c=2){message ::whistles::;}
if (this.c=3){message ::dozes off:: HALT! oh..;}
if (this.c=4){message Bleh... this job is boring;}
if (this.c=5){message ::sighs::;}
if (this.c=6){message ::yawns::;}
if (this.c=7){message ::taps foot lightly::;}
if (this.c=8){message Im tired...;}
if (this.c=9){message If any criminals come my way Ill take care of them! ::laughs::;}
if (this.c=10){message ;}
if (this.c=11){message ::farts::;}
}
function changedir(){
this.a=0;
if (dir=0){dir=1}
else if (dir=1){dir=2}
else if (dir=2){dir=3}
else if (dir=3){dir=0}
}
timeout=0.1;
//#CLIENTSIDE
//Vision Lines
if (dir=0){
if (playerx in |x,x+2| && playery in |y-10,y|){
triggeraction x+1,y+1,check,#a;
}
}
if (dir=1){
if (playerx in |x-10,x| && playery in |y,y+2|){
triggeraction x+1,y+1,check,#a;

}
}
if (dir=2){
if (playerx in |x,x+2| && playery in |y,y+10|){
triggeraction x+1,y+1,check,#a;

}
}
if (dir=3){
if (playerx in |x,x+10| && playery in |y,y+2|){
triggeraction x+1,y+1,check,#a;
}
}
timeout=0.05;

__________________
Reply With Quote