NPC Code:
if (playerenters&&!isweapon) { toweapons test; }
if (weaponfired) { timeout=.1; }
if (timeout) {
//here we say if the length of the array
//of stepx is 0 we need to make it an array
if (arraylen(stepsx)=0) { init(); }
if (playerx!=stepsx[0]||playery!=stepsy[0]) {
movearray();
record();
}
show();
timeout=.1;
}
function init() {
//here we set the stepsx array to 5
//remember it only goes up to 4
//since it starts at 0
setarray stepsx,5;
setarray stepsy,arraylen(stepsx);
}
function movearray() {
//here we move the array
//we start at 4 and we go
//to 1 , everytime moving it back one.
//for example if stepsx[3] is 3 and stepsx[2]
//is 4,
//it will set stepsx[4] to 3 and stepsx[3]
//to 4 and so on
for (this.i=arraylen(stepsx)-1;this.i>0;this.i--) {
stepsx[this.i]=stepsx[this.i-1];
stepsy[this.i]=stepsy[this.i-1];
}
}
function record() {
//record current player position to 0
stepsx[0]=playerx;
stepsy[0]=playery;
}
function show() {
showimg 1,shadoworb.gif,stepsx[arraylen(stepsx)-1],stepsy[arraylen(stepsy)-1];
}