Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit c6b0c34

Browse files
committed
many improvements
Changed almost everything after a couple of hours researching the switch natives. Findings will be published on the fivem natives reference page later.
1 parent afec3f8 commit c6b0c34

File tree

1 file changed

+67
-28
lines changed

1 file changed

+67
-28
lines changed

cloading.lua

+67-28
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
-- Copyright © Vespura 2018
22
-- Edit it if you want, but don't re-release this without my permission, and never claim it to be yours!
33

4-
local cloudOpacity = 0.01
5-
local muteSound = true
64

5+
------- Configurable options -------
76

7+
-- set the opacity of the clouds
8+
local cloudOpacity = 0.01 -- (default: 0.01)
89

10+
-- setting this to false will NOT mute the sound as soon as the game loads
11+
-- (you will hear background noises while on the loading screen, so not recommended)
12+
local muteSound = true -- (default: true)
13+
14+
15+
16+
------- Code -------
17+
18+
-- Mutes or un-mutes the game's sound using a short fade in/out transition.
919
function ToggleSound(state)
1020
if state then
1121
StartAudioScene("MP_LEADERBOARD_SCENE");
@@ -14,61 +24,90 @@ function ToggleSound(state)
1424
end
1525
end
1626

27+
-- Runs the initial setup whenever the script is loaded.
1728
function InitialSetup()
18-
-- sometimes this works, but not always.
29+
-- Stopping the loading screen from automatically being dismissed.
1930
SetManualShutdownLoadingScreenNui(true)
31+
-- Disable sound (if configured)
2032
ToggleSound(muteSound)
21-
SwitchOutPlayer(PlayerPedId(), 0, 1)
33+
-- Switch out the player if it isn't already in a switch state.
34+
if not IsPlayerSwitchInProgress() then
35+
SwitchOutPlayer(PlayerPedId(), 0, 1)
36+
end
2237
end
2338

2439

40+
-- Hide radar & HUD, set cloud opacity, and use a hacky way of removing third party resource HUD elements.
2541
function ClearScreen()
2642
SetCloudHatOpacity(cloudOpacity)
2743
HideHudAndRadarThisFrame()
28-
SetDrawOrigin(0.0, 0.0, 0.0, 0) -- nice hack to 'hide' hud elements from other resources/scripts. kinda buggy though.
44+
45+
-- nice hack to 'hide' HUD elements from other resources/scripts. kinda buggy though.
46+
SetDrawOrigin(0.0, 0.0, 0.0, 0)
2947
end
3048

31-
-- Sometimes the game loads this code correctly, sometimes it doesn't, so let's try to do it anyway because it's much nicer if it actually works like this.
49+
-- Sometimes this gets called too early, but sometimes it's perfectly timed,
50+
-- we need this to be as early as possible, without it being TOO early, it's a gamble!
3251
InitialSetup()
3352

53+
3454
Citizen.CreateThread(function()
55+
56+
-- In case it was called too early before, call it again just in case.
3557
InitialSetup()
3658

37-
local timer = GetGameTimer()
38-
39-
-- Wait
40-
while true do
41-
ClearScreen()
59+
-- Wait for the switch cam to be in the sky in the 'waiting' state (5).
60+
while GetPlayerSwitchState() ~= 5 do
4261
Citizen.Wait(0)
43-
if GetGameTimer() - timer > 5000 then
44-
-- somewhat smooth transition
45-
DoScreenFadeOut(100)
46-
Citizen.Wait(100)
47-
ShutdownLoadingScreenNui()
48-
Citizen.Wait(500)
49-
DoScreenFadeIn(1000)
50-
timer = GetGameTimer()
51-
ToggleSound(false)
52-
break
53-
end
62+
ClearScreen()
5463
end
5564

65+
-- Shut down the game's loading screen (this is NOT the NUI loading screen).
66+
ShutdownLoadingScreen()
67+
68+
ClearScreen()
69+
Citizen.Wait(0)
70+
DoScreenFadeOut(0)
71+
72+
-- Shut down the NUI loading screen.
73+
ShutdownLoadingScreenNui()
74+
5675
ClearScreen()
76+
Citizen.Wait(0)
77+
ClearScreen()
78+
DoScreenFadeIn(500)
79+
while not IsScreenFadedIn() do
80+
Citizen.Wait(0)
81+
ClearScreen()
82+
end
83+
84+
local timer = GetGameTimer()
85+
86+
-- Re-enable the sound in case it was muted.
87+
ToggleSound(false)
5788

5889
while true do
5990
ClearScreen()
6091
Citizen.Wait(0)
61-
if GetGameTimer() - timer > 3000 then
62-
-- zoom in
92+
93+
-- wait 5 seconds before starting the switch to the player
94+
if GetGameTimer() - timer > 5000 then
95+
96+
-- Switch to the player.
6397
SwitchInPlayer(PlayerPedId())
64-
while GetGameTimer() - timer < 8500 do
65-
-- keep hud invisible while transitioning
66-
ClearScreen()
98+
99+
ClearScreen()
100+
101+
-- Wait for the player switch to be completed (state 12).
102+
while GetPlayerSwitchState() ~= 12 do
67103
Citizen.Wait(0)
104+
ClearScreen()
68105
end
106+
-- Stop the infinite loop.
69107
break
70108
end
71109
end
110+
111+
-- Reset the draw origin, just in case (allowing HUD elements to re-appear correctly)
72112
ClearDrawOrigin()
73113
end)
74-

0 commit comments

Comments
 (0)