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

Custom Npc

Robbiet6

New Member
Joined
Feb 22, 2009
Messages
83
Reaction score
1
Does anybody have, or can make me a script for an npc that will do the following.
If you have 100 x 5953 (item id)
He will give you 30 x 6541 (item id)

Would really appreciate it if you can help me out
I understand their are scripts that can be edited to do this but im just looking for a simple script for this 1 on 1 trade and all the ones i have found so far seem more complicated than 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

item = 'You do not have the required items.'
done = 'Here you are.'

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	end
	
		if msgcontains(msg, 'offer') then
		selfSay('You can here change some items for {item}.', cid)

			elseif msgcontains(msg, 'item') then
			if getPlayerItemCount(cid,5953) >= 100 then
				selfSay('Did you bring me the 100 item ?', cid)
				talk_state = 1
			else
				selfSay('I need 100 item, to give you the item. 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,5953) >= 100 then
			if doPlayerRemoveItem(cid,5953, 100) == TRUE then
							selfSay(done, cid)
			doPlayerAddItem(cid, 6541, 30)
			end
			else
				selfSay(item, cid)
			end

        elseif msgcontains(msg, 'no') and (talk_state >= 1 and talk_state <= 5) then
            selfSay('Ok than.')
            talk_state = 0
        end
    -- Place all your code in here. Remember that hi, bye and all that stuff is already handled by the npcsystem, so you do not have to take care of that yourself.
    return true
end

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


Try that one!
 
Last edited:
Hey ty for this but i seem to get this error...
Attempt to index global 'KeywordHandler' <a nil value>
I also get this exact problem on some of my other npcs so im thinking maybe its a problem ive got with my ot
Do you know how i can fix this problem?
 
Hey ty for this but i seem to get this error...
Attempt to index global 'KeywordHandler' <a nil value>
I also get this exact problem on some of my other npcs so im thinking maybe its a problem ive got with my ot
Do you know how i can fix this problem?

How did you fix it? Im having the smae problem with ALL my npcs
 
Back
Top