• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

NPC Broadcaster | For TFS.

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,839
Solutions
18
Reaction score
618
Location
Poland

* Informations:
This NPC is talking on red, player words.
You can buy Broadcast message by this NPC.

* Script:
Lua:
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())

* Credits:
Cykotitan for remake and make the script shorter.
 
Last edited:
The broadcast message is wrong, shud be:

Code:
doBroadcastMessage("[BroadCaster]: ".. getCreatureName(cid) .." : ".. messages[cid].."")
 
ooo nice job i dont remember seeing any broadcast NPC's for TFS yet. nice job
 
error.jpg
Anyone could solve this mystery? I'm useing TFS 0.2.7
 
Last edited:
@BUMP

ChangeLog:
* Added new advanced version for engine TFS 0.3.6pl1 - Tibia 8.54.
 
1281377467212.png
 
Lua:
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())
 
Then they won't be able to msg the player directly!
Lua:
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
			local v = getCreatureName(cid)
			for _, pid in ipairs(getPlayersOnline()) do
				doBroadcastMessage('[BroadCaster] ' .. v .. ': ' .. K[cid])

			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())
 
Back
Top