• 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.X+ Boardcast

ImaG

Active Member
Joined
Aug 16, 2017
Messages
75
Solutions
1
Reaction score
36
Location
Poland
GitHub
ImaGus01v
Lua:
local function broadcastEventMessage()
  for _, player in ipairs(Game.getPlayers()) do
    Game.broadcastMessage("Wydarzenie rozpocznie się za 5 minut!", MESSAGE_STATUS_WARNING)
  end
end


This is my part of the code responsible for notifying players about the event. But it doesn't work what could be the reason?
otsevrbr 10.98
if it is well written, there are no errors
 
Lua:
local function broadcastEventMessage()
  for _, player in ipairs(Game.getPlayers()) do
    Game.broadcastMessage("Wydarzenie rozpocznie się za 5 minut!", MESSAGE_STATUS_WARNING)
  end
end


This is my part of the code responsible for notifying players about the event. But it doesn't work what could be the reason?
otsevrbr 10.98
if it is well written, there are no errors
Lua:
local function broadcastEventMessage()
    for _, player in ipairs(Game.getPlayers()) do
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "Wydarzenie rozpocznie się za 5 minut!")
    end
end
 
Thank you for your answer, but the script still doesn't work.
I think something is still wrong with the ontime function, I'll leave it here
I also looked into the zombiemod script, there is a redirect to the lib folder, maybe that's the problem?

Lua:
local EVENT_HOUR = 10
local EVENT_MINUTE = 25
local MINUTES_BEFORE_EVENT = 1

local function startEventForPlayer(player)
  local minX = 1160
  local minY = 1320
  local maxX = 1180
  local maxY = 1340
  local floor = 7
 
  for i = 1, 5 do
    local position = Position(math.random(minX, maxX), math.random(minY, maxY), floor)
    local tile = Tile(position)
   
    if tile and tile:getItemCount() == 0 and tile:getTopCreature() == nil and tile:getTopDownItem() == nil then
      Game.createItem(16102, 1, position)
    end
  end
 
  local monsterPosition = Position(1167, 1327, 7)
  local monster = Game.createMonster("chicken", monsterPosition)
end

local function broadcastEventMessage
    for _, player in ipairs(Game.getPlayers()) do
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "Wydarzenie rozpocznie się za 1 minute!")
    end
end

function onTime(interval)
  local currentTime = os.date("*t")
 
  if currentTime.hour == EVENT_HOUR and currentTime.min == (EVENT_MINUTE - MINUTES_BEFORE_EVENT) then
    broadcastEventMessage()
  elseif currentTime.hour == EVENT_HOUR and currentTime.min == EVENT_MINUTE then
    local players = Game.getPlayers()
    for _, player in ipairs(players) do
      startEventForPlayer(player)
    end
  end
 
  return true
end
Code:
 
Last edited:
Lua:
local EVENT_HOUR = 10
local EVENT_MINUTE = 25
local MINUTES_BEFORE_EVENT = 1

local function startEventForPlayer(player)
  local minX = 1160
  local minY = 1320
  local maxX = 1180
  local maxY = 1340
  local floor = 7
 
  for i = 1, 5 do
    local position = Position(math.random(minX, maxX), math.random(minY, maxY), floor)
    local tile = Tile(position)
 
    if tile and tile:getItemCount() == 0 and tile:getTopCreature() == nil and tile:getTopDownItem() == nil then
      Game.createItem(16102, 1, position)
    end
  end
 
  local monsterPosition = Position(1167, 1327, 7)
  local monster = Game.createMonster("chicken", monsterPosition)
end

local function broadcastEventMessage()
  for _, player in ipairs(Game.getPlayers()) do
    player:sendTextMessage(MESSAGE_STATUS_WARNING, "Wydarzenie rozpocznie się za 1 minutę!")
  end
end

function onTime(interval)
  local currentTime = os.date("*t")
 
  if currentTime.hour == EVENT_HOUR and currentTime.min == (EVENT_MINUTE - MINUTES_BEFORE_EVENT) then
    broadcastEventMessage()
  elseif currentTime.hour == EVENT_HOUR and currentTime.min == EVENT_MINUTE then
    local players = Game.getPlayers()
    for _, player in ipairs(players) do
      startEventForPlayer(player)
    end
  end
 
  return true
end

or

Code:
 local EVENT_HOUR = 10
local EVENT_MINUTE = 25
local MINUTES_BEFORE_EVENT = 1

local function startEventForPlayer(player)
  local minX = 1160
  local minY = 1320
  local maxX = 1180
  local maxY = 1340
  local floor = 7
 
  for i = 1, 5 do
    local position = Position(math.random(minX, maxX), math.random(minY, maxY), floor)
    local tile = Tile(position)
 
    if tile and tile:getItemCount() == 0 and tile:getTopCreature() == nil and tile:getTopDownItem() == nil then
      Game.createItem(16102, 1, position)
    end
  end
 
  local monsterPosition = Position(1167, 1327, 7)
  local monster = Game.createMonster("chicken", monsterPosition)
end

local function broadcastEventMessage()
  Game.broadcastMessage("Wydarzenie rozpocznie się za 1 minutę!", MESSAGE_STATUS_WARNING)
end

function onTime(interval)
  local currentTime = os.date("*t")
 
  if currentTime.hour == EVENT_HOUR and currentTime.min == (EVENT_MINUTE - MINUTES_BEFORE_EVENT) then
    broadcastEventMessage()
  elseif currentTime.hour == EVENT_HOUR and currentTime.min == EVENT_MINUTE then
    local players = Game.getPlayers()
    for _, player in ipairs(players) do
      startEventForPlayer(player)
    end
  end
 
  return true
end
 
I thought I'd make an event in the "now" time.
And add lanes :
Code:
  if currentTime.hour == EVENT_HOUR and currentTime.min == (EVENT_MINUTE - MINUTES_BEFORE_EVENT) then
    broadcastEventMessage()
  elseif currentTime.hour == EVENT_HOUR and currentTime.min == EVENT_MINUTE then
    local players = Game.getPlayers()
    for _, player in ipairs(players) do
      Game.broadcastMessage('Chicken Colour Event START in Vvs City Gate!', MESSAGE_STATUS_WARNING)
      player:sendTextMessage(MESSAGE_INFO_DESCR, "Chicken Colour Event START in Vvs City Gate!")
      startEventForPlayer(player)
    end
  end

It works but in real time it doesn't announce it beforehand.
Thanks for your help, this thread can be closed or given ideas to others.
 
Back
Top