vSync (v1.4.0) | Simple weather and time sync


#1

vSync

Very basic time and weather sync.

Since there’s quite a lot of people requesting this simple script, and I’ve not had the time to merge it into my vBasic script, I thought I’d release it as a separate script instead.

Commands

/weather <weathertype>
/time <hour> <minutes>
/freezetime (New in v1.2.0)
/morning
/noon
/evening
/night
/freezeweather (new in v1.3.0)
/blackout (new in v1.3.0)

Configuration

Edit the Admins list in the vs_server.lua, add the player identifiers of the players that should have access to the commands in there.
That’s it, there’s nothing else to configure.

Download / Source

here

Known bugs

If you have a custom chat resource, the commands may not work correctly. In that case use the server console instead, or preferably switch back to the regular FiveM chat!

Changelog

v1.4.0

Time is now synced with GTA:O time by default. You can still override it like usual.

v1.3.0

+. Added Dynamic Weather changes. By default weather changes every 10 minutes (this feature can be enabled/disabled by either enabling/disabling it in the config, or using `/freezeweather`). Weather changes according to a realistic weather pattern. If you change the weather using the /weather command, and Dynamic Weather is enabled, then the 10 minute time will be reset to prevent having the weather change a few minutes after you changed it.
+. Added blackout feature. Type /blackout to toggle it on or off. (Blackout removes all light sources from the game).
+. Added notifications for the player that changes the time/weather/blackout mode/freeze and unfreeze weather and time.

v1.2.1

~ Fixed chat message bug (displaying incorrect new time after using /time <h> <m>)
+ Added parameters to the command suggestions to improve user experience

v1.2.0

+ Added /freezetime command to toggle frozen time.
+ Fixed "access denied" bug.
~ Made all chat messages somewhat use the same format/style.
+ Added chat suggestions!

v1.01

+ Added console support for the commands.
+ Improved invalid syntax errors to show the correct usage.
+ Fixed an issue that would crash your game if you set the time to be more than 23 hours or more than 59 minutes.

Support discord


[REQ] Time/Weather Sync Script
Most effective way to sync weather ? EX - Snow?
[Release] vBasic v3.0.1 | Basic server settings/configuration
[Request} Anyone know of a good working time and weather sync
[Release] vBasic v3.0.1 | Basic server settings/configuration
[Release] vBasic v3.0.1 | Basic server settings/configuration
Weather or time
[Release] Time And Date Display v0.4
#2

doesn’t smart weather already do this?
Anyhow thanks :slight_smile:


#3

ooh a weather script, my favorite!


#4

Smartweather doesn’t handle time.


#5

Finally ive been looking for just a simple weather and time script. Without all the extras.


#6

Is there any way to remove the permissions so anyone can change the weather?


#7

Nice work :slight_smile:


#8

Read the post, edit va_server.lua


#9

Yes, if you don’t want to use permissions (allow anyone to use the commands) then replace your vs_server.lua file with this code:

-------------------- DON'T CHANGE THIS --------------------
AvailableWeatherTypes = {
    'EXTRASUNNY', 
    'CLEAR', 
    'NEUTRAL', 
    'SMOG', 
    'FOGGY', 
    'OVERCAST', 
    'CLOUDS', 
    'CLEARING', 
    'RAIN', 
    'THUNDER', 
    'SNOW', 
    'BLIZZARD', 
    'SNOWLIGHT', 
    'XMAS', 
    'HALLOWEEN',
}
CurrentWeather = "EXTRASUNNY"
Time = {}
Time.h = 12
Time.m = 0



RegisterServerEvent('requestSync')
AddEventHandler('requestSync', function()
    TriggerClientEvent('updateWeather', -1, CurrentWeather)
    TriggerClientEvent('updateTime', -1, Time.h, Time.m)
end)

RegisterCommand('weather', function(source, args, rawCommand)
    if source == 0 then
        print("You can't use this command from the console!")
        return
    else
        if isAllowedToChange(source) then
            local validWeatherType = false
            if args[1] == nil then
                TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1Invalid syntax.')
            else
                for i,wtype in ipairs(AvailableWeatherTypes) do
                    if wtype == string.upper(args[1]) then
                        validWeatherType = true
                    end
                end
                if validWeatherType then
                    TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^3Weather has been upated.')
                    CurrentWeather = string.upper(args[1])
                    TriggerEvent('requestSync')
                else
                    TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1Invalid weather type, valid weather types are: ^0\nEXTRASUNNY CLEAR NEUTRAL SMOG FOGGY OVERCAST CLOUDS CLEARING RAIN THUNDER SNOW BLIZZARD SNOWLIGHT XMAS HALLOWEEN ')
                end
            end
        else
            TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1You do not have access to that command.')
            print('Access for command /weather denied.')
        end
    end
end, false)


RegisterCommand('morning', function(source)
    if isAllowedToChange(source) then
        Time.h = 9
        Time.m = 0
        TriggerEvent('requestSync')
    end
end)
RegisterCommand('noon', function(source)
    if isAllowedToChange(source) then
        Time.h = 12
        Time.m = 0
        TriggerEvent('requestSync')
    end
end)
RegisterCommand('evening', function(source)
    if isAllowedToChange(source) then
        Time.h = 18
        Time.m = 0
        TriggerEvent('requestSync')
    end
end)
RegisterCommand('night', function(source)
    if isAllowedToChange(source) then
        Time.h = 23
        Time.m = 0
        TriggerEvent('requestSync')
    end
end)


RegisterCommand('time', function(source, args, rawCommand)
    if source == 0 then
        print("You can't use this command from the console!")
        return
    elseif source ~= 0 then
        if isAllowedToChange(source) then
            if tonumber(args[1]) ~= nil and tonumber(args[2]) ~= nil then
                Time.h = tonumber(args[1])
                Time.m = tonumber(args[2])
                TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^2Time has been updated.')
                TriggerEvent('requestSync')
            else
                TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1Invalid syntax.')
            end
        else
            TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1You do not have access to that command.')
            print('Access for command /time denied.')
        end
    end
end)

function isAllowedToChange(player)
    return true
end

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(2000)
        Time.m = Time.m + 1
        if Time.m > 59 then
            Time.m = 0
            Time.h = Time.h + 1
            if Time.h > 23 then
                Time.h = 0
            end
        end
    end
end)

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(5000)
        TriggerClientEvent('updateTime', -1, Time.h, Time.m)
    end
end)
Citizen.CreateThread(function()
    while true do
        Citizen.Wait(300000)
        TriggerClientEvent('updateWeather', -1, CurrentWeather)
    end
end)

#10

:thinking: :thinking: :thinking: :thinking: :thinking:


#11

This is not working for me for some reason. I added myself as admin and added the steam id and license but it still doesn’t work. Any suggestions on how I can get it working?


#12

can you show the Admins section from your vs_server file?


#15

Are you using the latest server artifacts? Because it’s working for me :confused:


#16

Let me double check real quick


#17

By the way, do you get an error message saying you don’t have access to use the command or does it return nothing at all after typing /weather or /time?


#18

Great work! Thank you for sharing :slight_smile:


#19

When I do the command theres nothing at all not even in the rcon


#20

Are you sure the resource is actually started? Because using those commands should always return something, either an error message or a success message. Also this resource will conflict with other weather and time sync scripts.


#21

Is this client side only?


#22

I think I have another time sync in right now, let me remove it and try that