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

Trade in items for Experience/another item

  • Thread starter Thread starter Deleted member 49793
  • Start date Start date
D

Deleted member 49793

Guest
Hey so basicly an npc that you can trade items to for either like example

trade in 10 shrimp (id 2670) for either 10,000 experience or an amulet of loss.
(with more than one example so loops or something) :)

Thank you.
~Moist
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}
local items = {
	[{2670,10}] = 10000
}

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)
	for v, x in ipairs(items) do
		if (msgcontains(msg, "hello") or msgcontains(msg, "hi")) and (not npcHandler:isFocused(cid)) then
			if getPlayerItemCount(cid, v[1]) >= v[2] then
				npcHandler:say("Hello " .. getCreatureName(cid) .. ". Would you like to {exchange} 10 shrimp for some experience?", cid)
				Topic[cid] = 1
			else
				npcHandler:say("Hmm...don't think I can help you.", cid)
				Topic[cid] = 0
			end
			npcHandler:addFocus(cid)
		elseif(not npcHandler:isFocused(cid)) then
			return false
		elseif Topic[cid] == 1 then
			if msgcontains(msg, "exchange") then
				npcHandler:say("Are you sure you want to exchange " .. v[2] .. "x " .. getItemInfo(v[1]).name .. " for " .. x .. " experience points?", cid)
				Topic[cid] = 2
			else
				npcHandler:say("What was that? I don't understand you.", cid)
				Topic[cid] = 1
			end
		elseif Topic[cid] == 2 then
			if msgcontains(msg, "yes") then
				if doPlayerRemoveItem(cid, v[1], v[2] or 1) then
					npcHandler:say("Great! Here you are.", cid)
					doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
					doPlayerAddExperience(cid, x)
					Topic[cid] = 0
				else
					npcHandler:say("You do not have the item with you.", cid)
					Topic[cid] = 0
				end
			elseif msgcontains(msg, "no") then
				npcHandler:say("Well, then leave.", cid)
				Topic[cid] = 0
			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
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Have a good day!")
 
Last edited:
Back
Top