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

Lua Npcs Traveling Help

rodrilois

New Member
Joined
Jun 9, 2009
Messages
94
Reaction score
1
All npcs boat that has this script does not work in my ot

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 travelNodes = {
	["edron"] = {cost = 20, pos = {x = 33175, y = 31764, z = 6}, text = "Edron"},
	["eremo"] = {cost = 0, pos = {x = 33314, y = 31882, z = 6}, text = "Eremo island"},
}

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

	-- POSTMAN QUEST DISCOUNT
	discount = 0
	if(getPlayerStorageValue(cid, 250) >= 38) then
		discount = 10
	end
	-- POSTMAN QUEST DISCOUNT
	
	if(msgcontains(msg, "marlin")) then
		if(getPlayerItemCount(cid, 7963) >= 1) then
			npcHandler:say("WOW! You have a marlin!! I could make a nice decoration for your wall from it. May I have it?", cid)
			talkState[talkUser] = 1
		end
	elseif(msgcontains(msg, "yes")) then
		if(travelState[talkUser]) then
			if(getPlayerMoney(cid) >= math.max(0, travelNodes[travelState[talkUser]].cost - discount)) then
				doPlayerRemoveMoney(cid, math.max(0, travelNodes[travelState[talkUser]].cost - discount))
				doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
				doSendMagicEffect(travelNodes[travelState[talkUser]].pos, CONST_ME_TELEPORT)
				doTeleportThing(cid, travelNodes[travelState[talkUser]].pos)
				-- ACHIEVEMENT
				if(getPlayerStorageValue(cid, 1133) < 1250) then
					setPlayerStorageValue(cid, 1133, math.max(0, getPlayerStorageValue(cid, 1133)) + 1)
				else
					if(getPlayerAchievement(cid, 253) == false) then
						doPlayerAddAchievement(cid, 253)
					end
				end
				-- ACHIEVEMENT
			else
				npcHandler:say("You don't have enought money.", cid)
			end
		elseif(talkState[talkUser] == 1) then
			if(getPlayerItemCount(cid, 7963) >= 1) then
				npcHandler:say("Yeah! Now let's see... <fumble fumble> There you go, I hope you like it! ", cid)
				doPlayerAddItem(cid, 7964, 1)
				doPlayerRemoveItem(cid, 7963, 1)
				talkState[talkUser] = 0
			else
				npcHandler:say("You don't have the fish.", cid)
				talkState[talkUser] = 0
			end
		end
		travelState[talkUser] = nil
	elseif(msgcontains(msg, "no")) then
		travelState[talkUser] = nil
		npcHandler:say("Then no.", cid)
	else
		for k, v in ipairs(travelNodes) do
			if(msgcontains(msg, "yes")) then
				npcHandler:say("Do you want to travel to " .. v.text .. " for " .. (math.max(0, travelNodes[travelState[talkUser]].cost - discount) == 0) and "free" or (travelNodes[travelState[talkUser]].cost - discount .. "gold") .. "?", cid)
				travelState[talkUser] = 0
			end
		end
	end
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

I do not know if the problem of the libs on this npc, my server is version 9.83.

All npcs boat that has this not work:
LUA:
local travelNodes = {
	["ab'dendriel"] = {cost = 130, pos = {x = 32734, y = 31669, z = 6}, text = "Ab'Dendriel"},
	["carlin"] = {cost = 110, pos = {x = 32387, y = 31821, z = 6}, text = "Carlin"},
	["edron"] = {cost = 160, pos = {x = 33175, y = 31764, z = 6}, text = "Edron"},
	["liberty bay"] = {cost = 180, pos = {x = 32285, y = 32890, z = 6}, text = "Liberty Bay"},
	["port hope"] = {cost = 160, pos = {x = 32592, y = 32784, z = 6}, text = "Port Hope"},
	["svargrond"] = {cost = 180, pos = {x = 32341, y = 31108, z = 6}, text = "Svargrond"},
	["venore"] = {cost = 170, pos = {x = 32955, y = 32022, z = 6}, text = "Venore"},
}


Example of an NPC boat

LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local travelState = {}
 
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 travelNodes = {
	["ab'dendriel"] = {cost = 130, pos = {x = 32734, y = 31669, z = 6}, text = "Ab'Dendriel"},
	["carlin"] = {cost = 110, pos = {x = 32387, y = 31821, z = 6}, text = "Carlin"},
	["edron"] = {cost = 160, pos = {x = 33175, y = 31764, z = 6}, text = "Edron"},
	["liberty bay"] = {cost = 180, pos = {x = 32285, y = 32890, z = 6}, text = "Liberty Bay"},
	["port hope"] = {cost = 160, pos = {x = 32592, y = 32784, z = 6}, text = "Port Hope"},
	["svargrond"] = {cost = 180, pos = {x = 32341, y = 31108, z = 6}, text = "Svargrond"},
	["venore"] = {cost = 170, pos = {x = 32955, y = 32022, z = 6}, text = "Venore"},
}

function creatureSayCallback(cid, type, msg)
	if(not(npcHandler:isFocused(cid))) then
		return false
	end
	local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
	
	-- POSTMAN QUEST DISCOUNT
	discount = 0
	if(getPlayerStorageValue(cid, 250) >= 38) then
		discount = 10
	end
	-- POSTMAN QUEST DISCOUNT
	
	if(msgcontains(msg, "yes")) then
		if(travelState[talkUser]) then
			if(getPlayerMoney(cid) >= travelNodes[travelState[talkUser]].cost - discount) then
				doPlayerRemoveMoney(cid, travelNodes[travelState[talkUser]].cost - discount)
				doSendMagicEffect(getPlayerPosition(cid), CONST_ME_TELEPORT)
				doSendMagicEffect(travelNodes[travelState[talkUser]].pos, CONST_ME_TELEPORT)
				doTeleportThing(cid, travelNodes[travelState[talkUser]].pos)
				-- ACHIEVEMENT
				if(getPlayerStorageValue(cid, 1133) < 1250) then
					setPlayerStorageValue(cid, 1133, math.max(0, getPlayerStorageValue(cid, 1133)) + 1)
				else
					if(getPlayerAchievement(cid, 253) == false) then
						doPlayerAddAchievement(cid, 253)
					end
				end
				-- ACHIEVEMENT
			else
				npcHandler:say("You don't have enought money.", cid)
			end
		end
		travelState[talkUser] = nil
	elseif(msgcontains(msg, "no")) then
		travelState[talkUser] = nil
		npcHandler:say("Then no.", cid)
	else
		for k, v in ipairs(travelNodes) do
			if(msgcontains(msg, k)) then
				npcHandler:say("Do you want to travel to " .. v.text .. " for " .. v.cost - discount .. " gold?", cid)
				travelState[talkUser] = k
			end
		end
	end
	return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top