[NOTOFICATIONS] [Restart Announce]

Hello all :slight_smile:

I use the script “notifications”. I added some lines to Announce my Server restarts.
The Problem is, if 5 players are connectet, i get 5 times an announce. I only want to announce once.

client.lua

Citizen.CreateThread(function()
    while true do

	local year, date,day, hours, minutes, seconds = Citizen.InvokeNative(0x50C7A99057A69748, Citizen.PointerValueInt(), Citizen.PointerValueInt(), Citizen.PointerValueInt(), Citizen.PointerValueInt(), Citizen.PointerValueInt(), Citizen.PointerValueInt())	
	local stringhours = tostring(hours)
	local stringminutes = tostring(minutes)
    	local stringseconds = tostring(seconds)
	local time = stringminutes .. ":" .. stringseconds
    if (stringhours == "23") or (stringhours == "5") or (stringhours == "11") or (stringhours == "17") then
      switch(time, { 
        ["30:1"] = function()	
            ExecuteCommand("2154125") 
	    Citizen.Wait(1000) 
        end,
        ["45:1"] = function()	
            ExecuteCommand("7846985")
            Citizen.Wait(1000)   
        end,
        ["50:1"] = function()	
            ExecuteCommand("61349785")
            Citizen.Wait(1000)
        end,
        ["55:1"] = function()	
            ExecuteCommand("468123348")
            Citizen.Wait(1000)
        end,
        ["59:1"] = function()	
            ExecuteCommand("4875511987")
            Citizen.Wait(1000)
        end,
        ['default'] = function()	
         
            Citizen.Wait(0)
        end
         })
        else Citizen.Wait(0)
        end
        end
        end)

server.lua

RegisterCommand("2154125", function(source, args)

    TriggerClientEvent("notifications_restart:on",-1, "Server restart in 30 Minuten")

end, false)

RegisterCommand("7846985", function(source, args)

    TriggerClientEvent("notifications_restart:on",-1, "Server restart in 15 Minuten")

end, false)

RegisterCommand("61349785", function(source, args)

    TriggerClientEvent("notifications_restart:on",-1, "Server restart in 10 Minuten")

end, false)

RegisterCommand("468123348", function(source, args)
    TriggerClientEvent("notifications_restart:on",-1, "Server restart in 5 Minuten")
end, false)

RegisterCommand("4875511987", function(source, args)
    TriggerClientEvent("notifications_restart:on",-1, "Server restart in 1 Minute")
end, false)
1 Like

Firstly, this is because each client executes the command. If you want the announcement to happen only once, you need to make the code in server.lua.

I also suggest to make a separate loop, that checks for the time and executes a function when needed to make it more optimized.

Also, don’t use commands to make the announcement, you can just use Trigger(Server/Client)Event and use functions/ events.

Let me know if you need some more help!

okay thank you, i will try :slight_smile:

1 Like