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

Npc exchange items

kamilcioo

Veteran OT User
Joined
Jul 25, 2008
Messages
979
Solutions
1
Reaction score
291
I got script for exchange 3 items for 1 item and when i got this items isnt work. Npc says to me You dont have items.

Here my script. Please help me.
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 tokenid = 2160
        local storage = 7000
        local getstorage = getPlayerStorageValue(cid, storage)
        local sorrymessage = "Sorry, are you sure you got all items??."
        local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
        if msgcontains(msg, 'quest') then
                if getstorage == 1 then
                        npcHandler:say("You are now finished.", cid)
                elseif getstorage < 1 then
                        npcHandler:say("If you got this three items say {key}", cid)
                        talkState[talkUser] = 1
                end
        elseif msgcontains(msg, 'key') then
                if getstorage < 1 then
                        npcHandler:say("You dont have items.", cid)
                elseif getstorage == 1 then
                        npcHandler:say("I have aledry give you this key !!.", cid)
                end
        elseif msgcontains(msg, 'yes') then
                if talkState[talkUser] == 1 then
                        if getstorage < 0 then
                                if doPlayerRemoveItem(cid, tokenid, 1) == TRUE then
                                        npcHandler:say("Ye' brought the key, needed to complete the quest'.", cid)
                                        setPlayerStorageValue(cid, storage, 1)
                                                                                doPlayerAddItem(cid, 2091, 1)
                                                                                doPlayerRemoveItem(cid, 10309, 1)
                                                                                doPlayerRemoveItem(cid, 8266, 1)
                                                                                doPlayerRemoveItem(cid, 6534, 1)
                                        talkState[talkUser] = 0
                                elseif doPlayerRemoveItem(cid, tokenid, 1) == FALSE then
                                        npcHandler:say(sorrymessage, cid)
                                        talkState[talkUser] = 0
                                end
                        end
                end
        elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
                npcHandler:say("Sure, come back later!", cid)
                talkState[talkUser] = 0
        end
return TRUE
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
LUA:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}

local storage = 7000
local items = {10309, 8266, 6534}
local reward = 2091
local sorrymessage = 'Sorry, are you sure you got all items?'

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 greetCallback(cid)
	Topic[cid] = 0
	return true
end

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	elseif msgcontains(msg, 'quest') or msgcontains(msg, 'mission') then
		if getPlayerStorageValue(cid, storage) == 1 then
			npcHandler:say('You are now finished.', cid)
			Topic[cid] = 0
		else
			npcHandler:say('Do you have the three items?', cid)
			Topic[cid] = 1
		end
	elseif msgcontains(msg, 'yes') and Topic[cid] == 1 then
		for i = 1, #items do
			if getPlayerItemCount(cid, items[i]) < 1 then
				Topic[cid] = 0
				return npcHandler:say(sorrymessage, cid)
			end
		end
		for i = 1, #items do
			doPlayerRemoveItem(cid, i, 1)
		end
		npcHandler:say('Ye\' brought the key, needed to complete the quest.', cid)
		setPlayerStorageValue(cid, storage, 1)
		doPlayerAddItem(cid, reward, 1)
		Topic[cid] = 0
	elseif msgcontains(msg, 'no') and Topic[cid] == 1 then
		npcHandler:say('Sure, come back later!', cid)
		Topic[cid] = 0
	end
	return true
end

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