To fix common issue by respawning, weapon loadout, etc.
Last updated
Most issue can fix by clamp any script with
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
2
Find how is dead can triggered
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.
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)
AddEventHandler('esx:onPlayerDeath', function(data)
if not exports.ArenaAPI:IsPlayerInAnyArena() then
OnPlayerDeath()
end
end)
---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
Search for all files find something like RemoveWeaponFromPed or RemoveAllPedWeapons that is how the script can remove your weapon.
2
Scroll up and find block of code and clamp it by ArenaAPI
---@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
client.tick = SetInterval(function()
if not exports.ArenaAPI:IsPlayerInAnyArena() then
DisablePlayerVehicleRewards(playerId)
if invOpen then
DisableAllControlActions(0)
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)
For example it's a script called
Most script using
It is in function OnDeath() then find
For 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)
For game disable auto respawn.
In [script_name]/config/client/event.lua