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

Need help trying to delay a Broadcast

PB3LL

Member
Joined
Oct 30, 2015
Messages
60
Reaction score
9
I am finding myself editing a script that already has an interval of 1

Code:
    <globalevent name="waitingroomcheck" interval="1" event="script" value="eventsystem/waitingroomcheck.lua"/>


If I needed to add a interval for the broadcast, is there a way of doing this using 0.3.6?

I tried, with no luck using this:

Code:
doBroadcastMessage("The event needs 5 more players",interval=600)

I need to make the Broadcast happen every 10 seconds or so. Instead of 1. But need the script to keep an interval of 1.

Hallppppppp
 
Code:
function broadcast(interval, message)
    doBroadcastMessage(message)
    addEvent(broadcast, interval, message)
end

broadcast(10000, 'The event needs 5 more players')
 
you didn't specify sources, so the args in this function might not be correct. I'm just assuming you're using 0.x

Code:
local text = 'The event needs 5 more players'

function onThink(interval, lastExecution, thinkInterval)
    doBroadcastMessage(text)
    return true
end
<globalevent name="broadcastmsg" interval ="10000" event="script" value="SCRIPTNAMEHERE.lua"/>

put the line above in globalevents.xml
 
thanks for the response @tokenzz i see now that i wasn't very clear in my initial post. I also see what you mean as well.

I was looking for something to add to the line of code 'doBroadcastMessage...' that would delay the broadcast for a determined amount of seconds while ignoring the interval set in globalevents.xml

what I need is just something that will count the amount of players needed and subtract the amount of players in the waiting room. Then broadcast that as a message once there is a certain amount of players. This message plays every 60 seconds and then stops when the amount of players needed is equal to amount of players in the waiting room.

any help is greatly appreciated.
 
Assuming interval of 1 is one minute.
If incorrect, change to whatever is classified as 1 minute for your distribution.

The way I have the code set-up it will check the room every 10 seconds, and broadcast an update each time.
Code:
<globalevent name="waitingroomcheck" interval="1" event="script" value="eventsystem/waitingroomcheck.lua"/>
Code:
local config = {
    top_left_corner  = {x = 1000, y = 1000, z = 7},
    bot_right_corner = {x = 1010, y = 1010, z = 7},
    players_required = 10
}

local loop_1_delay = 10000 -- don't change if you don't understand
local loop_1_loop_amount = 6 -- set-up to broadcast 6 times over 60 seconds

local function loop_1(n)
    local player_count = 0
    for t = config.top_left_corner.x, config.bot_right_corner.x do
        for f = config.top_left_corner.y, config.bot_right_corner.y do
            for m = config.top_left_corner.z, config.bot_right_corner.z do
                pos = {x = t, y = f, z = m}
                pid = getTopCreature(pos).uid
                if isPlayer(pid) then
                    player_count = player_count + 1
                end
            end
        end
    end
    if player_count >= config.players_required then
        doBroadcastMessage("Enough players are present for the event.")
    else
        local count = config.players_required - player_count
        doBroadcastMessage("" .. count .. " more " .. (count == 1 and "player" or "players") .. " required for the event.")
    end
    if n > 0 then
        addEvent(loop_1, loop_1_delay, n - 1)
    end
end

function onThink(interval, lastExecution, thinkInterval)
    addEvent(loop_1, loop_1_delay, loop_1_loop_amount)
    return true
end
 
Assuming interval of 1 is one minute.
If incorrect, change to whatever is classified as 1 minute for your distribution.

The way I have the code set-up it will check the room every 10 seconds, and broadcast an update each time.
Code:
<globalevent name="waitingroomcheck" interval="1" event="script" value="eventsystem/waitingroomcheck.lua"/>
Code:
local config = {
    top_left_corner  = {x = 1000, y = 1000, z = 7},
    bot_right_corner = {x = 1010, y = 1010, z = 7},
    players_required = 10
}

local loop_1_delay = 10000 -- don't change if you don't understand
local loop_1_loop_amount = 6 -- set-up to broadcast 6 times over 60 seconds

local function loop_1(n)
    local player_count = 0
    for t = config.top_left_corner.x, config.bot_right_corner.x do
        for f = config.top_left_corner.y, config.bot_right_corner.y do
            for m = config.top_left_corner.z, config.bot_right_corner.z do
                pos = {x = t, y = f, z = m}
                pid = getTopCreature(pos).uid
                if isPlayer(pid) then
                    player_count = player_count + 1
                end
            end
        end
    end
    if player_count >= config.players_required then
        doBroadcastMessage("Enough players are present for the event.")
    else
        local count = config.players_required - player_count
        doBroadcastMessage("" .. count .. " more " .. (count == 1 and "player" or "players") .. " required for the event.")
    end
    if n > 0 then
        addEvent(loop_1, loop_1_delay, n - 1)
    end
end

function onThink(interval, lastExecution, thinkInterval)
    addEvent(loop_1, loop_1_delay, loop_1_loop_amount)
    return true
end
You don't need to use 3 loops for top-left and bottom-right positions since you can just use getSpectators, plus if you still use that your script will only return the topmost creature

Code:
local centerpos = {x = 1000, y = 1000, z = 7}
local spec = getSpectators(centerpos, 25, 25)
local count = 0
    if spec then
        for i = 1, #spec do
            if isPlayer(spec[i]) then
                count = count + 1
            end
        end
    end
 
You don't need to use 3 loops for top-left and bottom-right positions since you can just use getSpectators, plus if you still use that your script will only return the topmost creature

Code:
local centerpos = {x = 1000, y = 1000, z = 7}
local spec = getSpectators(centerpos, 25, 25)
local count = 0
    if spec then
        for i = 1, #spec do
            if isPlayer(spec[i]) then
                count = count + 1
            end
        end
    end
it's not an efficient function, hence the use of looping through the area.
 
@Xikini
thanks it worked as explained however;
once players have been teleported out of the waiting room, it keeps sending an update: 06:32 10 more players required for the event.

How do you stop it from broadcasting once the players have been teleported? It seems to be stuck in the loop thats telling us how many players in waiting room
 
Use a globalstorage check.
When event starts set global storage to 1, when players have been teleported use 2, when event finished set back to 0.

Make the script check for players when the globalstorage is equal to 1.
 
Problem has been solved. Thank you to everyone that helped. Here is a solution:

Code:
<globalevent name="waitingroomcheck" interval="60" event="script" value="eventsystem/waitingroomcheck.lua"/>

Code:
local config = {
top_left_corner = {x = 1096, y = 937, z = 7},
bot_right_corner = {x = 1112, y = 945, z = 7},
players_required = 8, --the amount of players required to get the broadcast/notification
players_needed = 10, --the actual amount of players needed to get teleported
room_name = "Rush Event"
}

local loop_1_delay = 10000 -- don't change if you don't understand
local loop_1_loop_amount = 6 -- set-up to broadcast 6 times over 60 seconds

local function loop_1(n)
local player_count = 0
for t = config.top_left_corner.x, config.bot_right_corner.x do
for f = config.top_left_corner.y, config.bot_right_corner.y do
for m = config.top_left_corner.z, config.bot_right_corner.z do
pos = {x = t, y = f, z = m}
pid = getTopCreature(pos).uid
if isPlayer(pid) then
player_count = player_count + 1
end
end
end
end
if player_count >= config.players_required then
local count = config.players_needed - player_count
doBroadcastMessage("Only " .. count .. " more " .. (count == 1 and "player" or "players") .. " required for the " ..config.room_name.. ".")
end
if n > 0 then
addEvent(loop_1, loop_1_delay, n - 1)
end
end

function onThink(interval, lastExecution, thinkInterval)
addEvent(loop_1, loop_1_delay, loop_1_loop_amount)
return true
end

to clarify what this does:

I needed something to count the amount of players in a given area, in my case it is a waiting room.
This will count players + broadcast a message[custom] when there are a certain amount of players[custom] in a given area[custom].
It will broadcast this message every 10 seconds [custom] until the players have left.

I have another script that teleports players to event once I reach 10 players.
 
Back
Top