Common Issue

To fix common issue by respawning, weapon loadout, etc.

Most issue can fix by clamp any script with ArenaAPI export This example try to clamp custom roleplay revive script by add ArenaAPI:IsPlayerInAnyArena() And also work with custom HUD like block weapon hotbar or speedo.

Citizen.CreateThread(fuunction()
    while true do
        if not exports.ArenaAPI:IsPlayerInAnyArena() then -- Don't check player dead while in lobby game
            if IsPedDeadOrDying(PlayerPedId()) then
                IsDeath = true
            end
        end
        Citizen.Wait(0)
    end
end)
Citizen.CreateThread(fuunction()
    while true do
        if not exports.ArenaAPI:IsPlayerInAnyArena() then -- Don't toggle speedo  while in lobby game
            if IsPedInAnyVehicle(PlayerPedId(), false)
                ShowSpeedo()
            else
                HideSpeedo()
            end
        end
        Citizen.Wait(0)
    end
end)

Custom Death Script

When your custom death script triggered it can block your client input or play screen effect that can make lobby game unplayable.

1

For example it's a script called qb-ambulancejob

2

Find how is dead can triggered

Most script using isDead = true

It is in function OnDeath() then find how it trigger

3

Clamp trigger by using ArenaAPI

AddEventHandler('gameEventTriggered', function(event, data)
    if event == 'CEventNetworkEntityDamage' then
        local victim, attacker, victimDied, weapon = data[1], data[2], data[4], data[7]
        if not IsEntityAPed(victim) then return end
        if victimDied and NetworkGetPlayerIndexFromPed(victim) == PlayerId() and IsEntityDead(PlayerPedId()) then
            if not exports.ArenaAPI:IsPlayerInAnyArena() then
                if not InLaststand then
                    SetLaststand(true)
                elseif InLaststand and not isDead then
                    SetLaststand(false)
                    local playerid = NetworkGetPlayerIndexFromPed(victim)
                    local playerName = GetPlayerName(playerid)..' '..'('..GetPlayerServerId(playerid)..')' or Lang:t('info.self_death')
                    local killerId = NetworkGetPlayerIndexFromPed(attacker)
                    local killerName = GetPlayerName(killerId)..' '..'('..GetPlayerServerId(killerId)..')' or Lang:t('info.self_death')
                    local weaponLabel = (QBCore.Shared.Weapons and QBCore.Shared.Weapons[weapon] and QBCore.Shared.Weapons[weapon].label) or 'Unknown'
                    local weaponName = (QBCore.Shared.Weapons and QBCore.Shared.Weapons[weapon] and QBCore.Shared.Weapons[weapon].name) or 'Unknown'
                    TriggerServerEvent('qb-log:server:CreateLog', 'death', Lang:t('logs.death_log_title', {playername = playerName, playerid = GetPlayerServerId(playerid)}), 'red', Lang:t('logs.death_log_message', {killername = killerName, playername = playerName, weaponlabel = weaponLabel, weaponname = weaponName}))
                    deathTime = Config.DeathTime
                    OnDeath()
                    DeathTimer()
                end
            end
        end
    end
end)

Learn by look at the code patten on code highlighting.

es_extended/blob/master/client/modules/death.lua

Citizen.CreateThread(function()
	local isDead = false

	while true do
		Citizen.Wait(0)
		
		if not exports.ArenaAPI:IsPlayerInAnyArena() then -- Disable while in lobby game.
			local player = PlayerId()

			if NetworkIsPlayerActive(player) then
				local playerPed = PlayerPedId()

				if IsPedFatallyInjured(playerPed) and not isDead then
					isDead = true

					local killer, killerWeapon = NetworkGetEntityKillerOfPlayer(player)
					local killerServerId = NetworkGetPlayerIndexFromPed(killer)
			
					if killer ~= playerPed and killerServerId ~= nil and NetworkIsPlayerActive(killerServerId) then
						PlayerKilledByPlayer(GetPlayerServerId(killerServerId), killerServerId, >killerWeapon)
					else
						PlayerKilled()
					end

				elseif not IsPedFatallyInjured(playerPed) then
					isDead = false
				end
			end
		else
			Citizen.Wait(1000)
		end
	end
end)

esx_ambulancejob/client/main.lua

AddEventHandler('esx:onPlayerDeath', function(data)
    if not exports.ArenaAPI:IsPlayerInAnyArena() then
        OnPlayerDeath()
    end
end)

vMenu

For vMenu you need to make Respawn As Default MP Character to disable by default. Because it make you respawn out side vehicle. Set server command. (vMenu/config/permissions.cfg)

setr vmenu_disable_spawning_as_default_character true

basic-gamemode

For game basic-gamemode disable auto respawn. In [script_name]/config/client/event.lua

---Call on game start.
AddEventHandler("[script_name]:OnSessionStart", function()
	exports.spawnmanager:setAutoSpawn(false) -- Disable fivem auto respawn.
end)

---Call on game end
AddEventHandler("[script_name]:OnSessionEnd", function()
	exports.spawnmanager:setAutoSpawn(true) -- Enable fivem auto respawn.
end)

Custom Weapon Loadout

Some of roleplay base script has a custom weapon loadout that can make in lobby weapon disappear. You need to find how that script remove your weapon from game lobby.

1

For example it's a script called ox_inventory

Search for all files find something like RemoveWeaponFromPed or RemoveAllPedWeapons that is how the script can remove your weapon.

ox_inventory /client.lua:537

ox_inventory /client.lua:1539

ox_inventory/modules/weapon /client.lua:134

2

Scroll up and find block of code and clamp it by ArenaAPI

ox_inventory /client.lua:470

---@param slot number
---@return boolean?
local function useSlot(slot, noAnim)
	if not exports.ArenaAPI:IsPlayerInAnyArena() then
		local item = PlayerData.inventory[slot]
		if not item then return end

ox_inventory /client.lua:1428

client.tick = SetInterval(function()
	if not exports.ArenaAPI:IsPlayerInAnyArena() then
		DisablePlayerVehicleRewards(playerId)

		if invOpen then
			DisableAllControlActions(0)

ox_inventory/modules/weapon /client.lua

function Weapon.Disarm(currentWeapon, noAnim)
	if not exports.ArenaAPI:IsPlayerInAnyArena() then
		if currentWeapon?.timer then
			currentWeapon.timer = nil

Custom HUD

In [script_name]/config/client/event.lua you can put this event to any your scripts to do some thing when lobby started and ended like hide roleplay HUD.

-- Call on game start
AddEventHandler("[script_name]:OnSessionStart", function()
	HideSpeedoHUD()
end)

-- Call on game end
AddEventHandler("[script_name]:OnSessionEnd", function()
	ShowSpeedoHUD()
end)

Last updated