Aurolio
New Member
- Joined
- Aug 26, 2018
- Messages
- 45
- Reaction score
- 3
Hi all, I am trying to implement broadcast message system on my OT, but I don't know how to put an exhaust on it. So what I mean by that is:
1. Player sends a message and NPC gets exhausted.
2. After sending a message, nobody can send a message for X time.
3. After the time has passed, you can send message again.
I am not talking about exhausting the player, but exhausting the npc so that it will allow to send a message every x time.
Here is the script I am using:
Credit for the script goes to: Cykotitan.
Thanks and I am looking forward to your help.
1. Player sends a message and NPC gets exhausted.
2. After sending a message, nobody can send a message for X time.
3. After the time has passed, you can send message again.
I am not talking about exhausting the player, but exhausting the npc so that it will allow to send a message every x time.
Here is the script I am using:
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local t, K = {
level = 75,
minl = 10,
maxl = 150,
base = 25000,
char = 1000
}, {}
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 greetCallback(cid)
K[cid] = nil
return true
end
function creatureSayCallback(cid, type, msg)
if not npcHandler:isFocused(cid) then
return false
elseif not K[cid] then
if t.level and getPlayerLevel(cid) < t.level then
selfSay('You need to be level ' .. t.level .. ' or higher to broadcast.', cid)
elseif t.minl and msg:len() < t.minl then
selfSay('Your message must contain at least ' .. t.minl .. ' characters.', cid)
elseif t.maxl and msg:len() >= t.maxl then
selfSay('Your message may contain no more than ' .. t.maxl .. ' characters.', cid)
else
selfSay('Do you want to broadcast this message for ' .. (t.base or 0) + (t.char or 0) * msg:len() .. ' gold?', cid)
K[cid] = msg
end
elseif K[cid] and msgcontains(msg, 'yes') then
if doPlayerRemoveMoney(cid, (t.base or 0) + (t.char or 0) * K[cid]:len()) then
for _, pid in ipairs(getPlayersOnline()) do
doCreatureSay(cid, K[cid], TALKTYPE_BROADCAST, false, pid)
end
selfSay('Your message has been broadcasted.', cid)
else
selfSay('Come back when you\'ve got enough money!', cid)
end
K[cid] = nil
end
return true
end
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Credit for the script goes to: Cykotitan.
Thanks and I am looking forward to your help.