Quote: "I'm looking for a way to make the npc disperse when entering the house"
do you mean you want it to disappear?
i would make an object to check the distance from (like the door of the house) then make the character hide(e) when within range and use a timer to continue the code after
so if we borrow honkey's pathing script from the post below
local turn_speed = {}
local destx = {}
local destz = {}
local hasEntered = {}
local houseE = 4 --entity number of the house / door / object to stop at
local waitTime = 600000 --time to wait til exiting house
local health = {}
function merchant_init(e)
turn_speed[e] = 4
destx[e] = 0
destz[e] = 0
CharacterControlUnarmed(e)
hasEntered[e] = 0
health[e] = -1
ai_soldier_pathindex[e] = -1
end
-- THIS SECTION CONTAINS THE WAYPOINT FOLLOWING CODE
function merchant_main(e)
EntObjNo = g_Entity[e]['obj']
CharacterControlUnarmed(e)
if hasEntered[e] == 1 then
if GetTimer(e) < waitTime then
return
else
hasEntered[e] = 2
Show(e)
CollisionOn(e)
end
end
if ai_soldier_pathindex[e] == -1 then
ai_soldier_pathindex[e] = -2
-- find initial waypoint path to follow
PathIndex = -1;
pClosest = 99999;
for pa = 1, AIGetTotalPaths(), 1 do
for po = 1 , AIGetPathCountPoints(pa), 1 do
pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po);
pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po);
pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ));
if pDist < pClosest and pDist < 200 then
pClosest = pDist;
PathIndex = pa;
end
end -- po
end -- pa
-- follow found path
if PathIndex > -1 then
ai_soldier_pathindex[e] = PathIndex;
ai_path_point_index[e] = 2
ModulateSpeed(e,1.0)
SetCharacterToWalk(e)
ai_path_point_direction[e] = 1
ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e])
end
end
-- If we have a path then lets patrol it
if ai_soldier_pathindex[e] > -1 then
ai_patrol_x[e] = AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e])
ai_patrol_z[e] = AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e])
AIEntityGoToPosition(EntObjNo,ai_patrol_x[e],ai_patrol_z[e])
tDistX = g_Entity[e]['x'] - ai_patrol_x[e]
tDistZ = g_Entity[e]['z'] - ai_patrol_z[e]
DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
if DistFromPath < 300 then
if hasEntered[e] == 0 then
local tdistx = g_Entity[e]['x'] - g_Entity[houseE]['x']
local tdistz = g_Entity[e]['z'] - g_Entity[houseE]['z']
local distfrompath = math.sqrt((tdistx*tdistx)+(tdistz*tdistz))
if distfrompath < 300 then
StartTimer(e)
hasEntered[e] = 1
Hide(e)
CollisionOff(e)
return
end
else
if ai_path_point_direction[e] == 1 then
ai_path_point_index[e] = ai_path_point_index[e] + 1
if ( ai_path_point_index[e] > ai_path_point_max[e] ) then
ai_path_point_index[e] = ai_path_point_max[e] -1
ai_path_point_direction[e] = 0
end
else
ai_path_point_index[e] = ai_path_point_index[e] - 1
if ( ai_path_point_index[e] < 1 ) then
ai_path_point_index[e] = 2
ai_path_point_direction[e] = 1
end
end
end
end
else
CharacterControlFidget(e)
end
end
-- END OF WAYPOINT FOLLOWING CODE