-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinit.lua
More file actions
99 lines (80 loc) · 3.5 KB
/
init.lua
File metadata and controls
99 lines (80 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
-------------------------------------------------------------------------------------------------------------------------------
-- This mod was created by keanuWheeze from CP2077 Modding Tools Discord.
--
-- You are free to use this mod as long as you follow the following license guidelines:
-- * It may not be uploaded to any other site without my express permission.
-- * Using any code contained herein in another mod requires credits / asking me.
-- * You may not fork this code and make your own competing version of this mod available for download without my permission.
-------------------------------------------------------------------------------------------------------------------------------
local minR4Version = "0.9.0"
local initializationError = true
local audio = require("modules/utils/audioEngine")
local radio = {
runtimeData = {
inMenu = false,
inGame = false,
time = nil,
ts = nil
},
GameUI = require("modules/utils/GameUI"),
config = require("modules/utils/config"),
Cron = require("modules/utils/Cron"),
observersV = require("modules/vehicle/observersV"),
observersP = require("modules/physical/observersP"),
logger = require("modules/utils/logger")
}
function radio:new()
registerForEvent("onInit", function()
math.randomseed(os.clock()) -- Prevent predictable random() behavior
if not RadioExt then
print("[RadioExt] Error: Red4Ext part of the mod is missing")
return
end
if tostring(RadioExt.GetVersion()) < minR4Version then
print("[RadioExt] Red4Ext Part version mismatch: Version is " .. RadioExt.GetVersion() .. " Expected: " .. minR4Version .. " or newer")
return
end
self.radioManager = require("modules/radioManager"):new(self)
self.radioManager:init()
Observe('RadialWheelController', 'OnIsInMenuChanged', function(_, isInMenu) -- Setup observer and GameUI to detect inGame / inMenu
self.runtimeData.inMenu = isInMenu
end)
self.GameUI.OnSessionStart(function()
self.runtimeData.inGame = true
end)
self.GameUI.OnSessionEnd(function()
self.runtimeData.inGame = false
self.radioManager:disableCustomRadios()
end)
self.observersV.init(self)
self.observersP.init(self)
self.runtimeData.ts = GetMod("trainSystem")
self.runtimeData.inGame = not self.GameUI.IsDetached() -- Required to check if ingame after reloading all mods
initializationError = false
end)
registerForEvent("onShutdown", function()
self.radioManager:disableCustomRadios()
end)
registerForEvent("onUpdate", function(delta)
if initializationError then return end
if (not self.runtimeData.inMenu) and self.runtimeData.inGame then
self.Cron.Update(delta)
self.radioManager:update()
self.radioManager.managerV:handleTS()
self.logger.update()
audio.update(delta)
else
self.radioManager:handleMenu()
end
end)
return self
end
return radio:new()
-- NoSync:
-- Car off, pocket on => Car turns on when entering
-- Car on, pocket off => Exiting car pocket stays off
-- Entering car with pocket on => Overrides car state
-- Changing in car, then exiting => Pocket is independent
-- Sync:
-- Entering car with pocket on => Overrides car state | Same as NoSync
-- Changing in car, then exiting => Overrides pocket | Only difference