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

[ easy ] npc exchanger

lorduke

New Member
Joined
May 22, 2009
Messages
32
Reaction score
1
Hello,

I would like a npc exchanger,if player have 30 soul orbs he can exchanger for a royal helmet,and 50 orbs for 1kk of experience.

Im using TFS 0.3.6

Regards,
Lorduke.
 
not tested;
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 needItems = {id = {2176}, count = {50}}
	local tradeItems = {id = {2498}, count = {1}}
	
	if(msgcontains(msg, 'exchange') or msgcontains(msg, 'change')) then
		selfSay('Do you want to change '.. needItems.count[1] ..' '.. getItemNameById(needItems.id[1]) ..'s for '.. tradeItems.count[1] ..' '.. getItemNameById(tradeItems.id[1]) ..'?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, needItems.id[1]) >= needItems.count[1]) then
				doPlayerRemoveItem(cid, needItems.id[1], needItems.count[1])
				doPlayerAddItem(cid, tradeItems.id[1], tradeItems.count[1])
				selfSay('Here you are.', cid)
		else
				selfSay('Sorry, you dont\'t have the item with you.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Yea, but you can only change 1 item for 1 item. Just write the item id. But you cannot do more items. I have'nt done that in the script.
But does it work?
 
not tested;
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 needItems = {id = {2176}, count = {50}}
	local tradeItems = {id = {2498}, count = {1}}
	
	if(msgcontains(msg, 'exchange') or msgcontains(msg, 'change')) then
		selfSay('Do you want to change '.. needItems.count[1] ..' '.. getItemNameById(needItems.id[1]) ..'s for '.. tradeItems.count[1] ..' '.. getItemNameById(tradeItems.id[1]) ..'?', cid)
		talkState[talkUser] = 1
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, needItems.id[1]) >= needItems.count[1]) then
				doPlayerRemoveItem(cid, needItems.id[1], needItems.count[1])
				doPlayerAddItem(cid, tradeItems.id[1], tradeItems.count[1])
				selfSay('Here you are.', cid)
		else
				selfSay('Sorry, you dont\'t have the item with you.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return true
end

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

I will test it now :)
 
Back
Top