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

[TFS 1.3] Game.Broadcast() not showing in game window

strutZ

Australian OT Member {AKA Beastn}
Joined
Nov 16, 2014
Messages
1,391
Solutions
7
Reaction score
550
During my server save on my server it does not broadcast properly. The boradcast only shows in the server log and not in the game window.. Can anyone shed some light on this?

game.lua
Lua:
function Game.broadcastMessage(message, messageType)
    if messageType == nil then
        messageType = MESSAGE_STATUS_WARNING
    end

    for _, player in ipairs(Game.getPlayers()) do
        player:sendTextMessage(messageType, message)
    end
end

ANd here is the server save script i am using
Lua:
local shutdownAtServerSave = true
local cleanMapAtServerSave = true

local function serverSave()
   if shutdownAtServerSave then
       Game.setGameState(GAME_STATE_SHUTDOWN)
   else
       Game.setGameState(GAME_STATE_CLOSED)

       if cleanMapAtServerSave then
           cleanMap()
       end

       Game.setGameState(GAME_STATE_NORMAL)
   end
end

local function secondServerSaveWarning()
   for _, targetPlayer in ipairs(Game.getPlayers()) do
       targetPlayer:sendPrivateMessage("Server is saving game in one minute. Please logout.", TALKTYPE_BROADCAST)
   end
   broadcastMessage("Server is saving game in one minute. Please logout.", MESSAGE_STATUS_WARNING)
   --addEvent(serverSave, 60000)
end

local function firstServerSaveWarning()
   broadcastMessage("Server is saving game in 3 minutes. Please logout.", TALKTYPE_BROADCAST)
   addEvent(secondServerSaveWarning, 120000)
end

function onTime(interval)
   broadcastMessage("Server is saving game in 5 minutes. Please logout.", MESSAGE_STATUS_WARNING)
   Game.setGameState(GAME_STATE_STARTUP)
   addEvent(firstServerSaveWarning, 120000)
   return not shutdownAtServerSave
end

Its just the default server save tfs came with so wondering if this is maybe a change made on purpose?
 
Anonymous broadcasts will only be shown in server log. If you want your broadcast to show in game window you must use Player:say, which requires a player as you can see. If you do not want a player name you can use this little "hack" version I created (which means it could've been made properly and I'm not sure if it would work perfectly in e.g. Flash client, has worked fine on 10.98 regular client at least):

Lua:
function Game.broadcast(message, sender)
    local players = Game.getPlayers()
   for _, cid in ipairs(players) do
      local msg = NetworkMessage()
      msg:addByte(0xAA)
      msg:addU32(1) -- ???????
      msg:addString(sender)
      msg:addU16(0x00)
      msg:addByte(TALKTYPE_BROADCAST)
      msg:addString(message)
      msg:sendToPlayer(Player(cid))
   end
end
"sender" is a string. You can use the code as follows:
Lua:
Game.broadcast("Server will restart in 2 minutes.", "Announcement")
 
Anonymous broadcasts will only be shown in server log. If you want your broadcast to show in game window you must use Player:say, which requires a player as you can see. If you do not want a player name you can use this little "hack" version I created (which means it could've been made properly and I'm not sure if it would work perfectly in e.g. Flash client, has worked fine on 10.98 regular client at least):

Lua:
function Game.broadcast(message, sender)
    local players = Game.getPlayers()
   for _, cid in ipairs(players) do
      local msg = NetworkMessage()
      msg:addByte(0xAA)
      msg:addU32(1) -- ???????
      msg:addString(sender)
      msg:addU16(0x00)
      msg:addByte(TALKTYPE_BROADCAST)
      msg:addString(message)
      msg:sendToPlayer(Player(cid))
   end
end
"sender" is a string. You can use the code as follows:
Lua:
Game.broadcast("Server will restart in 2 minutes.", "Announcement")
Thanks for that, Yeah I did something similar to what you did. I guess it was more of a was this intentional?
 
ummmm the thread isn't solved? Maybe you should read the thread again.

Am I missing something? You asked how to send it as someone broadcasted it, Colandus gave you a code and you said you did something similar (that worked?)
If you got more problems please tell what.
 
Am I missing something? You asked how to send it as someone broadcasted it, Colandus gave you a code and you said you did something similar (that worked?)
If you got more problems please tell what.
"Its just the default server save tfs came with so wondering if this is maybe a change made on purpose?"

"Thanks for that, Yeah I did something similar to what you did. I guess it was more of a was this intentional?"
 
"Its just the default server save tfs came with so wondering if this is maybe a change made on purpose?"

"Thanks for that, Yeah I did something similar to what you did. I guess it was more of a was this intentional?"
I guess it was more of a was this intentional?
Wut?

Intentional sure, why send out a character name when it's the server doing something?
Im really lost here haha, is the script working or was it a question of why it was written like that?

Otherwise please write that question again, beacuse you are asking if it was more of a ... ? and if it was intentional.
 
The question is why does the broadcast() command no longer display in the players game window. Is this an intentional change made by Mark?
 
The question is why does the broadcast() command no longer display in the players game window. Is this an intentional change made by Mark?

Oh okay now I get it, well as you can see here: forgottenserver/game.lua at master · otland/forgottenserver · GitHub
This is the new broadcast function, it was most likely removed to have less functions and less overhead with C++.
But as Colandus wrote you can still send it as a player or even just write the player name (as most do right now) in the message, the time will always be sent in the message so send;
Lua:
player:getName .. "x"

insted of
Lua:
"x"
 
Back
Top