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:
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())