• 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!

Requesting !broadcast message for players tfs 1.2

Thorn

Spriting since 2013
Joined
Sep 24, 2012
Messages
2,203
Solutions
1
Reaction score
921
Location
Chile
Hello guys, im requesting a !broadcast message script wich takes some money out of the person, and has exhaustion so it cant be used very often, this for tfs 1.2
plzzzzz!
 
Solution
Hope this work for you:

Lua:
--Functions by Printer
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player.hasExhaustion(self, value)
    return self:getExhaustion(value) >= os.time() and true or false
end
-- / Functions by Printer

local CONFIG = {
    COST = 20000, -- On Gold
    TIME = 2, -- On minutes
    STORAGE = 2552
}

function onSay(player, words, param)
    local split = param:split(",")
    if split[1] == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR...
Hope this work for you:

Lua:
--Functions by Printer
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player.hasExhaustion(self, value)
    return self:getExhaustion(value) >= os.time() and true or false
end
-- / Functions by Printer

local CONFIG = {
    COST = 20000, -- On Gold
    TIME = 2, -- On minutes
    STORAGE = 2552
}

function onSay(player, words, param)
    local split = param:split(",")
    if split[1] == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Command param is required.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end 
    if player:removeMoney(CONFIG.COST) then
        if player:getExhaustion(CONFIG.STORAGE) <= 0 then
            print("> " .. player:getName() .. " broadcasted: \"" .. param .. "\".")
            local players = Game.getPlayers()
            for i = 1, #players do
                players[i]:sendPrivateMessage(player, param, TALKTYPE_BROADCAST)
            end
            player:setExhaustion(CONFIG.STORAGE, CONFIG.TIME * 60)
            return false
        else
            player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You can only send a message each : '.. CONFIG.TIME ..' minutes.')
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You need ' .. CONFIG.COST .. ' gold pieces to broadcast.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return false
end
 
Last edited:
Solution
Hope this work for you:

Lua:
--Functions by Printer
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player:hasExhaustion(value)
    return self:getExhaustion(value) >= os.time() and true or false
end
-- / Functions by Printer

local CONFIG = {
    COST = 20000, -- On Gold
    TIME = 2, -- On minutes
    STORAGE = 2552
}

function onSay(player, words, param)
    if player:removeMoney(CONFIG.COST) and not player:hasExhaustion(CONFIG.STORAGE) then
        print("> " .. player:getName() .. " broadcasted: \"" .. param .. "\".")
        local players = Game.getPlayers()
        for i = 1, #players do
            players[i]:sendPrivateMessage(player, param, TALKTYPE_BROADCAST)
        end
        player:setExhaustion(CONFIG.STORAGE, CONFIG.TIME * 60 * 1000)
        return true
    end
    return false
end
thank you the message is send! but the exhaustion isnt working :(
 
Works super, yet, for me it keeps taking my money after using it in ej:
I use it, and if i dont have the money puff and doesnt take my money(its ok)
If I have the money and use it , it broadcast a massage and it takes money (its ok)
But if I use the command once again it goes puff (its ok) but keeps taking the players money(which is NOT ok)
Any idea on what could be causing that?
Thanks in advance guys :)!
(edited this reply cuz of minor misspellings)
 
Last edited:
You have to replace "ifs".

That "if " with money put under the " if "with getexhaustion .

Dont forget replace "elses" too otherwise it will be sending wrong informations.
 
You have to replace "ifs".

That "if " with money put under the " if "with getexhaustion .

Dont forget replace "elses" too otherwise it will be sending wrong informations.
Thanks! could you do further helping(i dont know which one should i remove and modify), just in case somebody else has the same problem in this thread?
:)
 
Thanks! could you do further helping(i dont know which one should i remove and modify), just in case somebody else has the same problem in this thread?
:)
Lua:
--Functions by Printer
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player.hasExhaustion(self, value)
    return self:getExhaustion(value) >= os.time() and true or false
end
-- / Functions by Printer

local CONFIG = {
    COST = 20000, -- On Gold
    TIME = 2, -- On minutes
    STORAGE = 2552
}

function onSay(player, words, param)
    local split = param:split(",")
    if split[1] == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Command param is required.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    if player:getExhaustion(CONFIG.STORAGE) <= 0 then
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You can only send a message each : '.. CONFIG.TIME ..' minutes.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    if player:removeMoney(CONFIG.COST) then
        print("> " .. player:getName() .. " broadcasted: \"" .. param .. "\".")
        local players = Game.getPlayers()
        for i = 1, #players do
            players[i]:sendPrivateMessage(player, param, TALKTYPE_BROADCAST)
        end
        player:setExhaustion(CONFIG.STORAGE, CONFIG.TIME * 60)
        return false
    else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You need ' .. CONFIG.COST .. ' gold pieces to broadcast.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return false
end
 
Thanks flaviiojr :D!
unluckly :( it doesnt work, but right now im not able to open console, ill report back trying to figure out how can i make it work.
thank u guys , with both of you have giving me ideas on what could the problem be.

ill report back later :D!
thanks in advance

Edit: i think i got some on my own but was mistake. sorry
 
Last edited:
Is it possible to block the messages that are sent from a command? That is, if a player does not want to see the messages.
Post automatically merged:

If you want the players to decide if they want to receive the message or not. Use this code. Thanks to @Ricarpe

Lua:
--Functions by Printer
function Player.setExhaustion(self, value, time)
    self:setStorageValue(value, time + os.time())
end

function Player.getExhaustion(self, value)
    local storage = self:getStorageValue(value)
    if not storage or storage <= os.time() then
        return 0
    end

    return storage - os.time()
end

function Player.hasExhaustion(self, value)
    return self:getExhaustion(value) >= os.time() and true or false
end
-- / Functions by Printer

local CONFIG = {
    COST = 20000, -- On Gold
    TIME = 2, -- On minutes
    STORAGE = 2552,
    IGNORE_STORAGE = 2553
}

function onSay(player, words, param)
    local split = param:split(",")
    if split[1] == nil then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "Command param is required.")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
    if player:removeMoney(CONFIG.COST) then
        if player:getExhaustion(CONFIG.STORAGE) <= 0 then
            print("> " .. player:getName() .. " broadcasted: \"" .. param .. "\".")
            local players = Game.getPlayers()
            for i = 1, #players do
                if (players[i]:getStorageValue(CONFIG.IGNORE_STORAGE) ~= 1) then
                    players[i]:sendPrivateMessage(player, param, TALKTYPE_BROADCAST)
                end
            end
            player:setExhaustion(CONFIG.STORAGE, CONFIG.TIME * 60)
            return false
        else
            player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You can only send a message each : '.. CONFIG.TIME ..' minutes.')
            player:getPosition():sendMagicEffect(CONST_ME_POFF)
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You need ' .. CONFIG.COST .. ' gold pieces to broadcast.')
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return false
end
 
Last edited:
Back
Top