Code modernize (#234)

* refactor: declare exports at runtime and drop the player-data provides alias

Signed-off-by: Mathu-lmn <[email protected]>

* refactor: pass handlers directly to RegisterNetEvent

Signed-off-by: Mathu-lmn <[email protected]>

* refactor: use CreateThread/Wait without the Citizen prefix

Signed-off-by: Mathu-lmn <[email protected]>

* chore: remove trailing whitespace, stray lines and unused locals

Signed-off-by: Mathu-lmn <[email protected]>

---------

Signed-off-by: Mathu-lmn <[email protected]>
This commit is contained in:
Mathu-lmn
2026-09-23 21:00:01 +02:00
committed by GitHub
parent 2935a6ba1d
commit 39b91b14ce
23 changed files with 64 additions and 137 deletions
+4 -16
View File
@@ -6,25 +6,13 @@ author 'Cfx.re <[email protected]>'
description 'A flexible handler for game type/map association.'
repository 'https://github.com/citizenfx/cfx-server-data'
client_scripts {
"mapmanager_shared.lua",
"mapmanager_client.lua"
}
client_script 'mapmanager_client.lua'
server_scripts {
"mapmanager_shared.lua",
"mapmanager_server.lua"
}
server_script 'mapmanager_server.lua'
shared_script 'mapmanager_shared.lua'
fx_version 'cerulean'
games { 'gta5', 'rdr3' }
server_export "getCurrentGameType"
server_export "getCurrentMap"
server_export "changeGameType"
server_export "changeMap"
server_export "doesMapSupportGameType"
server_export "getMaps"
server_export "roundEnded"
rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aware my resources *will* become incompatible once RedM ships.'
@@ -40,8 +40,8 @@ AddEventHandler('onClientResourceStart', function(res)
loadMap(res)
-- defer this to the next game tick to work around a lack of dependencies
Citizen.CreateThread(function()
Citizen.Wait(15)
CreateThread(function()
Wait(15)
if maps[res] then
TriggerEvent('onClientMapStart', res)
@@ -12,14 +12,14 @@ local function refreshResources()
if GetNumResourceMetadata(resource, 'resource_type') > 0 then
local type = GetResourceMetadata(resource, 'resource_type', 0)
local params = json.decode(GetResourceMetadata(resource, 'resource_type_extra', 0))
local valid = false
local games = GetNumResourceMetadata(resource, 'game')
if games > 0 then
for j = 0, games - 1 do
local game = GetResourceMetadata(resource, 'game', j)
if game == GetConvar('gamename', 'gta5') or game == 'common' then
valid = true
end
@@ -313,3 +313,11 @@ function doesMapSupportGameType(gameType, map)
return maps[map].gameTypes[gameType]
end
exports('getCurrentGameType', getCurrentGameType)
exports('getCurrentMap', getCurrentMap)
exports('changeGameType', changeGameType)
exports('changeMap', changeMap)
exports('doesMapSupportGameType', doesMapSupportGameType)
exports('getMaps', getMaps)
exports('roundEnded', roundEnded)
@@ -74,7 +74,7 @@ function parseMap(file, owningResource)
}
setmetatable(env, mt)
local fileData = LoadResourceFile(owningResource, file)
local mapFunction, err = load(fileData, file, 't', env)
@@ -185,9 +185,7 @@ local function freezePlayer(id, freeze)
end
function loadScene(x, y, z)
if not NewLoadSceneStart then
return
end
if not NewLoadSceneStart then return end
NewLoadSceneStart(x, y, z, 0.0, 0.0, 0.0, 20.0, 0)
@@ -199,13 +197,11 @@ local spawnLock = false
-- spawns the current player at a certain spawn point index (or a random one, for that matter)
function spawnPlayer(spawnIdx, cb)
if spawnLock then
return
end
if spawnLock then return end
spawnLock = true
Citizen.CreateThread(function()
CreateThread(function()
-- if the spawn isn't set, select a random one
if not spawnIdx then
spawnIdx = GetRandomIntInRange(1, #spawnPoints + 1)
@@ -231,7 +227,7 @@ function spawnPlayer(spawnIdx, cb)
DoScreenFadeOut(500)
while not IsScreenFadedOut() do
Citizen.Wait(0)
Wait(0)
end
end
@@ -302,7 +298,7 @@ function spawnPlayer(spawnIdx, cb)
local time = GetGameTimer()
while (not HasCollisionLoadedAroundEntity(ped) and (GetGameTimer() - time) < 5000) do
Citizen.Wait(0)
Wait(0)
end
ShutdownLoadingScreen()
@@ -311,7 +307,7 @@ function spawnPlayer(spawnIdx, cb)
DoScreenFadeIn(500)
while not IsScreenFadedIn() do
Citizen.Wait(0)
Wait(0)
end
end
@@ -332,10 +328,10 @@ end
local respawnForced
local diedAt
Citizen.CreateThread(function()
CreateThread(function()
-- main loop thing
while true do
Citizen.Wait(50)
Wait(50)
local playerPed = PlayerPedId()