Page 1 of 1
LUA function for random wanderings
Posted: Sun Aug 10, 2008 11:33 am
by John Adams
Is it possible to get a Move command for NPCs to wander within the confines of their area randomly? Like fish swimming in their ponds, deer wandering around the meadow. Maybe we can set up safe "bounds" that they can walk in, and they just randomly pick x,y,z,heading,delay themselves.
I still haven't figured out how to get "patrols" to stick together... I think we talked about it, but not sure if that got implemented yet.
Posted: Tue Sep 02, 2008 4:34 pm
by John Adams
Random wanderings has been figured out by Scatman's patience, resolve, and sheer will power to make deer scatter in all directions.

Here's a sample, for anyone else looking for seemingly random wander paths:
Code: Select all
--[[
Script Name : circle_clockwise_small_01.lua
Script Purpose : Makes the spawn do a small circle in a clockwise fashion.
Script Author : Scatman
Script Date : 2008-08-26
Script Notes : If the coords are out of bounds then the spawn will still go there.
--]]
function spawn(NPC)
x = GetX(NPC)
y = GetY(NPC)
z = GetZ(NPC)
MovementLoopAddLocation(NPC, x + 7 , y, z - 8 , 2, math.random(5, 15))
MovementLoopAddLocation(NPC, x - 5 , y, z - 10, 2, math.random(5, 15))
MovementLoopAddLocation(NPC, x - 10, y, z + 9 , 2, math.random(5, 15))
MovementLoopAddLocation(NPC, x + 5 , y, z + 8 , 2, math.random(5, 15))
end
function respawn(NPC)
spawn(NPC)
end
function hailed(NPC, Spawn)
FaceTarget(NPC, Spawn)
end
You can probably randomize x and z as well if you know your boundaries.
Thank you Scatman!
Posted: Tue Sep 02, 2008 4:37 pm
by Scatman
Yah the only problem is if there is a wall in the way, the mob will grab their climbing gear and scale the mountain, no matter how steep it is! Not really a big deal right but maybe later on boundary detection will be put in?