JIT
creating a weather synchronization script for a game server
client.lua local vZones = {} local currentZone = nil local lastZone = nil local timeSeconds = 0 local timeMinutes = 0 local timeHours = 0 Citizen.CreateThread(function() Citizen.Wait(2500) TriggerServerEvent('weathersync:fetchZones') while true do local wait = 20000 local pedCoords = GetEntityCoords(PlayerPedId()) local lastDst = nil local _thisZone = nil for k,v in pairs(Config.Zones) do local dstCheck = GetDistanceBetweenCoords(pedCoords, v, true) if lastDst ~= nil then if dstCheck < lastDst then lastDst = dstCheck _thisZone = k end else _thisZone = k lastDst = dstCheck end end currentZone = _thisZone Wait(wait) end end) Citizen.CreateThread(function() while currentZone == nil do Wait(3000) end while true do if currentZone ~= nil then if currentZone ~= lastZone then lastZone = currentZone SetWeatherTypeOverTime(vZones[currentZone], 5.0) Citizen.Wait(5000) end ClearOverrideWeather() ClearWeatherTypePersist() SetWeatherTypePersist(vZones[lastZone]) SetWeatherTypeNow(vZones[lastZone]) SetWeatherTypeNowPersist(vZones[lastZone]) end Wait(100) end end) RegisterNetEvent('weathersync:updateZones') AddEventHandler('weathersync:updateZones', function(zones) if zones then vZones = zones end end) RegisterNetEvent('weathersync:updateTime') AddEventHandler('weathersync:updateTime', function(hours, minutes, seconds) timeHours = hours timeMinutes = minutes timeSeconds = seconds end) Citizen.CreateThread(function() while true do Citizen.Wait(0) NetworkOverrideClockTime(timeHours, timeMinutes, timeSeconds) end end) -- RegisterCommand('removesnow', function() -- SetForceVehicleTrails(false) -- SetForcePedFootstepsTracks(false) -- end) config.lua Config = {} Config.Zones = { [1] = vector3(-18.83, -960.19, 71.2), [2] = vector3(1586.7, 3603.19, 47.24), [3] = vector3(145.33, 6632.3, 42.83), } Config.WeatherTypes = { [1] = { ['type'] = 'EXTRASUNNY', ['chance'] = 35, }, [2] = { ['type'] = 'CLEAR', ['chance'] = 25, }, [3] = { ['type'] = 'CLOUDS', ['chance'] = 25, }, [4] = { ['type'] = 'SMOG', ['chance'] = 25, }, [5] = { ['type'] = 'THUNDER', ['chance'] = 0, }, [6] = { ['type'] = 'RAIN', ['chance'] = 10, }, } kan du göra en server.lua
Updated files
v1