Skip to content

Commit

Permalink
Merge pull request #772 from Gravxd/master
Browse files Browse the repository at this point in the history
feat(client/admin_client) add ability to disable player shooting if frozen
  • Loading branch information
Blumlaut authored Aug 10, 2023
2 parents b1fd689 + c008480 commit 141a824
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
67 changes: 49 additions & 18 deletions client/admin_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ MessageShortcuts = {}
FrozenPlayers = {}
MutedPlayers = {}

local cachedInfo = {
ped = PlayerPedId(),
veh = 0,
player = PlayerId(),
}

local vehicleInfo = {
netId = nil,
seat = nil,
Expand Down Expand Up @@ -126,20 +132,37 @@ RegisterNetEvent('EasyAdmin:SetPlayerMuted', function(player,state)
end
end)

Citizen.CreateThread( function()
while true do
Citizen.Wait(0)
if frozen then
local localPlayerPedId = PlayerPedId()
FreezeEntityPosition(localPlayerPedId, frozen)
if IsPedInAnyVehicle(localPlayerPedId, true) then
FreezeEntityPosition(GetVehiclePedIsIn(localPlayerPedId, false), frozen)
end
else
Citizen.Wait(200)
function freezeMe()

Citizen.CreateThread(function()

local disableShootingWhileFrozen = GetConvar("ea_disableShootingWhileFrozen", 'false')

while frozen do

FreezeEntityPosition(cachedInfo.ped, frozen)
if cachedInfo.veh ~= 0 then
FreezeEntityPosition(cachedInfo.veh, frozen)
end
if disableShootingWhileFrozen == 'true' then
DisablePlayerFiring(cachedInfo.player, true)
end

Wait(0)

end

end)

end

function unFreezeMe()
local localPlayerPedId = PlayerPedId()
FreezeEntityPosition(localPlayerPedId, false)
if IsPedInAnyVehicle(localPlayerPedId, true) then
FreezeEntityPosition(GetVehiclePedIsIn(localPlayerPedId, false), false)
end
end)
end

RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, tgtCoords)
local localPlayerPed = PlayerPedId()
Expand All @@ -166,6 +189,7 @@ RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, tgtCoords
end
spectatePlayer(localPlayerPed,GetPlayerFromServerId(PlayerId()),GetPlayerName(PlayerId()))
frozen = false
unFreezeMe()
return
else
if not oldCoords then
Expand All @@ -174,6 +198,7 @@ RegisterNetEvent("EasyAdmin:requestSpectate", function(playerServerId, tgtCoords
end
SetEntityCoords(localPlayerPed, tgtCoords.x, tgtCoords.y, tgtCoords.z - 10.0, 0, 0, 0, false)
frozen = true
freezeMe()
stopSpectateUpdate = true
local adminPed = localPlayerPed
local playerId = GetPlayerFromServerId(playerServerId)
Expand Down Expand Up @@ -252,8 +277,8 @@ end)
Citizen.CreateThread( function()
while true do
Citizen.Wait(500)
local localPlayerPed = PlayerPedId()
if drawInfo and not stopSpectateUpdate then
local localPlayerPed = PlayerPedId()
local targetPed = GetPlayerPed(drawTarget)
local targetGod = GetPlayerInvincible(drawTarget)

Expand All @@ -264,6 +289,11 @@ Citizen.CreateThread( function()
else
Citizen.Wait(1000)
end
cachedInfo = {
ped = localPlayerPed,
veh = GetVehiclePedIsIn(localPlayerPed, false),
player = PlayerId(),
}
end
end)

Expand Down Expand Up @@ -328,11 +358,11 @@ end, false)

RegisterNetEvent("EasyAdmin:FreezePlayer", function(toggle)
frozen = toggle
local playerPed = PlayerPedId()
FreezeEntityPosition(playerPed, frozen)
if IsPedInAnyVehicle(playerPed, false) then
FreezeEntityPosition(GetVehiclePedIsIn(playerPed, false), frozen)
end
if frozen then
freezeMe()
else
unFreezeMe()
end
end)


Expand Down Expand Up @@ -376,6 +406,7 @@ function spectatePlayer(targetPed,target,name)
StopDrawPlayerInfo()
TriggerEvent("EasyAdmin:showNotification", GetLocalisedText("stoppedSpectating"))
frozen = false
unFreezeMe()
Citizen.Wait(200) -- to prevent staying invisible
SetEntityVisible(playerPed, true, 0)
SetEntityCollision(playerPed, true, true)
Expand Down
3 changes: 2 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ convar_category 'EasyAdmin' {
{ "Token for Discord bot", "$ea_botToken", "CV_STRING", "none" },
{ "Channel for Discord bot to log", "$ea_botLogChannel", "CV_STRING", "none" },
{ "Channel for Discord bot to enable live status", "$ea_botStatusChannel", "CV_STRING", "true" },
{ "Enable Allowlist", "$ea_enableAllowlist", "CV_BOOL", "false" }
{ "Enable Allowlist", "$ea_enableAllowlist", "CV_BOOL", "false" },
{ "Disable Shooting Whilst Frozen", "$ea_disableShootingWhileFrozen", "CV_BOOL", "false" },
}
}

0 comments on commit 141a824

Please sign in to comment.