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
local talkState = {}
local greetCallbackk = ""
local cfg = {storageTile = 999999, itemId1 = 50016, iCount1 = 20, itemId2 = 50001, iCount2 = 50, ptName = "Big Daddy Tomb" } --7 do 8 proba
local str1 = "Hello adventuer! What can I do for You? Do you want to get access to {"..cfg.ptName.."}?"
local str2 = "Hello |PLAYERNAME|! Sorry but I'm bussy right now, we can talk later...?"
local itemName1 = getItemNameById(cfg.itemId1)
local itemName2 = getItemNameById(cfg.itemId2)
local msg = "Give me {"..cfg.iCount1.." "..itemName1.."s} and {"..cfg.iCount1.." "..cfg.itemName1.."s} then I give you a pass. Do you have it?"
local msgYes = "Let me have look..."
local msgNo = "Come back wehen you change your mind..."
local msgNe = "Hey, you dont have enough items! I need {"..cfg.iCount1.." "..cfg.itemName1.."s} and {"..cfg.iCount1.." "..cfg.itemName1.."s}. Come back when you get it."
local msgAg = "Thank You my friend, You can go now!"
local msgW = "Stop wasting my time!"
--
function greetCallback(cid)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if (getPlayerStorageValue(cid, cfg.storageTile) == -1) then
greetCallbackk = str1
talkState[talkUser] = 1
elseif (getPlayerStorageValue(cid, cfg.storageTile) > 0)then
greetCallbackk = str2
talkState[talkUser] = 0
end
npcHandler:setMessage(MESSAGE_GREET, greetCallbackk)
return true
end
function creatureSayCallback(cid, type, msg)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
if (talkState[talkUser] == 0) then
npcHandler:unGreet(cid) --reset/unfocus/bye
elseif (talkState[talkUser] == 1) then -- state 1
if (msgcontains(msg, cfg.ptName)) then
selfSay(msg, cid)
talkState[talkUser] = 2
end
elseif (talkState[talkUser] == 2) then -- state 2
if (msgcontains(msg, 'yes')) then
selfSay(msgYes, cid)
--items check
if getPlayerItemCount(cid, cfg.itemId1) >= cfg.iCount1 and getPlayerItemCount(cid, cfg.iCount2) >= cfg.iCount2 then --access granted
doPlayerRemoveItem(cid, cfg.itemId1, cfg.iCount1)
doPlayerRemoveItem(cid, cfg.itemId2, cfg.iCount2)
doPlayerSetStorageValue(cid, cfg.storageTile, 1)
selfSay(msgAg, cid)
else -- not enough items
selfSay(msgNe, cid)
end
elseif (msgcontains(msg, 'no')) then --dont want it?
selfSay(msgNo, cid)
else
selfSay(msgW, cid) --npc is bussy
end
npcHandler:unGreet(cid) --reset anyway
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setMessage(MESSAGE_GREET, greetCallbackk)
npcHandler:setMessage(MESSAGE_FAREWELL, 'See Ya!')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Hmpf...')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())