# Common Issue

Most issue can fix by clamp any script with [ArenaAPI export](https://hamer.gitbook.io/hamer/scripts/arenaapi/client-side)\
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.

<pre class="language-lua"><code class="lang-lua">Citizen.CreateThread(fuunction()
    while true do
<strong>        if not exports.ArenaAPI:IsPlayerInAnyArena() then -- Don't check player dead while in lobby game
</strong>            if IsPedDeadOrDying(PlayerPedId()) then
                IsDeath = true
            end
<strong>        end
</strong>        Citizen.Wait(0)
    end
end)
</code></pre>

```lua
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.

{% stepper %}
{% step %}

### For example it's a script called [qb-ambulancejob](https://github.com/qbcore-framework/qb-ambulancejob/)

{% endstep %}

{% step %}

### Find how is dead can triggered

Most script using [isDead = true](https://github.com/qbcore-framework/qb-ambulancejob/blob/e7e9445aaba272760252b1d4bb41995035ca54c0/client/dead.lua#L17)

It is in `function OnDeath()` then find [how it trigger](https://github.com/qbcore-framework/qb-ambulancejob/blob/e7e9445aaba272760252b1d4bb41995035ca54c0/client/dead.lua#L120)
{% endstep %}

{% step %}

### Clamp trigger by using ArenaAPI

<pre class="language-lua"><code class="lang-lua"><strong>AddEventHandler('gameEventTriggered', function(event, data)
</strong>    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
<strong>            if not exports.ArenaAPI:IsPlayerInAnyArena() then
</strong>                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
<strong>            end
</strong>        end
    end
end)
</code></pre>

{% endstep %}
{% endstepper %}

Learn by look at the code patten on code highlighting.

[es\_extended/blob/master/client/modules/death.lua](https://github.com/mitlight/es_extended/blob/master/client/modules/death.lua)

<pre class="language-lua"><code class="lang-lua">Citizen.CreateThread(function()
	local isDead = false

	while true do
		Citizen.Wait(0)
		
<strong>		if not exports.ArenaAPI:IsPlayerInAnyArena() then -- Disable while in lobby game.
</strong>			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
<strong>		else
</strong><strong>			Citizen.Wait(1000)
</strong><strong>		end
</strong>	end
end)
</code></pre>

[esx\_ambulancejob/client/main.lua](https://github.com/lockdownstudio/esx_ambulancejob/blob/bc66bbf091a811aacefc687fba6dcbcedc98c899/client/main.lua#L334)

<pre class="language-lua"><code class="lang-lua">AddEventHandler('esx:onPlayerDeath', function(data)
<strong>    if not exports.ArenaAPI:IsPlayerInAnyArena() then
</strong>        OnPlayerDeath()
<strong>    end
</strong>end)
</code></pre>

## vMenu

For [vMenu](https://github.com/TomGrobbe/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)

```nginx
setr vmenu_disable_spawning_as_default_character true
```

## basic-gamemode

For game [basic-gamemode](https://github.com/citizenfx/cfx-server-data/tree/master/resources/%5Bgamemodes%5D/basic-gamemode) disable auto respawn.\
In **\[script\_name]/config/client/event.lua**

<pre class="language-lua"><code class="lang-lua">---Call on game start.
AddEventHandler("[script_name]:OnSessionStart", function()
<strong>	exports.spawnmanager:setAutoSpawn(false) -- Disable fivem auto respawn.
</strong>end)

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

## 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.

{% stepper %}
{% step %}

### For example it's a script called [ox\_inventory](https://github.com/overextended/ox_inventory)

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

[<mark style="color:red;">ox\_inventory /client.lua:537</mark>](https://github.com/overextended/ox_inventory/blob/c0abafb246ecfababc18c7f8fe04abf2fcfdfd6f/client.lua#L537)

[<mark style="color:green;">ox\_inventory /client.lua:1539</mark>](https://github.com/overextended/ox_inventory/blob/c0abafb246ecfababc18c7f8fe04abf2fcfdfd6f/client.lua#L1539)

[<mark style="color:purple;">ox\_inventory/modules/weapon /client.lua:134</mark>](https://github.com/overextended/ox_inventory/blob/c0abafb246ecfababc18c7f8fe04abf2fcfdfd6f/modules/weapon/client.lua#L134)
{% endstep %}

{% step %}

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

[<mark style="color:red;">ox\_inventory /client.lua:470</mark>](https://github.com/overextended/ox_inventory/blob/c0abafb246ecfababc18c7f8fe04abf2fcfdfd6f/client.lua#L470C1-L477C29)

<pre class="language-lua"><code class="lang-lua">---@param slot number
---@return boolean?
local function useSlot(slot, noAnim)
<strong>	if not exports.ArenaAPI:IsPlayerInAnyArena() then
</strong>		local item = PlayerData.inventory[slot]
		if not item then return end
		...
		...
<strong>	end
</strong>end
exports('useSlot', useSlot)
</code></pre>

[<mark style="color:green;">ox\_inventory /client.lua:1428</mark>](https://github.com/overextended/ox_inventory/blob/c0abafb246ecfababc18c7f8fe04abf2fcfdfd6f/client.lua#L1428)

<pre class="language-lua"><code class="lang-lua">client.tick = SetInterval(function()
<strong>	if not exports.ArenaAPI:IsPlayerInAnyArena() then
</strong>		DisablePlayerVehicleRewards(playerId)

		if invOpen then
			DisableAllControlActions(0)
		...
		...
<strong>	end
</strong>end)
</code></pre>

[<mark style="color:purple;">ox\_inventory/modules/weapon /client.lua</mark>](https://github.com/overextended/ox_inventory/blob/c0abafb246ecfababc18c7f8fe04abf2fcfdfd6f/modules/weapon/client.lua#L97)

<pre class="language-lua"><code class="lang-lua">function Weapon.Disarm(currentWeapon, noAnim)
<strong>	if not exports.ArenaAPI:IsPlayerInAnyArena() then
</strong>		if currentWeapon?.timer then
			currentWeapon.timer = nil
		...
		...
		Utils.WeaponWheel()
		RemoveAllPedWeapons(cache.ped, true)
<strong>	end
</strong>end
</code></pre>

{% endstep %}
{% endstepper %}

## 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.

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

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

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hamer.gitbook.io/hamer/scripts/arenaapi/common-issue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
