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

vSync

Very basic time and weather sync.

Update 17-12-2018

I will no longer be maintaining/supporting this resource. The GitHub repo has been archived. Fork it if you want to update it yourself.

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.

Important support info / FAQ

Update 26-11-2018: Since everyone seems to be unable to figure out how to use CTRL + F on this forum topic, here you go. It’s not that difficult, really. I will ignore people who ask the following things from now on:

  • I installed this resource but it says I don’t have access to execute the commands [even though i added myself as an admin]:
    Spoiler alert: you didn’t add yourself as an admin. You probably used the wrong identifier. Look on the wiki or look in the forums. There are a million explanations already out there on how to get your player identifier, and how to setup vSync. I’d suggest you start with the vSync installation instructions.

  • I installed vSync but the ‘sky/lights are flickering’ (or whatever you’all seem to call this issue):
    Disable any other weather/time (sync) script. Remove all (broken) (graphics) mods from your FiveM/GTA V installation.

52 Likes

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

2 Likes

ooh a weather script, my favorite!

2 Likes

Smartweather doesn’t handle time.

3 Likes

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

4 Likes

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

1 Like

Nice work :slight_smile:

3 Likes

Read the post, edit va_server.lua

2 Likes

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)
7 Likes

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

4 Likes

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?

8 Likes

can you show the Admins section from your vs_server file?

1 Like

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

2 Likes

Let me double check real quick

1 Like

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?

2 Likes

Great work! Thank you for sharing :slight_smile:

2 Likes

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

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.

1 Like

Is this client side only?

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

1 Like