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 onCreatureSay(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if getPlayerStorageValue(cid, 3331) ~= 1 and getPlayerStorageValue(cid, 3332) ~= 1 and getPlayerStorageValue(cid, 3333) ~= 1 then
npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. I've heard so much about you. I was told you would need a weapon to defend yourself. I have {sword}, {axe}, and {club} weapon types. Which do you want?")
else
npcHandler:setMessage(MESSAGE_GREET, "Hello |PLAYERNAME|. You can buy a new weapon from me if you lost yours. Want to {trade}?")
end
npcHandler:onCreatureSay(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
---------------- config msg ------------------
local intro1 = 'I can offer you a {sword}, {axe}, or {club} type weapon. Which do you want?' -- (npc) response to weapon types --
local intro2 = 'weapon' -- (player) weapon type --
local intro3 = 'type' -- (player) weapon type --
local intro4 = 'weapons' -- (player) weapon type --
local intro5 = 'types' -- (player) weapon type --
local frase1 = 'sword' -- (player) Player wants sword --
local frase2 = 'axe' -- (player) Player wants axe --
local frase3 = 'club' -- (player) Player wants club --
local answer1 = 'I can give you a carlin sword. Is that what you want?' -- (npc) Are you sure (sword) --
local answer2 = 'I can give you a hatchet. Is that what you want?' -- (npc) Are you sure? (axe) --
local answer3 = 'I can give you a mace. Is that what you want?' -- (npc) Are you sure? (club) --
local final1 = 'yes' -- (player) yes --
local final2 = 'no' -- (player) no --
local final3 = 'Here is your weapon, free of charge. Have a nice day.' -- (npc) Response to yes --
local final4 = 'No? My offer is a weapon free of charge. Just let me know what {weapon type} you want.' -- (npc) Response to no --
local storage1 = 3331 -- Storage value for sword --
local storage2 = 3332 -- Storage value for axe --
local storage3 = 3333 -- Storage value for club --
local itemid1 = 2395 -- Sword ID --
local itemid2 = 2388 -- Axe ID --
local itemid3 = 2398 -- Club ID --
----------------------------------------------
if (msgcontains(msg, intro2) or msgcontains(msg, intro3) or msgcontains(msg, intro4) or msgcontains(msg, intro5)) then
selfSay(intro1, cid)
elseif(msgcontains(msg, frase1)) and getPlayerStorageValue(cid, storage1) ~= 1 and getPlayerStorageValue(cid, storage2) ~= 1 and getPlayerStorageValue(cid, storage3) ~= 1 then
selfSay(answer1, cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, frase2)) and getPlayerStorageValue(cid, storage1) ~= 1 and getPlayerStorageValue(cid, storage2) ~= 1 and getPlayerStorageValue(cid, storage3) ~= 1 then
selfSay(answer2, cid)
talkState[talkUser] = 2
elseif(msgcontains(msg, frase3)) and getPlayerStorageValue(cid, storage1) ~= 1 and getPlayerStorageValue(cid, storage2) ~= 1 and getPlayerStorageValue(cid, storage3) ~= 1 then
selfSay(answer3, cid)
talkState[talkUser] = 3
elseif(msgcontains(msg, final1) and talkState[talkUser] == 1) then
setPlayerStorageValue(cid, storage1, 1)
doPlayerAddItem(cid, itemid1)
selfSay(final3, cid)
talkState[talkUser] = 0
elseif(msgcontains(msg, final1) and talkState[talkUser] == 2) then
setPlayerStorageValue(cid, storage2, 1)
doPlayerAddItem(cid, itemid2)
selfSay(final3, cid)
talkState[talkUser] = 0
elseif(msgcontains(msg, final1) and talkState[talkUser] == 3) then
setPlayerStorageValue(cid, storage3, 1)
doPlayerAddItem(cid, itemid3)
selfSay(final3, cid)
talkState[talkUser] = 0
elseif(msgcontains(msg, final2) and talkState[talkUser] == 1) then
selfSay(final4, cid)
talkState[talkUser] = 0
elseif(msgcontains(msg, final2) and talkState[talkUser] == 2) then
selfSay(final4, cid)
talkState[talkUser] = 0
elseif(msgcontains(msg, final2) and talkState[talkUser] == 3) then
selfSay(final4, cid)
talkState[talkUser] = 0
end
return TRUE
end
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
npcHandler:addModule(FocusModule:new())