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

Commit

Permalink
many improvements
Browse files Browse the repository at this point in the history
Changed almost everything after a couple of hours researching the switch natives. Findings will be published on the fivem natives reference page later.
  • Loading branch information
TomGrobbe committed Oct 18, 2018
1 parent afec3f8 commit c6b0c34
Showing 1 changed file with 67 additions and 28 deletions.
95 changes: 67 additions & 28 deletions cloading.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
-- Copyright © Vespura 2018
-- Edit it if you want, but don't re-release this without my permission, and never claim it to be yours!

local cloudOpacity = 0.01
local muteSound = true

------- 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");
Expand All @@ -14,61 +24,90 @@ function ToggleSound(state)
end
end

-- Runs the initial setup whenever the script is loaded.
function InitialSetup()
-- sometimes this works, but not always.
-- Stopping the loading screen from automatically being dismissed.
SetManualShutdownLoadingScreenNui(true)
-- Disable sound (if configured)
ToggleSound(muteSound)
SwitchOutPlayer(PlayerPedId(), 0, 1)
-- 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()
SetDrawOrigin(0.0, 0.0, 0.0, 0) -- nice hack to 'hide' hud elements from other resources/scripts. kinda buggy though.

-- nice hack to 'hide' HUD elements from other resources/scripts. kinda buggy though.
SetDrawOrigin(0.0, 0.0, 0.0, 0)
end

-- 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.
-- 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()

local timer = GetGameTimer()

-- Wait
while true do
ClearScreen()
-- Wait for the switch cam to be in the sky in the 'waiting' state (5).
while GetPlayerSwitchState() ~= 5 do
Citizen.Wait(0)
if GetGameTimer() - timer > 5000 then
-- somewhat smooth transition
DoScreenFadeOut(100)
Citizen.Wait(100)
ShutdownLoadingScreenNui()
Citizen.Wait(500)
DoScreenFadeIn(1000)
timer = GetGameTimer()
ToggleSound(false)
break
end
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)
if GetGameTimer() - timer > 3000 then
-- zoom in

-- wait 5 seconds before starting the switch to the player
if GetGameTimer() - timer > 5000 then

-- Switch to the player.
SwitchInPlayer(PlayerPedId())
while GetGameTimer() - timer < 8500 do
-- keep hud invisible while transitioning
ClearScreen()

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)

0 comments on commit c6b0c34

Please sign in to comment.