• 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!

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

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.
 
Post npc script.

Not much to look at. Mostly am asking how.

Either way, here it is:

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
---------------------------------------------------------
	if(msgcontains(msg, 'yes')) then
		doTeleportThing(cid, {x = 37, y = 117, z = 7})
		npcHandler:say("Good luck in there!", cid)
	elseif(msgcontains(msg, 'no')) then
		doTeleportThing(cid, {x = 37, y = 117, z = 7})
		npcHandler:say("Too bad, you are going in anyway.", cid)
		return true
	end
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end

local function creatureFarewell(cid)
    if not(isPlayer(cid)) then return true end
    doTeleportThing(cid, {x = 37, y = 117, z = z})
	return true
end



function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
---------------------------------------------------------
	if(msgcontains(msg, 'yes')) then
		doTeleportThing(cid, {x = 37, y = 117, z = 7})
		npcHandler:say("Good luck in there!", cid)
	elseif(msgcontains(msg, 'no')) then
		doTeleportThing(cid, {x = 37, y = 117, z = 7})
		npcHandler:say("Too bad, you are going in anyway.", cid)
		return true
	end
end
 
npcHandler:setCallback(CALLBACK_FAREWELL, creatureFarewell)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureFarewell)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
I made this one earlier when I saw your thread in requests, so just change the message part (I've tested it on 0.3).
LUA:
local fight = createConditionObject(CONDITION_INFIGHT)
setConditionParam(fight, CONDITION_PARAM_TICKS, 90000) --time in seconds x1000

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
 
function onCreatureAppear(cid)                  npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)               npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)          npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                              npcHandler:onThink() end
 
local function greetCallback(cid)
	if isPlayer(cid) then
		doAddCondition(cid, fight)
	end
	return true
end

local function farewellCallBack(cid)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	if (getCreatureCondition(cid, CONDITION_INFIGHT)) then
		doRemoveCondition(cid, CONDITION_INFIGHT)
	end
	doTeleportThing(cid, {x=37,y=117,z=7})
	return true
end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end

	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	if(msgcontains(msg, 'yes')) then
		doTeleportThing(cid, {x = 37, y = 117, z = 7})
		npcHandler:say("Good luck in there!", cid)
	elseif(msgcontains(msg, 'no')) then
		doTeleportThing(cid, {x = 37, y = 117, z = 7})
		npcHandler:say("Too bad, you are going in anyway.", cid)
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_FAREWELL, farewellCallBack)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, farewellCallBack)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Edit: nvm, added your message part.
 
Last edited:
Back
Top