• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Best travel NPC

why don't you just edit the old code? Example:
Lua:
local travelNode = keywordHandler:addKeyword({'liberty bay'}, {npcHandler = npcHandler, premium = true, level = 0, cost = 160, destination = {x=32816, y=31272, z=6} })
 
Can you add the npc lua also? Cuz I dont have a travel npc, and if I copy another then it will just accept the word trade or offer.
 
Not needed elseif if you use a table here...
Here is the script remade with tables, easier if you want to add a new city, you just have to add a new line on citys and edit money and pos.
Lua:
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 citys = {
	['thais'] = {money = 100, pos={x=32311, y=32210, z=6}},
	['carlin'] ={money = 100, pos={x=32387, y=31821, z=6}}
}

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

	if citys[msg] and not isPlayerPzLocked(cid) then
		if doPlayerRemoveMoney(cid, citys[msg].money) == true then
			doTeleportThing(cid,citys[msg].pos)
			self:releaseFocus(cid)					
		else
			npcHandler:say('You don\'t have enought money to travel!', cid) 
			self:releaseFocus(cid)
		end
	else
		npcHandler:say('I cant travel there!', cid) 
		self:releaseFocus(cid)
	end

	if isPlayerPzLocked(cid) then
		npcHandler:say('You can\'t travel, you have pz!', cid) 
	end

	return true
end		
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
keywordHandler:addKeyword({'travel'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'I can take you to all places: {thais}, {carlin}.'})

npcHandler:addModule(FocusModule:new())

I only replaced if msgcontains for if citys[msg] validating that the msg is on the table 'citys' (only thais and carlin by default), else npc would say 'I cant travel there!.

EDIT loool this thread is fukcing old haha, didnt realize, sorry.
 
Last edited:
Back
Top