• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[NPC] Is it possible?

Jeremgod

New Member
Joined
Aug 9, 2007
Messages
93
Reaction score
3
Location
Quebec City, Canada
Hello

I was wondering if it's possible to determine a certain path for a NPC, In other words, I have a Patrol NPC just for looks I want him to be able to roam the streets only I don't want him to go everywhere, is it possible to make an NPC go from point A to point B (like if we would map click as a player) and more specifically waypoints, if so how do I do this? and can anyone show me an example of the code?

Thanks in advance, Jeremgod
 
I think you should disable autowaking from NPC and do script with function onThink() with selfMoveTo(x, y, z)
 
Code:
local waypoints, waypoint = {
}, 1

function onThink()
	if doComparePositions(getThingPosition(getNpcId()), waypoints[waypoint]) then
		waypoint = waypoint + 1
		if waypoint > #waypoints then
			waypoint = 1
		end

		selfMoveTo(waypoints[waypoint])
	end
end

I think something like this would work.
 
This will makes npc moves to the last position, and when the npc reachs the last position, returns to start position
Lua:
local waypoints =
{
	{x = 91, y = 127, z = 7},
	{x = 91, y = 128, z = 7},
	{x = 91, y = 129, z = 7},
	{x = 92, y = 128, z = 7},
	{x = 93, y = 129, z = 7}
}

local waypoint = 1
local lastWaypoint = 0
local interval = 5
local i = 5
function onThink()
	doCreatureSetNoMove(getNpcCid(), true)
	i = i + 1
	if i >= interval then
		if waypoint > #waypoints then
			waypoint = #waypoints - 1
		elseif waypoint < 1 then
			waypoint = 1
		end

		doTeleportThing(getNpcCid(), waypoints[waypoint], true)
		if waypoint > lastWaypoint or waypoint == lastWaypoint then
			lastWaypoint = waypoint
			waypoint = waypoint + 1
		else
			lastWaypoint = waypoint
			waypoint = waypoint - 1
		end
		i = 0
	end
end
 
Last edited:
Lua:
speed="10000"

Example
Lua:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Speed" script="default.lua" walkinterval="2000" speed="10000" floorchange="0">
	<health now="150" max="150"/>
	<look type="136" head="20" body="59" legs="117" feet="92" corpse="2212"/>
	<parameters>
		<parameter key="message_greet" value="Hello |PLAYERNAME|."/>
	</parameters>
</npc>
 
It does not work... for example I need the npc to walk the waypoints at the speed of a Rat, a Wolf, or a Sheep, but moving smooth.
 
If you want it to walk like a monster, just make the speed the same as the monster and the walkinterval really low.
 
I think he means like a constant movement like a monster, so wouldn't the interval be 0 and the speed be same as the monster?
 

Similar threads

Back
Top