Thread: Moving Class
View Single Post
  #1  
Old 03-17-2003, 12:24 AM
tlf288 tlf288 is offline
Registered User
tlf288's Avatar
Join Date: Nov 2001
Location: new account: Trevor
Posts: 0
tlf288 is on a distinguished road
Send a message via AIM to tlf288 Send a message via Yahoo to tlf288
Moving Class

I want to help out the Graal community so I will be posting things for playerworld to use.

This class can be used for NPCs to move around:
NPC Code:

/*****************************
* name: people *
* type: class *
* by: Trevor (Scripter) *
*****************************/
canwarp;
if(timeout){

if(this.step>=arraylen(this.moveVecX)){
this.step=0;
dir=this.moveDirC[0];
this.distWent=0;
x=this.baseX;
y=this.baseY;
}

if(dir==1||dir==3){
if(this.distWent>=abs(this.moveVecX[this.step])){
this.distWent=0;
this.step++;
dir=this.moveDirC[this.step];
}
}else if(dir==0||dir==2){
if(this.distWent>=abs(this.moveVecY[this.step])){
this.distWent=0;
this.step++;
dir=this.moveDirC[this.step];
}
}

this.nX=x+vecx(dir)*(this.speed/2);
this.nY=y+vecy(dir)*(this.speed/2);

this.testP=testplayer(this.nX+1.5+vecx(dir),this.n Y+2+vecy(dir));
if(this.testP>=0){
setcharani idle,;
this.messageOn=true;
this.message=1;
doMessage();
if(this.hold==false){
this.hold=true;
}
}else{this.hold=false; message;}

if(this.hold==false){
setcharani walk,;
move this.nX-x,this.nY-y,.1,2+16;
this.distWent+=(this.speed/2);
}
timeout=.1;
}

function doMessage()
{
if(this.messageOn==true){
if(this.message==1){
message #R(#s(this.message));
this.message=-1;
}
sleep4;
this.messageOn=false;
}
}



Here is an example DBNPC for the class:
NPC Code:

join people;
if (initialized) {
showcharacter;
setcharprop #C0,orange;
setcharprop #C1,darkblue;
setcharprop #C2,blue;
setcharprop #C3,black;
setcharprop #C4,black;
setcharprop #n,*Debbie (Police);
setcharprop #2,shield3.gif;
setcharprop #3,head21.png;
setcharprop #8,body4.png;
setcharprop #P1,hat92.png;
setcharprop #1,zeroriotstick-sword.png;
shieldpower=1;
this.speed=1;
ap=100;
this.moveVecX={ 4, 0, -4, 0}
this.moveVecY={ 0, 4, 0, -4}
this.moveDirC={ 3, 2, 1, 0}
dir=this.moveDirC[0];
this.step=0;
this.baseX=x; // You may want to change this var to the start x
this.baseY=y; // ""-x + y
timeout=.1;
setstring this.message,Welcome to Graal2001!,Enjoy your stay :),Hope you have fun here at Graal2001;
}



You can use both of these freely as long as you keep the credits in the script.
__________________
new account: Trevor
Reply With Quote