[OpenSource][C#] FiveSPN-Weather - Open-Source Release [Updated 11/12/22 v3.0.2]

fspnweather

FiveSPN—Weather - Updated 11/12/22 v3.0.2

Since 2019 I have done considerable development for my own FiveM servers. I have since graduated with a BS in Software Development and am revamping everything that I wrote for public open-source release! This resource has been written from scratch and is part of a collection of resources that will be released over the next few weeks!

FiveSPN-Weather is a FiveM resource that syncs the game server weather between all players to up to four real-world locations or a global override set by a server admin from within the game.

View the source and get the resource on GitHub!

Prerequisites

For best performance and monitoring, make sure the FiveSPN–Logger resource is used as well. It is available on GitHub

Installation

Step One: Add the resource to your server.

Copy the folder inside of the FiveMResource folder into your server’s resources folder and add it to the server.cfg with the following line.

start FiveSPN-WeatherSync

Step Two: Get an Open Weather Map API key for your server.

  1. Goto https://openweathermap.org/
  2. Register
  3. Navigate to the API key area and generate a key for each server you are using.
  4. Add the key to the FiveSPN-Weather resource manifest.

Step Three: Add the source location to the locations.json file.

Using either a zip code, city id, city name, or weather string, add up to ten weather points in the locations.json file. You can add just one type or mix and match!

Default locations are Seattle, WA for the northwest, Phoenix for the desert areas, and Pasadena (LA) for the big city, with snow on top of the big mountain!

The main pieces of information in each line of the locations.json are:

  1. Location or Weather String.
    • [Cities] City name text string. IE “Dallas”, “Reno”, “Denver”
    • [Zips] Zip code numeral. IE 90210
    • [Ids] City Id code numeral. This is useful for complicated city names!
      • Can be found here by searching and looking at url on city page
      • Can be found here in the current city list if you can decipher json.
    • [Forced] Weather string. This lets you permanently set a weather type for an area. See the commands below for weather-type options.
  2. The three X/Y/Z coordinates of the point.
  3. The range for the weather. Leave the range at 0 to extend against all other points. (If no points are 0, the weather will be clear when not in a ranged point)

Using City Name

{
    "Cities": [
        ["Seattle", -165.17, 6052.23, 80.03, 0],
        ["Phoenix", 1398.82, 3977.76, 324.74, 0],
        ["Pasadena", -353.02, 523.95, 523.95, 0]
    ],
    "Zips": [
        
    ],
    "Ids": [
        
    ],
    "Forced": [
        ["SNOW", 491.32,5580.2,792.42, 350]
    ]
}

Using Zip

{
    "Cities": [

    ],
    "Zips": [
        [98101, -165.17, 6052.23, 80.03, 0],
        [85323, 1398.82, 3977.76, 324.74, 0],
        [90001, -353.02, 523.95, 523.95, 0]
    ],
    "Ids": [

    ],
    "Forced": [
        ["SNOW", 491.32,5580.2,792.42, 350]
    ]
}

Using City Id

{
    "Cities": [
        
    ],
    "Zips": [
        
    ],
    "Ids": [
        [5809844, -165.17, 6052.23, 80.03, 0],
        [5308655, 1398.82, 3977.76, 324.74, 0],
        [5368361, -353.02, 523.95, 523.95, 0]
    ],
    "Forced": [
        ["SNOW", 491.32,5580.2,792.42, 350]
    ]
}

Admin Server Commands v3.0.2

These can be used to test information and weather.
Can be used by anyone.
/Weather DEBUG - Displays debug information. 
/Weather SYNC - Forces a client weather sync. (Overrides the normal client side update delay)
/Weather REFRESH - Requests the latest data from the server be sent to all players. (Overrides the normal server side update time delay)

These can be used to update the weather server wide.
Can be used by anyone in the group ServerAdmin or WeatherAdmin.
/Weather REFRESH - Forces a server wide refresh of weather.
/Weather RESET - Resumes using real world sync.
/Weather CLEAR - Sets weather to clear.
/Weather THUNDER - Sets weather to thunderstorms.
/Weather RAIN - Sets weather to rain.
/Weather SNOWLIGHT - Sets weather to light snow.
/Weather SNOW - Sets weather to snow.
/Weather BLIZZARD - Sets weather to blizzard.
/Weather FOGGY - Sets weather to foggy.
/Weather EXTRASUNNY - Sets weather to extra sunny.
/Weather CLOUDS - Sets weather to clouds.
/Weather OVERCAST - Sets weather to overcast.
/Weather SMOG - Sets weather to smog.

Forced Weather Type Strings:

"CLEAR" - Sets weather to clear.
"THUNDER" - Sets weather to thunderstorms.
"RAIN" - Sets weather to rain.
"SNOWLIGHT" - Sets weather to light snow.
"SNOW" - Sets weather to snow.
"BLIZZARD" - Sets weather to blizzard.
"FOGGY" - Sets weather to foggy.
"EXTRASUNNY" - Sets weather to extra sunny.
"CLOUDS" - Sets weather to clouds.
"OVERCAST" - Sets weather to overcast.
"SMOG" - Sets weather to smog.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Licensing

Copyright ©2022 Owen Dolberg (SourPatchNom)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.

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

In the hopes that the greater community may benefit, you may use this code under the GNU Affero General Public License v3.0.

This resource distribution utilizes the Newtonsoft.JSON Library under the MIT License.

This software references CitizenFX.Core.Server and CitizenFX.Core.Client NuGet packages (c) 2017-2020 the CitizenFX Collective used under license and under the FiveM Service Agreement

Credits

  • Sloosecannon for inspiration and rubber ducky assistance during the initial conception of all this in 2020.
  • AGHMatti I think… for reference on the http helper, really wish I could locate the source repo now.
3 Likes

does it sync time aswell?

2 Likes

FiveSPN-Weather does not sync game time but check out FiveSPN-Clock! It is made specifically to sync the game time for all players to real-world time or a scaled real-world time! I’ll be posting it and a few more resources here tomorrow, and more over the next few weeks!

Curious how this will work with IPL loaded housing and things of that magnitude? Will that cause flicker

1 Like

Are you referencing third-party interiors? Assuming that the asset is properly built the game should know that you are inside. The system uses the default game weather, so when you are in a default game IPL for example, you can hear thunder if it’s a thunderstorm outside, but no rain issues or glitch issues inside.

1 Like

Great :heart:
Im a little confused about the locations, basically i want ‘normal’ weather in the City and Desert, Snow at upper part of Mount Chilliard and snowy in Paleto Bay. What City would you choose for permanent snow?

1 Like

How does this set up zoning on the map for different weather?

Like will weather be different in paleto than sandy or the city?

Been getting errors on start up, followed instructions unsure what im missing.
server:
Log>[ FiveSPN-Weather][ Error]14:43:21 Unable to process WeatherAPI request! Log>[ FiveSPN-Weather][ Error]14:43:21 Value cannot be null.
Client
Loaded WeatherSyncClient.net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null into ScriptDomain_2086382914

Saying the public key token is null? but have the API key put on the fxmanifest?

You have to create an API first

1 Like

I have created an API thou? pasted it in fxmanifest.
EDIT:

Created one yesterday, said it would take up to 1 hour to confirm. I been checking constantly on my test server and it hasnt updated.

@fourliferoleplay Great news!

I just pushed an update today that added the ability to force a weather type for an area instead of using real-world weather! You can also do both so if you want Chilliad to always be snowy and Las Santos to be synced with Pasadenas weather you can!

The original post is updated with more information above!

1 Like

That is correct!

@Beauflexx Hmmm, you might double-check your fxmanifest.lua and make sure you have it formatted properly with an on each end. It may also take some time for your key to be activated!

notepad++_Im7Ndf4XON

1 Like

update slightly fixed issue, was able to get it connected.
Zip codes can be weird, having better luck with city names

1 Like

Glad to hear!

A big thank you for your scripts

It’s awesome

1 Like

with me it snows ingame although with us the sun shines :smiley:

url must be changed in fxmanifest??

@noskillarmy I’m not following completely, maybe these can help:

The installation guide is on GitHub, you do need an API key that is outlined there to be put in fxmanifest.

It takes time for the weather to change for any given client. The resource has both client and server update intervals to gradually transitions weather over a period of time.

You can test better with the latest release v3.0.2. It is available in the repositories and has new commands to force the sync to happen a little faster as well as a debug option to display more info on the screen.

Admin Server Commands v3.0.2

These can be used to test information and weather.
/Weather DEBUG - Displays debug information. 
/Weather SYNC - Forces a client weather sync. (Overrides the normal client-side update delay)
/Weather REFRESH - Requests the latest data from the server be sent to all players. (Overrides the normal server-side update time delay)

These can be used to update the weather server-wide.
/Weather RESET - Resumes using real-world sync.
/Weather CLEAR - Sets weather to clear.
/Weather THUNDER - Sets weather to thunderstorms.
/Weather RAIN - Sets weather to rain.
/Weather SNOWLIGHT - Sets weather to light snow.
/Weather SNOW - Sets weather to snow.
/Weather BLIZZARD - Sets weather to blizzard.
/Weather FOGGY - Sets weather to foggy.
/Weather EXTRASUNNY - Sets weather to extra sunny.
/Weather CLOUDS - Sets weather to clouds.
/Weather OVERCAST - Sets weather to overcast.
/Weather SMOG - Sets weather to smog.

But there is a problem when running now that I use the script
I always have snow tracks

@Script4ever That’s an interesting effect, I am unable to recreate anything like that. It almost seems like a graphics card or additional script issue.

Do you have other scripts running that might affect the weather?

Did you transition from snow to another weather area?

What environment is that under? (world location or set weather?)