• 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 [NPC] NPC only trades with a storage value

WSouls

New Member
Joined
Aug 5, 2010
Messages
51
Reaction score
1
the bug right now is that the NPC always accepts the trade even if you dont have the storage value

Code:
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 shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
--  Valuables
--buying them
shopModule:addBuyableItem({'black pearl'}, 2144, 560)
--shopModule:addBuyableItem({'orichalcum pearl'}, 5022, 80)
shopModule:addBuyableItem({'small amethyst'}, 2150, 400)
shopModule:addBuyableItem({'small diamond'}, 2145, 600)
shopModule:addBuyableItem({'small emerald'}, 2149, 500)
shopModule:addBuyableItem({'small ruby'}, 2147, 500)
shopModule:addBuyableItem({'small sapphire'}, 2146, 400)
shopModule:addBuyableItem({'white pearl'}, 2143, 320)
--selling them
shopModule:addSellableItem({'black pearl'}, 2144, 280)
shopModule:addSellableItem({'blue gem'}, 2158, 5000)
shopModule:addSellableItem({'Crystal of Balance'}, 9942, 1000)
shopModule:addSellableItem({'Crystal of Focus'}, 9941, 2000)
shopModule:addSellableItem({'Crystal of Power'}, 9980, 3000)
shopModule:addSellableItem({'emerald bangle'}, 2127, 800)
--shopModule:addSellableItem({'giant shimmering pearl'}, 2127, 3000)
shopModule:addSellableItem({'green gem'}, 2155, 5000)
shopModule:addSellableItem({'red gem'}, 2156, 1000)
shopModule:addSellableItem({'scarab coin'}, 2159, 100)
shopModule:addSellableItem({'silver brooch'}, 4845, 150)
shopModule:addSellableItem({'small amethyst'}, 2150, 200)
shopModule:addSellableItem({'small diamond'}, 2145, 300)
shopModule:addSellableItem({'small emerald'}, 2149, 250)
shopModule:addSellableItem({'small ruby'}, 2147, 250)
shopModule:addSellableItem({'small sapphire'}, 2146, 200)
shopModule:addSellableItem({'small topaz'}, 9970, 200)
shopModule:addSellableItem({'violet gem'}, 2153, 10000)
shopModule:addSellableItem({'white pearl'}, 2143, 160)
shopModule:addSellableItem({'yellow gem'}, 2154, 1000)

--rings
--buying
shopModule:addBuyableItem({'dwarven ring'}, 2213, 2000) 
shopModule:addBuyableItem({'energy ring'}, 2167, 2000) 
shopModule:addBuyableItem({'might ring'}, 2164, 5000) 
shopModule:addBuyableItem({'power ring'}, 2166, 100) 
shopModule:addBuyableItem({'time ring'}, 2169, 2000) 
shopModule:addBuyableItem({'wedding ring'}, 2121, 1000000)
--selling
shopModule:addSellableItem({'axe ring'}, 2208, 100) 
shopModule:addSellableItem({'club ring'}, 2209, 100)
shopModule:addSellableItem({'crystal ring'}, 2124, 250)
shopModule:addSellableItem({'death ring'}, 6300, 1000)
shopModule:addSellableItem({'dwarven ring'}, 2213, 100)
shopModule:addSellableItem({'energy ring'}, 2167, 100)
shopModule:addSellableItem({'might ring'}, 2164, 250)
shopModule:addSellableItem({'power ring'}, 2166, 50) 
shopModule:addSellableItem({'ring of the sky'}, 2123, 30000)
shopModule:addSellableItem({'sword ring'}, 2207, 100) 
shopModule:addSellableItem({'time ring'}, 2169, 100)
shopModule:addSellableItem({'wedding ring'}, 2121, 100)

function creatureSayCallback(cid, type, msg)
	if(msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
		npcHandler:say("Hello " .. getCreatureName(cid) .. ". Come have a look at my rare gem collection.", cid)
		if getPlayerStorageValue(cid, 49968) == 1 then
			Topic[cid] = 1
		else
			Topic[cid] = nil
		end
		npcHandler:addFocus(cid)
	elseif(not npcHandler:isFocused(cid)) then
		return false
	elseif  msgcontains(msg, "help") or msgcontains(msg, "quest") then
		if getPlayerStorageValue(cid, 49968) == -1 then
			npcHandler:say("Well I need a few items before you can use my shop. Come back to me when you find me something to hard enough to turn diamonds into dust, and at least 65 rare gems.", cid)
			doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
			setPlayerStorageValue(cid, 49968, 2)
		elseif getPlayerStorageValue(cid, 49968) == 2 then
			local esapphire = getPlayerItemCount(cid, 7759)
			local eruby = getPlayerItemCount(cid, 7760)
			local eemerald = getPlayerItemCount(cid, 7761)
			local eamethyst = getPlayerItemCount(cid, 7762)
			if esapphire + eruby + eemerald + eamethyst >= 65 then
				if doPlayerTakeItem(cid,4846,1) == LUA_NO_ERROR and doPlayerTakeItem(cid,7759,esapphire) == LUA_NO_ERROR and doPlayerTakeItem(cid,7760,eruby) == LUA_NO_ERROR and doPlayerTakeItem(cid,7761,eemerald) == LUA_NO_ERROR and doPlayerTakeItem(cid,7762,eamethyst) == LUA_NO_ERROR then
					npcHandler:say("Thank you this will surely help me with my crafting of jewerly. You may now take advantage of my inventory.", cid)
					setPlayerStorageValue(cid, 49968, 1)
				else
					npcHandler:say("You are also suppose to bring me something that can turn diamonds into dust.", cid)
				end
			else
				npcHandler:say("You need to get some more rare gems.", cid)
			end
		else
			npcHandler:say("You have already helped me in thanks your allowed to use my shop.", cid)
			Topic[cid] = nil
			npcHandler:releaseFocus(cid)
		end
	elseif msgcontains(msg, "trade") or msgcontains(msg, "offer") then
		if Topic[cid] == 1 then
			doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
			npcHandler:say("Here are my offers!", cid)
			Topic[cid] = 1
		else
			npcHandler:say("You have to help me first if you want to see my offers.", cid)
		end
	elseif msgcontains(msg, "bye") or msgcontains(msg, "farewell") and npcHandler:isFocused(cid) then
		npcHandler:say("Good bye.", cid, TRUE)
		Topic[cid] = nil
		npcHandler:releaseFocus(cid)
	end

	return true
end

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