This repository was archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcloading.lua
113 lines (84 loc) · 3.17 KB
/
cloading.lua
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
-- Copyright © Vespura 2018
-- Edit it if you want, but don't re-release this without my permission, and never claim it to be yours!
------- Configurable options -------
-- set the opacity of the clouds
local cloudOpacity = 0.01 -- (default: 0.01)
-- setting this to false will NOT mute the sound as soon as the game loads
-- (you will hear background noises while on the loading screen, so not recommended)
local muteSound = true -- (default: true)
------- Code -------
-- Mutes or un-mutes the game's sound using a short fade in/out transition.
function ToggleSound(state)
if state then
StartAudioScene("MP_LEADERBOARD_SCENE");
else
StopAudioScene("MP_LEADERBOARD_SCENE");
end
end
-- Runs the initial setup whenever the script is loaded.
function InitialSetup()
-- Stopping the loading screen from automatically being dismissed.
SetManualShutdownLoadingScreenNui(true)
-- Disable sound (if configured)
ToggleSound(muteSound)
-- Switch out the player if it isn't already in a switch state.
if not IsPlayerSwitchInProgress() then
SwitchOutPlayer(PlayerPedId(), 0, 1)
end
end
-- Hide radar & HUD, set cloud opacity, and use a hacky way of removing third party resource HUD elements.
function ClearScreen()
SetCloudHatOpacity(cloudOpacity)
HideHudAndRadarThisFrame()
-- nice hack to 'hide' HUD elements from other resources/scripts. kinda buggy though.
SetDrawOrigin(0.0, 0.0, 0.0, 0)
end
-- Sometimes this gets called too early, but sometimes it's perfectly timed,
-- we need this to be as early as possible, without it being TOO early, it's a gamble!
InitialSetup()
Citizen.CreateThread(function()
-- In case it was called too early before, call it again just in case.
InitialSetup()
-- Wait for the switch cam to be in the sky in the 'waiting' state (5).
while GetPlayerSwitchState() ~= 5 do
Citizen.Wait(0)
ClearScreen()
end
-- Shut down the game's loading screen (this is NOT the NUI loading screen).
ShutdownLoadingScreen()
ClearScreen()
Citizen.Wait(0)
DoScreenFadeOut(0)
-- Shut down the NUI loading screen.
ShutdownLoadingScreenNui()
ClearScreen()
Citizen.Wait(0)
ClearScreen()
DoScreenFadeIn(500)
while not IsScreenFadedIn() do
Citizen.Wait(0)
ClearScreen()
end
local timer = GetGameTimer()
-- Re-enable the sound in case it was muted.
ToggleSound(false)
while true do
ClearScreen()
Citizen.Wait(0)
-- wait 5 seconds before starting the switch to the player
if GetGameTimer() - timer > 5000 then
-- Switch to the player.
SwitchInPlayer(PlayerPedId())
ClearScreen()
-- Wait for the player switch to be completed (state 12).
while GetPlayerSwitchState() ~= 12 do
Citizen.Wait(0)
ClearScreen()
end
-- Stop the infinite loop.
break
end
end
-- Reset the draw origin, just in case (allowing HUD elements to re-appear correctly)
ClearDrawOrigin()
end)