Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3 Weather System #666

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions vrp/cfg/control.lua

This file was deleted.

6 changes: 3 additions & 3 deletions vrp/cfg/groups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function police_init(user)
weapons["WEAPON_NIGHTSTICK"] = {ammo=0}
weapons["WEAPON_FLASHLIGHT"] = {ammo=0}

vRP.EXT.PlayerState.remote._giveWeapons(user.source,weapons,true)
vRP.EXT.Police.remote._setCop(user.source,true)
vRP.EXT.PlayerState.remote._setArmour(user.source,100)
--vRP.EXT.PlayerState.remote._giveWeapons(user.source,weapons,true)
--vRP.EXT.Police.remote._setCop(user.source,true)
--vRP.EXT.PlayerState.remote._setArmour(user.source,100)
end

function police_onjoin(user)
Expand Down
2 changes: 1 addition & 1 deletion vrp/cfg/modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local modules = {
group = true,
gui = true,
map = true,
control = true -- weather and time controls
weather = true,
}

return modules
29 changes: 29 additions & 0 deletions vrp/cfg/weather.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local cfg = {}

cfg.time = {
['Morning'] = 9,
['Noon'] = 12,
['Evening'] = 18,
['Night'] = 23
}

cfg.types = {
'EXTRASUNNY',
'CLEAR',
'SMOG',
'FOGGY',
'OVERCAST',
'CLOUDS',
'CLEARING',
'RAIN',
'THUNDER',
'SNOW',
'BLIZZARD',
'SNOWLIGHT'

--'XMAS',
--'NEUTRAL', --makes sky green
--'HALLOWEEN'
}

return cfg
126 changes: 0 additions & 126 deletions vrp/client/control.lua

This file was deleted.

116 changes: 116 additions & 0 deletions vrp/client/weather.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
-- https://github.com/ImagicTheCat/vRP
-- MIT license (see LICENSE or vrp/vRPShared.lua)
if not vRP.modules.weather then return end

local Weather = class("Weather", vRP.Extension)

-- METHODS

function Weather:__construct()
vRP.Extension.__construct(self)

self.current = nil
self.freeze = false
self.blackout = false

self.time = 0
self.newTime = 0
self.offset = 0

self.timer = 0
self.newTimer = 10

self.normal = 2000 -- normal ms per minute
self.alteredTime = 0 -- altered ms per minute
self.speedTime = 1 -- time speed increase default
self.slowTime = 1 -- time speed decrease default

end

function Weather:sync()
if not self.current then self.current = 'CLEAR' end
self.remote._setWeather(self.current)

if self.alteredTime >= 0 then self.alteredTime = 2000 end -- prevents time issue
SetMillisecondsPerGameMinute(self.alteredTime)
end

function Weather:setWeather(weather)
local current = string.upper(weather)
if not current then current = 'CLEAR' end

self.current = current
ClearOverrideWeather()
ClearWeatherTypePersist()
SetWeatherTypePersist(current)
SetWeatherTypeNow(current)
SetWeatherTypeNowPersist(current)
end

function Weather:setHour(hour)
self.offset = self.offset - ((((self.time + self.offset) / 60) % 24 ) - tonumber(hour)) * 60
end

function Weather:setTime(hour)
if not hour then hour = 12 end
self:setHour(hour)

local newTime = self.time
if GetGameTimer() - 500 > self.timer then
newTime = newTime + 0.25
self.timer = GetGameTimer()
end

self.time = newTime
hour = math.floor(((self.time + self.offset)/60)%24)
minute = math.floor((self.time + self.offset)%60)
NetworkOverrideClockTime(hour, minute, 0)
end

function Weather:speedUpTime(inc)
SetMillisecondsPerGameMinute(self.normal)

if not inc then inc = self.speedTime end
local minute = math.floor(GetMillisecondsPerGameMinute() / inc)

SetMillisecondsPerGameMinute(minute)
self.alteredTime = minute
end

function Weather:slowTime(dec)
SetMillisecondsPerGameMinute(self.normal)

if not dec then dec = self.slowTime end
local minute = math.floor(GetMillisecondsPerGameMinute() * dec)

SetMillisecondsPerGameMinute(minute)
self.alteredTime = minute
end

function Weather:toggleFreeze()
self.freeze = not self.freeze
local hours, minutes, seconds = GetClockHours(), GetClockMinutes(), GetClockSeconds()

while self.freeze do
Wait(1)
NetworkOverrideClockTime(GetClockHours(), GetClockMinutes(), GetClockSeconds())
end
end

function Weather:toggleBlackout()
self.blackout = not self.blackout
SetArtificialLightsState(self.blackout)
end

-- TUNNEL

Weather.tunnel = {}
Weather.tunnel.sync = Weather.sync
Weather.tunnel.setWeather = Weather.setWeather
Weather.tunnel.setTime = Weather.setTime
Weather.tunnel.toggleFreeze = Weather.toggleFreeze
Weather.tunnel.toggleBlackout = Weather.toggleBlackout
Weather.tunnel.speedUpTime = Weather.speedUpTime
Weather.tunnel.slowTime = Weather.slowTime

vRP:registerExtension(Weather)
Loading