• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Teleporting a player when they walk away or time out from an npc

Sportacus

Intermediate OT User
Joined
Aug 3, 2008
Messages
718
Reaction score
104
I want to force a player to get teleported to a location no matter what as long as they said hi to an npc, when the conversation ends.

And, I am just not sure how I work with the conditions of when a players ends the conversation by walking away, or timing out.

I am sure this is simple, I've just never done it before.
 
Last edited:
Just make it so when talk_state = 0, teleport the player to a pos. and when they say Hi make the talk_state = 1. Thats how I could do it in my distro. Using old stuff tho.
 
here is a npc system, its not mine. It will work for what you want.

LUA:
local focuses = {}
local playerInfos = {}
 
local function isFocused(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			return true
		end
	end
	return false
end
 
local function addFocus(cid)
	if(not isFocused(cid)) then
		table.insert(focuses, cid)
	end
end
 
local function removeFocus(cid)
	for i, v in pairs(focuses) do
		if(v == cid) then
			doTeleportThing(v, "type place here")   ----If you want normal NPC take this out. then it wont tp them on exit, you can do alot wit this npc system--
			table.remove(focuses, i)
			break
		end
	end
 
end
 
local function lookAtFocus()
	for i, v in pairs(focuses) do
		if(isPlayer(v) == TRUE) then
			doNpcSetCreatureFocus(v)
			return
		end
	end
end
 
function onCreatureDisappear(cid)
	if(isFocused(cid)) then
		selfSay("Good bye...")
		removeFocus(cid)
		if(isPlayer(cid) == TRUE) then --Be sure he's online
			closeShopWindow(cid)
		end
	end
end
 
function msgcontains(txt, str)
	return (string.find(txt, str) and not string.find(txt, '(%w+)' .. str) and not string.find(txt, str .. '(%w+)'))
end

 
function onCreatureSay(cid, type, msg)
 
	local msg = string.lower(msg)

-- HOW THIS WORKS!!!!!-----
if not isFocused(cid) and getDistanceTo(cid) < 4 and msgcontains(msg, "hi") then  -- if not focused and player says hi, and he is within 3 sqm. --
		selfSay("Welcome to the teleport you when you leave npc", cid) -- say this --
		addFocus(cid) -- add focus to the person --
return true
end

if isFocused(cid) and getDistanceTo(cid) < 4 and msgcontains(msg, "quest") then -- what ever the player says after they say hi --
	selfSay("say bye to teleport!") -- npc says this --
end

if isFocused(cid) and getDistanceTo(cid) < 4 and msgcontains(msg, "bye") then
	selfSay("TELEPORT NOW!")
	doTeleportThing(cid, "type place here")
	removeFocus(cid) -- always add this when you want npc to stop focusing...--
end
end


function onPlayerCloseChannel(cid)
	if(isFocused(cid)) then
		selfSay("Take care.")
		closeShopWindow(cid)
		removeFocus(cid)
		removeInfo(cid)
	end
end
 
function onThink()
	for i, focus in pairs(focuses) do
		if(isCreature(focus) == FALSE) then
			removeFocus(focus)
		else
			local distance = getDistanceTo(focus) or -1
			if((distance > 4) or (distance == -1)) then
				selfSay("Good Bye.", cid)
				closeShopWindow(focus)
				removeFocus(focus)
				removeInfo(cid)
			end
		end
	end
	lookAtFocus()
end
 
Last edited:
Back
Top