Found an old script on my hard drive while I was clearing things out. Don’t really know that I’ll ever use it and I’d rather it not go to waste. It should function properly on servers with multiple people. Not that we have anything like that here.
///////////////////////////////////////
//
// Randomized Walking NPC - Kondie
//
///////////////////////////////////////
//
// MODE VARIANTS
// -------------
// 0 - not busy
// 1 - busy/talking
// ?? 2 - walking ??
//
///////////////////////////////////////
// Must be on if (created) so it's only called once
if (created) { this.ogx = x; this.ogy = y; }
if (playerenters) {
timereverywhere;
showcharacter;
setcharprop #3,head26.png;
setcharprop #C0,orange;
setcharprop #C1,brown;
setcharprop #C2,brown;
setcharprop #C3,brown;
setcharprop #C4,black;
setcharprop #2,xialza_wooden-shield.gif;
shieldpower = 1;
setcharani idle,;
dir = 2;
this.xarea = 5; // Move within x tiles left/right of original x - pos
this.yarea = 5; // Move within x tiles up/down of original y - pos
this.walkSpeed = .15;
// Set timeout for walking loop
timeout = .05;
}
if (timeout) {
if (this.xdone == 0 && this.ydone == 0) {
setcharani idle,;
this.sleep = random(2, 5);
sleep();
this.randomdir = (int(random(0,100))) % 4;
dir = this.randomdir;
if (this.randomdir == 0 || this.randomdir == 2) { // Up or down (0, 2)
// Set 'ydone' to not done
this.ydone = 1;
this.destinationy = (this.randomdir == 0) ? int(random(this.ogy - this.yarea, y - 2)) : int(random(y + 2, this.ogy + this.yarea));
} else { // Left or right (1, 3)
// Set 'xdone' to not done
this.xdone = 1;
this.destinationx = (this.randomdir == 1) ? int(random(this.ogx - this.xarea, x - 2)) : int(random(x + 2, this.ogx + this.xarea));
}
}
message ;
playersCheck();
if (this.mode == 0) walk();
else setcharani idle,;
timeout = .05;
}
if (playertouchsme && this.mode == 1) {
setcharani idle,;
this.tempdir = dir;
dir = (playerdir + 2) % 4;
message Why the fuck are you so close, bruh?;
dir = this.tempdir;
timeout = .05;
}
function walk() {
if ( !(x in |this.destinationx - 1, this.destinationx + 1|) && x in |this.ogx - this.xarea, this.ogx + this.xarea| ) {
setcharani walkslow,;
x += vecx(dir) * this.walkSpeed;
} else this.xdone = 0;
if ( !(y in |this.destinationy - 1, this.destinationy + 1|) && y in |this.ogy - this.yarea, this.ogy + this.yarea| ) {
setcharani walkslow,;
y += vecy(dir) * this.walkSpeed;
} else this.ydone = 0;
}
// Checks the surrounding area for any players so
// that if there are any, it will stop to chat.
function playersCheck() {
for (this.i = 0; this.i < playerscount; this.i ++) {
if (players[this.i].x in |x - 3, x + 3| && players[this.i].y in |y - 3, y + 3|) {
this.mode = 1;
} else this.mode = 0;
}
}
function sleep() {
for (this.sleepTimer = 0; this.sleepTimer < this.sleep; this.sleepTimer += .05) {
playersCheck();
sleep .05;
}
}