From cf39f7c7d76242958ff88b255758d172df1681d9 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sun, 8 Sep 2019 13:22:09 +0200 Subject: [PATCH] Fixed invisable bug once and for all, closes #13 --- client/main.lua | 18 +++++++++++------- server/main.lua | 6 ++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/client/main.lua b/client/main.lua index 189d77d6..c8336ea8 100644 --- a/client/main.lua +++ b/client/main.lua @@ -176,16 +176,16 @@ Citizen.CreateThread(function() if instance.host then -- Get players and sets them as pairs for k,v in ipairs(GetActivePlayers()) do - playersToHide[v] = true + playersToHide[GetPlayerServerId(v)] = true end -- Dont set our instanced players invisible for _,player in ipairs(instance.players) do - playersToHide[GetPlayerFromServerId(player)] = nil + playersToHide[player] = nil end else for player,_ in pairs(instancedPlayers) do - playersToHide[GetPlayerFromServerId(player)] = true + playersToHide[player] = true end end end @@ -197,10 +197,14 @@ Citizen.CreateThread(function() local playerPed = PlayerPedId() -- Hide all these players - for player,_ in pairs(playersToHide) do - local otherPlayerPed = GetPlayerPed(player) - SetEntityVisible(otherPlayerPed, false, false) - SetEntityNoCollisionEntity(playerPed, otherPlayerPed, false) + for serverId,_ in pairs(playersToHide) do + local player = GetPlayerFromServerId(serverId) + + if NetworkIsPlayerActive(player) then + local otherPlayerPed = GetPlayerPed(player) + SetEntityVisible(otherPlayerPed, false, false) + SetEntityNoCollisionEntity(playerPed, otherPlayerPed, false) + end end end end) diff --git a/server/main.lua b/server/main.lua index b7fcf132..3f51be44 100644 --- a/server/main.lua +++ b/server/main.lua @@ -12,6 +12,12 @@ function GetInstancedPlayers() return players end +AddEventHandler('playerDropped', function(reason) + if instances[source] then + CloseInstance(source) + end +end) + function CreateInstance(type, player, data) instances[player] = { type = type,