[HELP] How To Detect Player Who Left The Battle

Hi guys

in first sorry for my bad English

guys , i have a warzone script for fivem , everything is ok , like enter battle , exit battle , counting and … you know everything is ok BUT

if player want to disconnect the server OR Close the game (ALT+F4) The source CANT detect that player is not in the battle and wont count as a EXITED player , still count as a live player in battle

SO , in client , i have a OnResourseStop

AddEventHandler("onResourceStop", function(resource)
    if resource == GetCurrentResourceName() then
		for k, v in pairs(itemObj) do
			ESX.Game.DeleteObject(v)
		end
        
        TriggerServerEvent('pmc-battleroyale:leave:game', source)
        TriggerEvent('DiscordBot:ToDiscord', 'warzone',	   'WarZone' , "```css\n" .. GetPlayerName(PlayerPedId()) .. " ALT+F4\n```",'user', source, true, false)
        SetEntityAsMissionEntity(pilot, false, true)
        DeleteEntity(pilot)
        SetEntityAsMissionEntity(aircraft, false, true)
        DeleteEntity(aircraft)
        DeleteEntity(parachute)
        DeleteEntity(crate)
        RemovePickup(pickup)
        RemoveBlip(blip)
        StopSound(soundID)
        ReleaseSoundId(soundID)

        for i = 1, #requiredModels do
            Wait(0)
            SetModelAsNoLongerNeeded(GetHashKey(requiredModels[i]))
        end

    end
end)

I think that is saying , if anyway player left the battle , SOURCE get STOP for him
but nothing happend !!!

PLEASE HELP ME , TNX

onResourceStop == if the resource is getting stopped. That doesn’t make sence.

Otherwise you can check if player is not in zone anymore, that he is getting stored into the db with “combatlogged” = 1 then use the AddEventHandler server side playerConnecting and check if the players table is combatlogged = 1, if yes, then let him connect, after that, wait until the session is loaded / started for him, after that place a message and teleport him out or give him a warning.

This is purely theoretically but does make sence.

1 Like

Dear
Thanks for Reply
Can you Please give me code ? u know iam not very professional on LUA
Can you please tell me exactly what i must to do ?! (GIVE ME CODE)

Thanks Bro

EDIT:
Dear i Just need a code what make (IF PLAYER LEFT OR CLOSE FIVEM ,AUTOMATIC REMOVE FROM BATTLE AND COUNT -1)

i dont want if player close the fivem and re connect to server , can play the battle
just want to remove from battle IF player CLOSE THE FIVEM , or DISSCONNECT

I’ll not write you the code for that. You haven’t even tried it.

1 Like

OK
you tell me to how to bring the player back into battle

I DONT WANT THE PLAYER GET BACK IN BATTLE IF CLOSED OR DISSCONNECTED

i want when player disconnect or close fivem , automatic count down from battle

AddEventHandler('playerDropped', function()
    local src = source
end)

Is the code you’re looking for, use this on server-sided scripts.

1 Like

tnx for replay

something like this ?!

RegisterNetEvent('playerDropped')
AddEventHandler('playerDropped', function()
    local src = tonumber(source)
	if gameIndex ~= nil and tonumber(gameIndex) ~= nil and gameIndex > 0 and not Battleroyale:LeavePlayer(source, gameIndex, died)  then
		TriggerEvent('DiscordBot:ToDiscord', 'warzone',	   'WarZone' , "```css\n" .. GetPlayerName(source) .. " ALT+F4\n```",'user', source, true, false)
	end
end)

EDIT

OR THIS ?!

RegisterNetEvent('pmc-battleroyale:playerDropped')
AddEventHandler('pmc-battleroyale:playerDropped', function()
	local source = tonumber(source)
		DropPlayer(source, 'DC')
		RemoveAllPedWeapons(PlayerPedId())
		RemoveAllPickups()
		TriggerEvent('DiscordBot:ToDiscord', 'warzone',	   'WarZone' , "```css\n" .. GetPlayerName(source) .. " ALT+F4\n```",'user', source, true, false)
end)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.