local config = {
storage = 89500,
seconds = 60,
maxlength = 100,
messagetype = MESSAGE_STATUS_WARNING
}
local talk = TalkAction("/guildbc", "!guildbc")
function talk.onSay(player, words, param)
if player:getStorageValue(config.storage) > os.time() then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can broadcast message only one time per " .. config.seconds .. " seconds.")
return false
end
if not player:getGuild() then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "Sorry, you\'re not in a guild.")
return false
end
if player:getGuildLevel() < 3 then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You have to be at least leader to guildcast!")
return false
end
if param == '' then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need to type a message to broadcast!")
return false
end
if param:len() > config.maxlength then
player:sendTextMessage(MESSAGE_STATUS_SMALL, "Your message max lenght " .. config.maxlength .. " characters")
return false
end
local members, message = 0,
"*Guild* " .. player:getName() .. " [" .. player:getLevel() .. "]:\n" .. param
for i, players in ipairs(Game.getPlayers()) do
if players:getGuild() and players:getGuild():getId() == player:getGuild():getId() then
players:sendTextMessage(config.messagetype, message)
members = members + 1
end
end
player:sendTextMessage(MESSAGE_STATUS_SMALL, "Message sent to your guild members. (Total: " .. members .. ")")
player:setStorageValue(config.storage, os.time() + config.seconds)
return false
end
talk:separator(" ")
talk:register()