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

Addon Item Exchanger Problem!

Edling

Member
Joined
Mar 1, 2009
Messages
246
Reaction score
11
Can't get this to work... Spool yarn works, fire sword works and chicken wing works. But not warrior sweat and fighting spirit
Problem solved, updated the script here which will only exchange magic sulphur, fighting spirit, enchanted chicken wing, warrior sweat, and spool of yarns!

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 
  
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 cycmsg = 'Cling Clang!' 
        local noimsg = 'Dont try to fool me!' 
        local deny      = 'Not sure eh?' 
        local infbolt = 4 -- change this to adjust the number of infernal bolts you want to give to the players for 1 soul orb. 
  
  
--------------------MESSAGES------------------------------------------------------------------------------ 
    if msgcontains(msg, 'help') or msgcontains(msg, 'trade') then 
                selfSay('I can exchange some equipment for other specialties...}.', cid) 
  
        elseif msgcontains(msg, 'spool of yarn') then 
                selfSay('You sure you want to make this exchange?', cid) 
                talkState[talkUser] = 1 
  
        elseif msgcontains(msg, 'warrior sweat') then 
                selfSay('You sure you want to make this exchange?', cid) 
                talkState[talkUser] = 2 
  
        elseif msgcontains(msg, 'magic sulphur') then 
                selfSay('You sure you want to make this exchange?', cid) 2195
                talkState[talkUser] = 3 
  
        elseif msgcontains(msg, 'enchanted chicken wing') then 
                selfSay('You sure you want to make this exchange?', cid) 
                talkState[talkUser] = 4 
				
        elseif msgcontains(msg, 'fighting spirit') then 
                selfSay('You sure you want to make this exchange?', cid) 
                talkState[talkUser] = 5
  
-------------GETTING METALS FROM HIM------------------- 
  
        -- Fighting Spirit 
        elseif talkState[talkUser] == 5 then 
                if msgcontains(msg, 'yes') then 
                        if doPlayerTakeItem(cid, 2498, 2) == true then 
                                doPlayerAddItem(cid, 5884, 1) 
                                selfSay(cycmsg, cid) 
                                talkState[talkUser] = 0 
                        else 
                                selfSay(noimsg, cid) 
                                talkState[talkUser] = 0 
                        end 
                else 
                        selfSay(deny, cid) 
                        talkState[talkUser] = 0 
                end 
        -- Chicken Wing 
        elseif talkState[talkUser] == 4 then 
                if msgcontains (msg, 'yes') then 
                        if doPlayerTakeItem(cid, 2195, 1) == true then 
                                doPlayerAddItem(cid, 5891, 1) 
                                selfSay(cycmsg, cid) 
                                talkState[talkUser] = 0 
                        else 
                                selfSay(noimsg, cid) 
                                talkState[talkUser] = 0 
                        end 
                else 
                        selfSay(deny, cid) 
                        talkState[talkUser] = 0 
                end  
        -- Magic Sulphur 
        elseif talkState[talkUser] == 3 then 
                if msgcontains (msg, 'yes') then 
                        if doPlayerTakeItem(cid, 2392, 3) == true then 
                                doPlayerAddItem(cid, 5904, 1) 
                                selfSay(cycmsg, cid) 
                                talkState[talkUser] = 0 
                        else 
                                selfSay(noimsg, cid) 
                                talkState[talkUser] = 0 
                        end 
                else 
                        selfSay(deny, cid) 
                        talkState[talkUser] = 0 
                end   
        -- Warrior Sweat 
        elseif talkState[talkUser] == 2 then 
                if msgcontains (msg, 'yes') then 
                        if doPlayerTakeItem(cid, 2475, 4) == true then 
                                doPlayerAddItem(cid, 5885, 1) 
                                selfSay(cycmsg, cid) 
                                talkState[talkUser] = 0 
                        else 
                                selfSay(noimsg, cid) 
                                talkState[talkUser] = 0 
                        end 
                else 
                        selfSay(deny, cid) 
                        talkState[talkUser] = 0 
                end   
        -- Spool Yarn 
        elseif talkState[talkUser] == 1 then 
                if msgcontains (msg, 'yes') then 
                        if doPlayerTakeItem(cid, 5879, 10) == true then 
                                doPlayerAddItem(cid, 5886, 1) 
                                selfSay(cycmsg, cid) 
                                talkState[talkUser] = 0 
                        else 
                                selfSay(noimsg, cid) 
                                talkState[talkUser] = 0 
                        end 
                else 
                        selfSay(deny, cid) 
                        talkState[talkUser] = 0 
                end              
        end 
end 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) 
npcHandler:addModule(FocusModule:new())
 
Last edited:
you can use this:
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 item = 'I\'m sorry, but you do not have the required items for this trade.'
local done = 'Here you are, thank you for your business.'

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	if msgcontains(msg, 'exchange') then
		selfSay('You can here change some items for {spider silk yarn}, {chunk of crude iron}, {draconian steel}, {warrior sweat}, {magic sulphur}, {enchanted chicken wing}, {royal steel}, {hell steel}, {fighting spirit}, {infernal bolt}.', cid)
	elseif msgcontains(msg, 'spider silk yarn') then
		if getPlayerItemCount(cid,5879) >= 10 then
			selfSay('Did you bring me the 10 giant spider silk?', cid)
			talk_state = 1
		else
			selfSay('I need a {10 giant spider silk}, to give you one spider silk yarn. Please come back when you have them.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 1 then
		talk_state = 0
		if getPlayerItemCount(cid,5879) >= 10 then
			if doPlayerRemoveItem(cid,5879, 10) == TRUE then
				selfSay(done, cid)
				doPlayerAddItem(cid, 5886, 1)
			end
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'chunk of crude iron') then
		if getPlayerItemCount(cid,2393) >= 1 then
			selfSay('Did you bring me the giant sword ?', cid)
			talk_state = 2
		else
			selfSay('I need a {giant sword}, to give you the chunk of crude iron. Come back when you have it.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 2 then
		talk_state = 0
		if getPlayerItemCount(cid,2393) >= 1 then
			if doPlayerRemoveItem(cid,2393,1) == TRUE then
				selfSay(done, cid)
				doPlayerAddItem(cid,5892,1)
			end
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'draconian steel') then
		if getPlayerItemCount(cid,2516) >= 1 then
			selfSay('Did you bring me dragon shield ?', cid)
			talk_state = 3
		else
			selfSay('I need {dragon shield}, to give you the draconian steel. Come back when you have it.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 3 then
		talk_state = 0
		if getPlayerItemCount(cid,2516) >= 1 then
			if doPlayerRemoveItem(cid,2516,1) == TRUE then
				doPlayerAddItem(cid,5889,1)
				selfSay(done, cid)
			end
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'warrior\'s sweat') then
		if getPlayerItemCount(cid,2475) >= 1 and getPlayerItemCount(cid,2475) >= 1 and getPlayerItemCount(cid,2475) >= 1 and getPlayerItemCount(cid,2475) >= 1 then
			selfSay('Did you bring me 4 warrior helmets?', cid)
			talk_state = 4
		else
			selfSay('I need {4 warrior helmet\'s}, to give you the warrior\'s sweat. Come back when you have them.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 4 then
		talk_state = 0
		if getPlayerItemCount(cid,2475) >= 4 then
			for i = 1, 4 do
				doPlayerRemoveItem(cid, 2475, i)
			end
			doPlayerAddItem(cid,5885,1)
			selfSay(done, cid)
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'magic sulphur') then
		if getPlayerItemCount(cid,2392) >= 3 then
			selfSay('Did you bring me 3 fire swords?', cid)
			talk_state = 5
		else
			selfSay('I need {3 fire sword\'s}, to give you the magic sulpher. Come back when you have them.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 5 then
		talk_state = 0
		if getPlayerItemCount(cid,2392) >= 3 then
			for i = 1, 4 do
				doPlayerRemoveItem(cid, 2392, i)
			end
			doPlayerAddItem(cid,5904,1)
			selfSay(done, cid)
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'enchanted chicken wing') then
		if getPlayerItemCount(cid,2195) >= 1 then
			selfSay('Did you bring me boots of haste?', cid)
			talk_state = 6
		else
			selfSay('I need {boots of haste}, to give you the enchanted chicken wing. Come back when you have them.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 6 then
		talk_state = 0
		if getPlayerItemCount(cid,2195) >= 1 then
			doPlayerRemoveItem(cid,2195,1)
			doPlayerAddItem(cid,5891,1)
			selfSay(done, cid)
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'royal steel') then
		if getPlayerItemCount(cid,2487) >= 1 then
			selfSay('Did you bring me the Crown Armor ?', cid)
			talk_state = 7
		else
			selfSay('I need a {crown armor}, to give you the royal steel. Come back when you have it.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 7 then
		talk_state = 0
		if getPlayerItemCount(cid,2487) >= 1 then
			if doPlayerRemoveItem(cid,2487,1) == TRUE then
				doPlayerAddItem(cid,5887,1)
				selfSay(done, cid)
			end
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'hell steel') then
		if getPlayerItemCount(cid,2462) >= 1 then
			selfSay('Did you bring me the devil helmet ?', cid)
			talk_state = 8
		else
			selfSay('I need a {devil helmet}, to give you the hell steel. Come back when you have it.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 8 then
		talk_state = 0
		if getPlayerItemCount(cid,2462) >= 1 then
			if doPlayerRemoveItem(cid,2462,1) == TRUE then
				doPlayerAddItem(cid,5888,1)
				selfSay(done, cid)
			end
		else
			selfSay(item, cid)
		end
	elseif msgcontains(msg, 'fighting spirit') then
		if getPlayerItemCount(cid,2498) >= 2 then
			selfSay('Did you bring me the 2 royal helmets?', cid)
			talk_state = 10
		else
			selfSay('I need a {2 royal helmet\'s}, to give you the Fighting Spirit. Come back when you have them.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 10 then
		talk_state = 0
		if getPlayerItemCount(cid,2498) >= 2 then
			for i = 1, 2 do
				doPlayerRemoveItem(cid, 2498, i)
			end
			doPlayerAddItem(cid,5884,1)
			selfSay(done, cid)
		else
			selfSay(item, cid)
		end


	elseif msgcontains(msg, 'infernal bolt') then
		if getPlayerItemCount(cid,5944) >= 1 then
			selfSay('Did you bring me the soul orb?', cid)
			talk_state = 11
		else
			selfSay('I need a {soul orb}, to give you the 10 Infernal Bolts. Come back when you have it.', cid)
			talk_state = 0
		end
	elseif msgcontains(msg, 'yes') and talk_state == 11 then
		talk_state = 0
		if getPlayerItemCount(cid,5944) >= 1 then
			if doPlayerRemoveItem(cid,5944,1) == TRUE then
				doPlayerAddItem(cid,6529,10)
				selfSay(done, cid)
			end


		else
			selfSay(item, cid)
		end


	elseif msgcontains(msg, 'no') and talk_state >= 1 and talk_state <= 5 then
		selfSay('Well, then leave.')
		talk_state = 0
	end
	
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
you need say "exchange"
 
I fixed the problem with my own script, only wanted to exchange 5 items. Thank you for sharing :)
 
Last edited:
Back
Top