• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Change Items NPC Help

mamon_2

Banned User
Joined
Jul 2, 2007
Messages
424
Reaction score
0
With the new NPC system of TFS Im not able to make a NPC that changes a certain amount of items for a new item:

Code:
        elseif msgcontains(msg, 'yes') and talk_state == 1 then
            if getPlayerItemCount(cid,2487) >= 1 then
                if doPlayerTakeItem(cid,2487,1) == 0 then
                    selfSay('Here you are.')
                    doPlayerAddItem(cid,5887,1)
                end
            else
                selfSay(hasNoMsg)
            end
            talk_state = 0[/php]

Someone could make one with the new system with this one:

[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

npcHandler:addModule(FocusModule:new())

Thanks :)
 
Last edited by a moderator:
try this

Code:
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

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return FALSE
	end
	
	
	
	if msgcontains(msg, 'SECRET KEYWORD!!! (what to write to execute it)') then
		npcHandler:say("Are you sure :o?", cid)
		talkState = 1
	elseif talkState == 1 then
		if doPlayerTakeItem(cid,2487,1) == 0 and msgcontains(msg, 'yes') then
            npcHandler:say('Here you are.', cid)
            doPlayerAddItem(cid,5887,1)
		else
			npcHandler:say('Come back with a bloody crown armor or I will kill you!', cid)
        end
		talkState = 0
	end
	
	return TRUE
end

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


Wrong place tho, next time in request and support!
 
Last edited by a moderator:
Here it goes:
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

	if(msgcontains(msg, 'royal steel')) then
		if(getPlayerItemCount(cid, 2487) >= 1) then
			selfSay('Do you want to trade a crown armor for a royal steel?', cid)
			talkState[talkUser] = 1
		else
			selfSay('I need a crown armor to trade with you for a royal steel.', cid)
		end
	elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
		if(getPlayerItemCount(cid, 2487) >= 1) then
			if(doPlayerTakeItem(cid, 2487, 1) == TRUE) then
				doPlayerGiveItem(cid, 5887, 1)
				selfSay('Here you are.', cid)
			end
		else
			selfSay('Sorry, you don\'t have requested item.', cid)
		end
		talkState[talkUser] = 0
	elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
		talkState[talkUser] = 0
		selfSay('Ok then.', cid)
	end

	return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Thanks man, the correct one and easyest is:

Code:
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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return FALSE
    end
    
    
    
    if msgcontains(msg, 'SECRET KEYWORD!!! (what to write to execute it)') then
        npcHandler:say("Are you sure :o?", cid)
        talkState = 1
    elseif talkState == 1 then
        if doPlayerTakeItem(cid,2487,1) == 0 and msgcontains(msg, 'yes') then
            npcHandler:say('Here you are.', cid)
            doPlayerAddItem(cid,5887,1)
        else
            npcHandler:say('Come back with a bloody crown armor or I will kill you!', cid)
        end
        talkState = 0
    end
    
    return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited by a moderator:
Thanks man, the correct one and easyest is:

Code:
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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return FALSE
    end
    
    
    
    if msgcontains(msg, 'SECRET KEYWORD!!! (what to write to execute it)') then
        npcHandler:say("Are you sure :o?", cid)
        talkState = 1
    elseif talkState == 1 then
        if doPlayerTakeItem(cid,2487,1) == 0 and msgcontains(msg, 'yes') then
            npcHandler:say('Here you are.', cid)
            doPlayerAddItem(cid,5887,1)
        else
            npcHandler:say('Come back with a bloody crown armor or I will kill you!', cid)
        end
        talkState = 0
    end
    
    return TRUE
end

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

This won't work with npc chat due to queue, talkState has to be a table.
 
Last edited by a moderator:
This should make it work try it out.

Code:
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

function creatureSayCallback(cid, type, msg)

    if(npcHandler.focus ~= cid) then
        return false
    end

local no_item = You dont have the correct items ----If player has wrong item
local giveid = 1890  ---id of the item that needs to be added
local item1 = 1890 -----id of the item that needs to get removed
local item2 = 1890 -----id of the item that needs to get removed local item3 = 1890 -----id of the item that needs to get removed
local item4 = 1890 -----id of the item that needs to get removed
local item5 = 1890 -----id of the item that needs to get removed if msgcontains(msg,'trade') then
selfSay('Would u like to trade items with me?')
if msgcontains(msg, 'yes') then	
         if doPlayerRemoveItem(cid,item1,1) and doPlayerRemoveItem(cid,item2,1) and doPlayerRemoveItem(cid,item3,1) and doPlayerRemoveItem(cid,item4,1) and doPlayerRemoveItem(cid,item5,1) == TRUE then
            doPlayerAddItem(cid,giveid,1)
                end
            else
                selfSay(no_item)
            end

        elseif msgcontains(msg, 'no') and (talk_state >= 1 then
            selfSay('Get out of mine sight!')
            talk_state = 0
            end
 
        return true
           end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


Please use code tages!!!!
//Mokerhamer
 
Last edited:
Back
Top