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

Traveler NPC to 3 different locations

breadmaker

New Member
Joined
Jul 16, 2010
Messages
160
Reaction score
3
Hello.
I want an NPC for TFS 0.3.6pl1.

Example:
- Hi
- Hello |PlayerName|, what can I do for you ?
- travel
- I can travel you to : "north", "west" or "east" sector.
- if i choose north or west or east i going to X,Y,Z (west X,Y,Z, east, north)
( all prizes are same! )
If player have storage X,Y,Z then travel cost is cheapest and the greetings message is different.

Anyone ?
 
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local list, t, cost = {
	['north'] = {x=100, y=100, z=7},
	['west'] = {x=100, y=100, z=7},
	['east'] = {x=100, y=100, z=7}
}, {}, {}

local storage = 123

cost.normal = 20
cost.cheap = 10

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 greetCallback(cid)
	if getCreatureStorage(cid, storage) == -1 then
		npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|, what can I do for you ?')
	else
		npcHandler:setMessage(MESSAGE_GREET, 'Hello |PLAYERNAME|, what can I do for you? You have strong storage Xdd!?')
	end
	t[cid] = nil
	return true
end

function creatureSayCallback(cid, type, msg)
	if not npcHandler:isFocused(cid) then
		return false
	elseif t[cid] then
		if msgcontains(msg, 'yes') then
			if doPlayerRemoveMoney(cid, getCreatureStorage(cid, storage) == -1 and cost.normal or cost.cheap) then
				npcHandler:say('Here we go!', cid)
				npcHandler:releaseFocus(cid)
				local p = getThingPos(cid)
				doTeleportThing(cid, list[t[cid]])
				doSendMagicEffect(p, CONST_ME_TELEPORT)
				doSendMagicEffect(list[t[cid]], CONST_ME_TELEPORT)
			else
				npcHandler:say('You don\'t have enough money.', cid)
			end
		else
			npcHandler:say('Perhaps next time.', cid)
		end
	elseif msgcontains(msg, 'travel') then
		local s = {}
		for k, v in pairs(list) do
			table.insert(s, '{' .. k .. '}')
		end
		npcHandler:say('I can travel you to: ' .. table.concat(s, ', ') .. '.', cid)
	else
		for k, v in pairs(list) do
			if msgcontains(msg, k) then
				t[cid] = k
				npcHandler:say('Do you want to travel to ' .. k .. ' for ' .. (getCreatureStorage(cid, storage) == -1 and cost.normal or cost.cheap) ..' gold?', cid)
				break
			end
		end
	end
	return true
end

npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Back
Top