local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local messages = {}
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 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, 'o') or msgcontains(msg, 'a') or msgcontains(msg, 'i') or msgcontains(msg, 'e') and talkState[talkUser] == 0) then
selfSay("Do you want to broadcast '".. msg .."' for 100 gold?", cid)
messages[cid] = msg
talkState[talkUser] = 1
elseif (msg == "yes" and talkState[talkUser] == 1) then
if getPlayerMoney(cid) >= 100 then
doBroadcastMessage(getCreatureName(cid) ..": ".. messages[cid])
doPlayerRemoveMoney(cid, 100)
else
selfSay("You don't have enough money.", cid)
end
messages[cid] = nil
talkState[talkUser] = 0
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())