Code Monkey home page Code Monkey logo

qb-weathersync's Introduction

qb-weathersync

Synced weather and time for QB-Core Framework ๐ŸŒ…

License

QBCore Framework
Copyright (C) 2021 Joshua Eger

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>

Dependencies

Features

  • Syncs the weather for all players

Installation

Manual

  • Download the script and put it in the [qb] directory.
  • Add the following code to your server.cfg/resouces.cfg
ensure qb-core
ensure qb-weathersync

Configuration

You can adjust available weather and defaults in config.lua to adjust weather patterns you need to modify nextWeatherStage() in server/server.lua

Commands

/freezetime - Toggle time progression

/freezeweather - Toggle dynamic weather

/weather [type] - Set weather

/blackout - Toggle blackout

/morning - Set time to 9am

/noon - Set time to 12pm

/evening - Set time to 6pm

/night - Set time to 11pm

/time [hour] (minute) - Set time to whatever you want

Exports

nextWeatherStage

Triggers event to switch weather to next stage

-- LUA EXAMPLE
local success = exports["qb-weathersync"]:nextWeatherStage();
// JAVASCRIPT EXAMPLE
const success = global.exports["qb-weathersync"].nextWeatherStage();

setWeather [type]

Switch to a specified weather type from Config.AvailableWeatherTypes

-- LUA EXAMPLE
local success = exports["qb-weathersync"]:setWeather("snow");
// JAVASCRIPT EXAMPLE
const success = global.exports["qb-weathersync"].setWeather("snow");

setTime [hour] (minute)

Sets sun position based on time to specified

-- LUA EXAMPLE
local success = exports["qb-weathersync"]:setTime(8, 10); -- 8:10 AM
// JAVASCRIPT EXAMPLE
const success = global.exports["qb-weathersync"].setTime(15, 30); // 3:30PM

setBlackout (true|false)

Sets or toggles blackout state and returns the state

-- LUA EXAMPLE
local newStatus = exports["qb-weathersync"]:setBlackout(); -- Toggle
// JAVASCRIPT EXAMPLE
const newStatus = global.exports["qb-weathersync"].setBlackout(true); // Enable

setTimeFreeze (true|false)

Sets or toggles time freeze state and returns the state

-- LUA EXAMPLE
local newStatus = exports["qb-weathersync"]:setTimeFreeze(); -- Toggle
// JAVASCRIPT EXAMPLE
const newStatus = global.exports["qb-weathersync"].setTimeFreeze(true); // Enable

setDynamicWeather (true|false)

Sets or toggles dynamic weather state and returns the state

-- LUA EXAMPLE
local newStatus = exports["qb-weathersync"]:setDynamicWeather(); -- Toggle
// JAVASCRIPT EXAMPLE
const newStatus = global.exports["qb-weathersync"].setDynamicWeather(true); // Enable

getBlackoutState

Returns if blackout is enabled or disabled

-- LUA EXAMPLE
local state = exports["qb-weathersync"]:getBlackoutState();
// JAVASCRIPT EXAMPLE
const state = global.exports["qb-weathersync"].getBlackoutState();

getTimeFreezeState

Returns if time progression is enabled or disabled

-- LUA EXAMPLE
local state = exports["qb-weathersync"]:getTimeFreezeState();
// JAVASCRIPT EXAMPLE
const state = global.exports["qb-weathersync"].getTimeFreezeState();

getWeatherState

Returns the current weather type

-- LUA EXAMPLE
local currentWeather = exports["qb-weathersync"]:getWeatherState();
// JAVASCRIPT EXAMPLE
const currentWeather = global.exports["qb-weathersync"].getWeatherState();

getDynamicWeather

Returns if time progression is enabled or disabled

-- LUA EXAMPLE
local state = exports["qb-weathersync"]:getDynamicWeather();
// JAVASCRIPT EXAMPLE
const state = global.exports["qb-weathersync"].getDynamicWeather();

Events

qb-weathersync:server:RequestStateSync - Sync time and weather for everyone

qb-weathersync:server:setWeather [type] - Set Weather type (List in Config)

qb-weathersync:server:setTime [hour] (minute) - Set simulated time

qb-weathersync:server:toggleBlackout (true|false) - Enable, disable or toggle blackout

qb-weathersync:server:toggleFreezeTime (true|false) (minute) - Enable, disable or toggle time progression

qb-weathersync:server:toggleDynamicWeather (true|false) - Enable, disable or toggle dynamic weather

qb-weathersync's People

Contributors

azutake avatar berkiebb avatar ciavalentinas avatar codereddev avatar danielcoelh0 avatar darknight2590 avatar dennrick avatar evanillaa avatar ghzgarage avatar i-kulgu avatar idrisdose avatar jensgryspeert avatar leaudevian avatar lionh34rt avatar mataskc avatar matthewrorke avatar meta-hub avatar newtonzz avatar nicodk6400 avatar revonity avatar sna-aaa avatar suelthedev avatar synthethics avatar theilleniumstudios avatar tom-osborne avatar unawarepuma avatar virus18sp avatar youremeh avatar z3rio avatar zfbx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

qb-weathersync's Issues

Time tick

How do I change how fast a day cycle is compared to IRL hour or minutes?

[BUG] AUTOMATIC WEATHER CHANGE

I DON'T KNOW IF IT'S A BUG OR IF I'VE GOT SOMETHING WRONG, BUT APART FROM NIGHT AND DAY YOU DON'T GET RAIN OR STORMS.... HERE IS A PICTURE OF WHETHER I HAVE GOT EVERYTHING RIGHT, WHAT DO YOU THINK?
WEATHER

Issue with day en nicht

I already place a topic but on the wrong place... so here again :)

I wonder why it's always nighttime on my server, I have to change the time every time, to get it daytime, no matter how I set it, if I turn off all timers and timesinc off then it's still always at night, really this is so annoying.

Freezetime not working

Freezetime no longer working, when you unfreeze time it returns to the time you froze it at,
eg. you set time for noon, freezetime, time still progresses.. its getting dark. unfreeze time and it goes back to noon.

[BUG] shows errors in F8 console

Describe the bug
When i start the Server and i press F8 this error shows up.
[ 31562] [ GTAProcess] MainThrd/ __Lua_InvokeNative: execution failed: Error executing native 0xe2b187c0939b3d32 at address (nil).
[ 31562] [ GTAProcess] MainThrd/ ^1SCRIPT ERROR: Execution of native e2b187c0939b3d32 in script host failed: Error executing native 0xe2b187c0939b3d32 at address (nil).^7
[ 31562] [ GTAProcess] MainThrd/ ^3> SetArtificialLightsStateAffectsVehicles^7 (^5SetArtificialLightsStateAffectsVehicles.lua^7:7)
[ 31562] [ GTAProcess] MainThrd/ ^3> fn^7 (^5@qb-weathersync/client/client.lua^7:56)

To Reproduce
Steps to reproduce the behavior:
Just start the Server

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Questions (please complete the following information):

  • When you last updated: today
  • Are you using custom resource? which ones? just qb-core and all qb-addons
  • Have you renamed qb- to something custom? no, the folder is "qb-core" like in the description on github

Additional context
Add any other context about the problem here.
2023-08-05 19_55_30

[SUGGESTION] More dynamic weather

Is your feature request related to a problem? Please describe.
Currently the weather changing seems to be non-existent, or so mild between states that it's hardly noticeable, despite the weather change timer set very low, between a 8-hour period.

Describe the feature you'd like
I think the config/script just needs playing with a bit more, we set weather to change every 5 minutes just to see what happens, excpet during a 8 hour window between restarts, all we see is extrasunny, cloudy and occasionally fog. It never rains (maybe once a week if that, so we end up having to force change weather for variety.

Describe alternatives you've considered
I remember an ollllld fork of qb-weathersync that made this much more dynamic, but I gave up bothering with maintaining it between default qb updates, so better to just enhance this one.

Additional context

Blackout enabled causes flickering

Not sure when or what asset i could have conflicting but i dont have vsync or any other possible weather related controlling script in but i recently dropped in a fresh clean copy of qb weathersync and as soon as i try to enable blackout, power only flickers.

"help wanted" make time slow

I want to slow down time on the server so that the day is about two to three hours long.
I didn't find any information in the config.
can someone tell me how to do it without third party resources?

[RFC] Confusing time calculation

As I want to set the game time depending on the current real time I was looking through the time code in here (that is probably also inspired by vSync).

I found some weird time calculations as the following (I'm assuming baseTime is in seconds):

local newBaseTime = os.time(os.date("!*t"))/2 + 360

OR

hour = math.floor(((baseTime+timeOffset)/60)%24)

The first (under my assumption) does not make any sence as dividing the time by 2 will make every time that was calculated based on newBaseTime inaccurate (hours won't match at all). Also I can't think of a good idea why you have to add 360.

For the second line of code it is just simply wrong. As you would have to calculate the hours by dividing the time by 3600 and then modulo 24 (based on the assumption of time in seconds).

TLDR

Time calculations seem wrong. Am I right? Should I rewrite this whole thing to make useful time calculation?

[BUG]

I have a QB Core framework, and has this qb-weathersync, but I also have vMenu. I am confused because the server is flicking day and night, I think the weathers on both resources are overriding each other. what to do to fix this?

[BUG] bloack feature broken, lights flicker

using qbcore 1.1.0

when i used the /blackout feature the lighting only flickers and appears to be bugged.
I do not have any other type of weather/time resource besides qb weathersync

any advise on fixing this?

No rain?

trying to make it rain, can hear it raining, can see the weather changed but cant see rain, puddles on the floor or water on the floor looks very vanilla

[BUG]

Describe the bug
A clear and concise description of what the bug is. A stranger to qbcore should be able to read your bug report and understand how to reproduce it themselves and understand how the feature should work normally.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Use this item '....' (item's name from shared.lua if applicable)
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.
This Problem is here for last2 years Please Fix it

Screenshots
If applicable, add screenshots to help explain your problem.
Screenshot_2

Questions (please complete the following information):

  • When you last updated: [e.g. last week]
  • Today
  • Are you using custom resource? which ones? [e.g. zdiscord, qb-target]
  • no custom resorce
  • Have you renamed qb- to something custom? [e.g. yes/no]
  • no

Additional context
Add any other context about the problem here.

incorrect increase in the duration of the weather cycle?

Please tell me, isn't there an incorrect increase in the duration of the weather cycle? Why is newWeatherTimer used in Wait in every iteration
Citizen.CreateThread(function()
while true do
newWeatherTimer = newWeatherTimer - 1
Citizen.Wait((1000 * 60) * Config.NewWeatherTimer)
if newWeatherTimer == 0 then
if Config.DynamicWeather then
NextWeatherStage()
end
newWeatherTimer = Config.NewWeatherTimer
end
end
end)

[SUGGESTION] Real Time

Describe the feature you'd like
I think it would be cool if you could synchronize the time in game with the time on the game server

I have a problem with this script [BUG]

I have a blackout script that is connected to other loot scripts, but when I start the server it gives me an error
SCRIPT ERROR: @qb-powerplant/server/sv_main.lua:102: No such export getBlackoutState in resource qb-weathersync

can you help me how to solve this problem

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.