You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
Changed almost everything after a couple of hours researching the switch natives. Findings will be published on the fivem natives reference page later.
-- Edit it if you want, but don't re-release this without my permission, and never claim it to be yours!
3
3
4
-
localcloudOpacity=0.01
5
-
localmuteSound=true
6
4
5
+
------- Configurable options -------
7
6
7
+
-- set the opacity of the clouds
8
+
localcloudOpacity=0.01-- (default: 0.01)
8
9
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
+
localmuteSound=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.
9
19
functionToggleSound(state)
10
20
ifstatethen
11
21
StartAudioScene("MP_LEADERBOARD_SCENE");
@@ -14,61 +24,90 @@ function ToggleSound(state)
14
24
end
15
25
end
16
26
27
+
-- Runs the initial setup whenever the script is loaded.
17
28
functionInitialSetup()
18
-
--sometimes this works, but not always.
29
+
--Stopping the loading screen from automatically being dismissed.
19
30
SetManualShutdownLoadingScreenNui(true)
31
+
-- Disable sound (if configured)
20
32
ToggleSound(muteSound)
21
-
SwitchOutPlayer(PlayerPedId(), 0, 1)
33
+
-- Switch out the player if it isn't already in a switch state.
34
+
ifnotIsPlayerSwitchInProgress() then
35
+
SwitchOutPlayer(PlayerPedId(), 0, 1)
36
+
end
22
37
end
23
38
24
39
40
+
-- Hide radar & HUD, set cloud opacity, and use a hacky way of removing third party resource HUD elements.
25
41
functionClearScreen()
26
42
SetCloudHatOpacity(cloudOpacity)
27
43
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)
29
47
end
30
48
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!
32
51
InitialSetup()
33
52
53
+
34
54
Citizen.CreateThread(function()
55
+
56
+
-- In case it was called too early before, call it again just in case.
35
57
InitialSetup()
36
58
37
-
localtimer=GetGameTimer()
38
-
39
-
-- Wait
40
-
whiletruedo
41
-
ClearScreen()
59
+
-- Wait for the switch cam to be in the sky in the 'waiting' state (5).
60
+
whileGetPlayerSwitchState() ~=5do
42
61
Citizen.Wait(0)
43
-
ifGetGameTimer() -timer>5000then
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()
54
63
end
55
64
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
+
56
75
ClearScreen()
76
+
Citizen.Wait(0)
77
+
ClearScreen()
78
+
DoScreenFadeIn(500)
79
+
whilenotIsScreenFadedIn() do
80
+
Citizen.Wait(0)
81
+
ClearScreen()
82
+
end
83
+
84
+
localtimer=GetGameTimer()
85
+
86
+
-- Re-enable the sound in case it was muted.
87
+
ToggleSound(false)
57
88
58
89
whiletruedo
59
90
ClearScreen()
60
91
Citizen.Wait(0)
61
-
ifGetGameTimer() -timer>3000then
62
-
-- zoom in
92
+
93
+
-- wait 5 seconds before starting the switch to the player
94
+
ifGetGameTimer() -timer>5000then
95
+
96
+
-- Switch to the player.
63
97
SwitchInPlayer(PlayerPedId())
64
-
whileGetGameTimer() -timer<8500do
65
-
-- keep hud invisible while transitioning
66
-
ClearScreen()
98
+
99
+
ClearScreen()
100
+
101
+
-- Wait for the player switch to be completed (state 12).
102
+
whileGetPlayerSwitchState() ~=12do
67
103
Citizen.Wait(0)
104
+
ClearScreen()
68
105
end
106
+
-- Stop the infinite loop.
69
107
break
70
108
end
71
109
end
110
+
111
+
-- Reset the draw origin, just in case (allowing HUD elements to re-appear correctly)
0 commit comments