Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Artificial Intellegence! (https://forums.graalonline.com/forums/showthread.php?t=46471)

Chris1Polly 07-25-2003 02:54 AM

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. :confused: 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;


Dude6252000 07-25-2003 03:08 AM

Post the NPC in a level? :x

Kaimetsu 07-25-2003 03:09 AM

Ew, chaotic indenting. It makes scripts more trouble to read :(

Chris1Polly 07-25-2003 04:32 AM

Chaotic Indent c.c
 
Quote:

Ew, chaotic indenting. It makes scripts more trouble to read
Well I have a habit of hitting the style button... lol for me its just as easy to read a block of script
"if (created){setimg door.png;setshape 1,32,32;}"
as it is to read the indented.. maybe its just me x.x;
but did you notice any reason why he doesnt react to players onces hes changed modes once?

Kaimetsu 07-25-2003 05:14 AM

Alas, I don't look at scripts unless they conform to KSI-GS.

Chris1Polly 07-25-2003 05:24 AM

KSI-GS
 
Kaimetsu Standards Institute - Graal Script?
Ill convert it if need be, but Ill need the guidelines.... I just really need to find out whats going wrong with this script, its bugging me to death. :\

Kaimetsu 07-25-2003 05:37 AM

The guidelines died after a stupid boy deleted them. I'll write up some new ones.

Python523 07-25-2003 05:52 AM

so inefficent =|

Chris1Polly 07-25-2003 05:57 AM

Well...
 
Well Im sorry it doesnt meet up to your standards, I can script most anything even if I do take the longer route, Im still new to npc server scripting, and I never took time to learn new commands... since well. o_O mostly the new commands Ive learned by hearing people talk about them. Ive not studied a command for at least 5 versions of graal. Most likely more :\ Instead of commenting on the way it was scripted perhaps you can help? o_O I know your good enough to.

Kaimetsu 07-25-2003 06:11 AM

Re: Well...
 
Quote:

Originally posted by Chris1Polly
I can script most anything
Believe me, you can't. Nobody can.

Chris1Polly 07-25-2003 06:20 AM

"most anything" not everything, I dont claim to be able to do that.

Kaimetsu 07-25-2003 06:38 AM

Quote:

Originally posted by Chris1Polly
"most anything" not everything, I dont claim to be able to do that.
You can create only a tiny proportion of the total imaginable scripts, just like any other human.

TribulationStaff 07-25-2003 06:44 AM

Huzzah for the laws of probability ;)

Tseng 07-25-2003 08:22 AM

Pick a form (preferably the standard one) of indenting and stick with it.

Don't put code outside of event blocks.

Don't treat flags as events.

Alexander 07-25-2003 08:12 PM

I maybe stupid but I thought = was assign, not equal.


All times are GMT +2. The time now is 12:46 AM.

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