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
local function msgcontains(message, keyword)
local a, b = string.find(string.lower(message), string.lower(keyword))
if a == nil or b == nil then
return false
end
return true
end
function greetCallback(cid)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
talkState[talkUser] = 0
return true
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
-- Keyword responses [Start]
if msgcontains(msg, 'job') then
npcHandler:say("I am a ..", cid)
elseif msgcontains(msg, 'name')
npcHandler:say("My name is ..", cid)
elseif msgcontains(msg, 'help')
npcHandler:say("I can give you some basic tips.", cid)
-- Keyword responses [End]
elseif (msgcontains(msg, 'quest') or msgcontains(msg, 'mission')) and talkState[talkUser] == 0 then
if getPlayerStorageValue(cid, 19000) <= 0 then
npcHandler:say("Do you want to join the army?", cid)
talkState[talkUser] = 1
else
npcHandler:say("You have already joined the army!", cid)
talkState[talkUser] = 0
end
elseif msgcontains(msg, 'yes') and talkState[talkUser] == 1 then
npcHandler:say("Congratulations |PLAYERNAME|, you have just joined the army!", cid)
setPlayerStorageValue(cid, 19000, 1)
talkState[talkUser] = 0
elseif talkState[talkUser] == 1 then
npcHandler:say("Then not.", cid)
talkState[talkUser] = 0
end
return TRUE
end
npcHandler:setMessage(MESSAGE_GREET, 'Hello there, |PLAYERNAME|. If you\'re interested in joining the army, ask me about a quest.')
npcHandler:setMessage(MESSAGE_WALKAWAY, 'Gone...')
npcHandler:setMessage(MESSAGE_FAREWELL, 'LONG LIVE THE KING!')
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())