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

Boat NPC check storage

kalle303

New Member
Joined
Oct 13, 2007
Messages
108
Reaction score
4
Location
Sweden
Hello!

I need help with a boat NPC that will only allow players with a spesific storage to travel. (3 destinations)

Thanks to everyone that helps! (Rep++)

/Kalle303
 
Here's my current script:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

-- OTServ event handling functions start
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
-- OTServ event handling functions end

	local travelNode = keywordHandler:addKeyword({'gengia'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to gengia?'})
        	travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 0, cost = 0, destination = {x=34472, y=32697, z=6} })
        	travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Then stay here!'}) 
	
	local travelNode = keywordHandler:addKeyword({'pyre'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to pyre?'})
        	travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 0, cost = 0, destination = {x=33623, y=4003, z=6} })
        	travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Then stay here!'}) 

	local travelNode = keywordHandler:addKeyword({'oken'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, text = 'Do you want to travel to oken?'})
        	travelNode:addChildKeyword({'yes'}, StdModule.travel, {npcHandler = npcHandler, premium = true, level = 0, cost = 0, destination = {x=19990, y=20008, z=6} })
        	travelNode:addChildKeyword({'no'}, StdModule.say, {npcHandler = npcHandler, onlyFocus = true, reset = true, text = 'Then stay here!'}) 

npcHandler:addModule(FocusModule:new())
 
I made it my way:

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
	
	local travels = {
	["gengia"] = {talk=1, cost=0, level=0, stor=true, storId=34343, destination={x=34472, y=32697, z=6}},
	["pyre"] = {talk=2, cost=0, level=0, stor=false, storId=43433, destination={x=33623, y=4003, z=6}}
	}
	
	for k, v in pairs(travels) do
		if(msgcontains(msg, k)) then
			if v.stor then
				if getPlayerStorageValue(cid, v.storId) > 0 then
					selfSay('Do you want to travel to '..k..' for '..v.cost..' gold coins?', cid)
					talkState[talkUser] = v.talk
				else
				selfSay('You are not able to travel to this place?', cid)
				talkState[talkUser] = 0	
				end
			else
			selfSay('Do you want to travel to '..k..' for '..v.cost..' gold coins?', cid)
			talkState[talkUser] = v.talk
			end		
		elseif(msgcontains(msg, 'yes') and talkState[talkUser] == v.talk) then
				if getPlayerLevel(cid) >= v.level then
					if(doPlayerRemoveMoney(cid, v.cost) == TRUE) then
						doTeleportThing(cid, v.destination, FALSE)
						selfSay('Traveled to '..k..'.', cid)
					else
					selfSay('Sorry, you don\'t have enough gold coins.', cid)
					end
				else
				selfSay('Sorry, you don\'t have enough level.', cid)
				end	
		talkState[talkUser] = 0
		elseif(msgcontains(msg, 'no') and isInArray({v.talk}, talkState[talkUser]) == TRUE) then
			talkState[talkUser] = 0
			selfSay('Ok then.', cid)
		end
	end	

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

If you whant to enter a new travel just add a new line in the table of "travel":

Lua:
	local travels = {
	["gengia"] = {talk=1, cost=0, level=0, stor=true, storId=34343, destination={x=34472, y=32697, z=6}},
	["pyre"] = {talk=2, cost=0, level=0, stor=false, storId=43433, destination={x=33623, y=4003, z=6}}
	}

You can config(cost, level, stor, storId and destination).
[] Brackets = The message you wll tell to the npc.
Talk = For each travel you add you most add +1
Level = Level to be able to travel
Stor = true/false
StorId = You only need to config this if "Stor" is equal true.
Destination = The destination to be traveled.
 
Back
Top