local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler
nCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler
nCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler
nCreatureSay(cid, type, msg) end
function onThink() npcHandler
nThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local key = doCreateItemEx(2088,1)
---------------------------------------------------------
if(msgcontains(msg, 'key') and getPlayerStorageValue(cid,45722) == -1) then
selfSay('Do you want buy this key for 1000 gold coins?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if(doPlayerRemoveMoney(cid, 1000) == TRUE) then
doPlayerAddItemEx(cid,key,1)
doItemSetAttribute(key,"aid",5555)
setPlayerStorageValue(cid, 45722,1)
selfSay('Here you are, this is your key.', cid)
else
selfSay('Sorry, you don/t have enough money!', cid)
end
else
selfSay('Sorry, you can buy this key only on times!', cid)
return TRUE
end
---------------------------------------------------------
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())