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

Selling NPC

Ward_214

Pro PvP
Joined
Dec 11, 2008
Messages
297
Reaction score
0
I have an NPC that I would like to sell items through words. (e.g. "Hi" "Hello player" "buy crusader armor" "would you like to buy crus. arm?" "yes" "Here you go!" (and you have the armor)).
The NPC will sell only one item though. I have 2 items to sell.
I say:
Hi
Buy Crusader Legs
Yes

The NPC gives me crusader armor instead of legs.
Here is script:

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
 
npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. I buy Kiwi tokens for donator items! I can sell you a {Crusader Armor}.") 
 
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, 'crusader armor') or msgcontains(msg, 'crus armor')) then
        selfSay('Do you want to buy a Crusader Armor for 2 Kiwi tokens?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if doPlayerRemoveItem(cid, 6527, 2) == true then
                doPlayerAddItem(cid, 2503, 1)
                selfSay('Here you are.', cid)
        else
            selfSay('Sorry, you don\'t have enough Kiwi Tokens.', cid)
        end
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser]) == TRUE) then
        talkState[talkUser] = 0
        selfSay('Ok then.', cid)
    end

    if(msgcontains(msg, 'crusader legs') or msgcontains(msg, 'crus legs')) then
        selfSay('Do you want to buy a Crusader Legs for 2 Kiwi tokens?', cid)
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        if doPlayerRemoveItem(cid, 6527, 2) == true then
                doPlayerAddItem(cid, 2504, 1)
                selfSay('Here you are.', cid)
        else
            selfSay('Sorry, you don\'t have enough Kiwi Tokens.', 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())
 
not tested check if works
Code:
llocal keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local Topic = {}

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:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. I buy Kiwi tokens for donator items! I can sell you a {Crusader Armor} and a {Crusader Legs}.") 

function creatureSayCallback(cid, type, msg)
	if(not npcHandler:isFocused(cid)) then
		return false
	elseif msgcontains(msg, "crusader armor") then
		npcHandler:say("Do you want to buy a Crusader Armor for 2 Kiwi tokens?", cid)
		Topic[cid] = 1
	elseif (msgcontains(msg, "crusader legs")  then
		npcHandler:say("Do you want to buy a Crusader Legs for 2 Kiwi tokens?", cid)
		Topic[cid] = 2

	elseif msgcontains(msg, "yes") and Topic[cid] == 1 then		
		if doPlayerRemoveItem(cid,6527,2) == TRUE then
			npcHandler:say("Here you are.", cid)
			doPlayerAddItem(cid,2503,1)
		else
			npcHandler:say("I only want Kiwi Tokens.", cid)
		end
		Topic[cid] = 0
	elseif msgcontains(msg, "yes") and Topic[cid] == 2 then
		if doPlayerRemoveItem(cid,6527,2) == TRUE then
			npcHandler:say("Here you are.", cid)
			doPlayerAddItem(cid,2504,1)
		else
			npcHandler:say("I only want Kiwi Tokens.", cid)
		end
		Topic[cid] = 0	
	elseif Topic[cid] > 0 then
		npcHandler:say("I'll be here when you're ready.", cid)
		Topic[cid] = 0
	end
	return TRUE
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
I fixed it about an hour after I posted this, then forgot to post to put solved on the thread.

The only thing I had to do was change the
Code:
talkState[talkUser] == 1
for each item

I'm sure your script would have worked. Thanks!
 
Back
Top