Fixed handcuff once and for all, implemented handcuff timer, closes #120 , closes #118

- You can no longer escape the handcuffs, e.g pan and tilt is also disabled now.
This commit is contained in:
ElPumpo
2018-07-12 16:20:09 +02:00
parent bbb7d6e00b
commit 9594e4751f
11 changed files with 157 additions and 83 deletions
+2 -2
View File
@@ -1,8 +1,8 @@
root = true
[*]
indent_size = 2
indent_style = space
indent_size = 4
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
+141 -81
View File
@@ -10,26 +10,25 @@ local Keys = {
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}
local PlayerData = {}
local GUI = {}
local HasAlreadyEnteredMarker = false
local LastStation = nil
local LastPart = nil
local LastPartNum = nil
local LastEntity = nil
local CurrentAction = nil
local CurrentActionMsg = ''
local CurrentActionData = {}
local IsHandcuffed = false
local IsDragged = false
local CopPed = 0
local hasAlreadyJoined = false
local blipsCops = {}
local isDead = false
CurrentTask = {}
local PlayerData = {}
local HasAlreadyEnteredMarker = false
local LastStation = nil
local LastPart = nil
local LastPartNum = nil
local LastEntity = nil
local CurrentAction = nil
local CurrentActionMsg = ''
local CurrentActionData = {}
local IsHandcuffed = false
local HandcuffTimer = nil
local IsDragged = false
local CopPed = 0
local hasAlreadyJoined = false
local blipsCops = {}
local isDead = false
local CurrentTask = {}
ESX = nil
GUI.Time = 0
ESX = nil
Citizen.CreateThread(function()
while ESX == nil do
@@ -89,7 +88,7 @@ end
function OpenCloakroomMenu()
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local elements = {
{ label = _U('citizen_wear'), value = 'citizen_wear' },
@@ -317,7 +316,7 @@ function OpenVehicleSpawnerMenu(station, partNum)
ESX.Game.SpawnVehicle(vehicleProps.model, vehicles[partNum].SpawnPoint, 270.0, function(vehicle)
ESX.Game.SetVehicleProperties(vehicle, vehicleProps)
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
end)
@@ -368,7 +367,7 @@ function OpenVehicleSpawnerMenu(station, partNum)
if not DoesEntityExist(vehicle) then
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
if Config.MaxInService == -1 then
@@ -491,7 +490,7 @@ function OpenPoliceActionsMenu()
end)
elseif data.current.value == 'vehicle_interaction' then
local elements = {}
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local vehicle = ESX.Game.GetVehicleInDirection()
@@ -591,7 +590,7 @@ function OpenPoliceActionsMenu()
}
}, function(data2, menu2)
local model = data2.current.value
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local forward = GetEntityForwardVector(playerPed)
local x, y, z = table.unpack(coords + forward * 1.0)
@@ -1051,7 +1050,7 @@ end
function OpenPutWeaponMenu()
local elements = {}
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local weaponList = ESX.GetWeaponList()
for i=1, #weaponList, 1 do
@@ -1320,7 +1319,7 @@ AddEventHandler('esx_policejob:hasEnteredMarker', function(station, part, partNu
if part == 'VehicleDeleter' then
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
if IsPedInAnyVehicle(playerPed, false) then
@@ -1352,7 +1351,7 @@ end)
AddEventHandler('esx_policejob:hasEnteredEntityZone', function(entity)
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
if PlayerData.job ~= nil and PlayerData.job.name == 'police' and not IsPedInAnyVehicle(playerPed, false) then
CurrentAction = 'remove_entity'
@@ -1362,7 +1361,7 @@ AddEventHandler('esx_policejob:hasEnteredEntityZone', function(entity)
if GetEntityModel(entity) == GetHashKey('p_ld_stinger_s') then
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
if IsPedInAnyVehicle(playerPed, false) then
@@ -1389,67 +1388,93 @@ end)
RegisterNetEvent('esx_policejob:handcuff')
AddEventHandler('esx_policejob:handcuff', function()
IsHandcuffed = not IsHandcuffed
local playerPed = PlayerPedId()
IsHandcuffed = not IsHandcuffed;
local playerPed = GetPlayerPed(-1)
Citizen.CreateThread(function()
if IsHandcuffed then
Citizen.CreateThread(function()
RequestAnimDict('mp_arresting')
while not HasAnimDictLoaded('mp_arresting') do
Citizen.Wait(100)
end
if IsHandcuffed then
TaskPlayAnim(playerPed, 'mp_arresting', 'idle', 8.0, -8, -1, 49, 0, 0, 0, 0)
RequestAnimDict('mp_arresting')
SetEnableHandcuffs(playerPed, true)
DisablePlayerFiring(playerPed, true)
SetCurrentPedWeapon(playerPed, GetHashKey('WEAPON_UNARMED'), true) -- unarm player
SetPedCanPlayGestureAnims(playerPed, false)
FreezeEntityPosition(playerPed, true)
while not HasAnimDictLoaded('mp_arresting') do
Wait(100)
end
if Config.EnableHandcuffTimer then
if HandcuffTimer then
ESX.ClearTimeout(HandcuffTimer)
end
TaskPlayAnim(playerPed, 'mp_arresting', 'idle', 8.0, -8, -1, 49, 0, 0, 0, 0)
SetEnableHandcuffs(playerPed, true)
SetPedCanPlayGestureAnims(playerPed, false)
FreezeEntityPosition(playerPed, true)
StartHandcuffTimer()
end
else
else
ClearPedSecondaryTask(playerPed)
SetEnableHandcuffs(playerPed, false)
SetPedCanPlayGestureAnims(playerPed, true)
FreezeEntityPosition(playerPed, false)
if Config.EnableHandcuffTimer and HandcuffTimer then
ESX.ClearTimeout(HandcuffTimer)
end
ClearPedSecondaryTask(playerPed)
SetEnableHandcuffs(playerPed, false)
DisablePlayerFiring(playerPed, false)
SetPedCanPlayGestureAnims(playerPed, true)
FreezeEntityPosition(playerPed, false)
end
end)
end
end)
end)
AddEventHandler('esx_policejob:unrestrain', function()
if IsHandcuffed then
local playerPed = PlayerPedId()
IsHandcuffed = false
ClearPedSecondaryTask(playerPed)
SetEnableHandcuffs(playerPed, false)
DisablePlayerFiring(playerPed, false)
SetPedCanPlayGestureAnims(playerPed, true)
FreezeEntityPosition(playerPed, false)
end
end)
RegisterNetEvent('esx_policejob:drag')
AddEventHandler('esx_policejob:drag', function(cop)
IsDragged = not IsDragged
CopPed = tonumber(cop)
IsDragged = not IsDragged
CopPed = tonumber(cop)
end)
Citizen.CreateThread(function()
while true do
Wait(0)
if IsHandcuffed then
if IsDragged then
local ped = GetPlayerPed(GetPlayerFromServerId(CopPed))
local myped = GetPlayerPed(-1)
AttachEntityToEntity(myped, ped, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
else
DetachEntity(GetPlayerPed(-1), true, false)
end
end
end
while true do
Citizen.Wait(1)
if IsHandcuffed then
if IsDragged then
local ped = GetPlayerPed(GetPlayerFromServerId(CopPed))
local myped = PlayerPedId()
AttachEntityToEntity(myped, ped, 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true)
else
DetachEntity(PlayerPedId(), true, false)
end
else
Citizen.Wait(500)
end
end
end)
RegisterNetEvent('esx_policejob:putInVehicle')
AddEventHandler('esx_policejob:putInVehicle', function()
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
if IsAnyVehicleNearPoint(coords.x, coords.y, coords.z, 5.0) then
local vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71)
local vehicle = GetClosestVehicle(coords.x, coords.y, coords.z, 5.0, 0, 71)
if DoesEntityExist(vehicle) then
@@ -1457,14 +1482,14 @@ AddEventHandler('esx_policejob:putInVehicle', function()
local freeSeat = nil
for i=maxSeats - 1, 0, -1 do
if IsVehicleSeatFree(vehicle, i) then
if IsVehicleSeatFree(vehicle, i) then
freeSeat = i
break
end
end
if freeSeat ~= nil then
TaskWarpPedIntoVehicle(playerPed, vehicle, freeSeat)
TaskWarpPedIntoVehicle(playerPed, vehicle, freeSeat)
end
end
@@ -1477,18 +1502,21 @@ RegisterNetEvent('esx_policejob:OutVehicle')
AddEventHandler('esx_policejob:OutVehicle', function(t)
local ped = GetPlayerPed(t)
ClearPedTasksImmediately(ped)
plyPos = GetEntityCoords(GetPlayerPed(-1), true)
plyPos = GetEntityCoords(PlayerPedId(), true)
local xnew = plyPos.x+2
local ynew = plyPos.y+2
SetEntityCoords(GetPlayerPed(-1), xnew, ynew, plyPos.z)
SetEntityCoords(PlayerPedId(), xnew, ynew, plyPos.z)
end)
-- Handcuff
Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
Citizen.Wait(1)
if IsHandcuffed then
DisplayRadar(false)
DisableControlAction(2, 1, true) -- Disable pan
DisableControlAction(2, 2, true) -- Disable tilt
DisableControlAction(2, 24, true) -- Attack
DisableControlAction(2, 257, true) -- Attack 2
DisableControlAction(2, 25, true) -- Aim
@@ -1502,8 +1530,21 @@ Citizen.CreateThread(function()
DisableControlAction(2, Keys['F1'], true) -- Disable phone
DisableControlAction(2, Keys['F2'], true) -- Inventory
DisableControlAction(2, Keys['F3'], true) -- Animations
DisableControlAction(2, Keys['V'], true) -- Disable changing view
DisableControlAction(2, Keys['P'], true) -- Disable pause screen
DisableControlAction(2, 59, true) -- Disable steering in vehicle
DisableControlAction(2, Keys['LEFTCTRL'], true) -- Disable going stealth
DisableControlAction(0, 47, true) -- Disable weapon
DisableControlAction(0, 264, true) -- Disable melee
DisableControlAction(0, 257, true) -- Disable melee
DisableControlAction(0, 140, true) -- Disable melee
DisableControlAction(0, 141, true) -- Disable melee
DisableControlAction(0, 142, true) -- Disable melee
DisableControlAction(0, 143, true) -- Disable melee
DisableControlAction(0, 75, true) -- Disable exit vehicle
DisableControlAction(27, 75, true) -- Disable exit vehicle
else
Citizen.Wait(1000)
Citizen.Wait(500)
end
end
end)
@@ -1537,7 +1578,7 @@ Citizen.CreateThread(function()
if PlayerData.job ~= nil and PlayerData.job.name == 'police' then
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
for k,v in pairs(Config.PoliceStations) do
@@ -1592,7 +1633,7 @@ Citizen.CreateThread(function()
if PlayerData.job ~= nil and PlayerData.job.name == 'police' then
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local isInMarker = false
local currentStation = nil
@@ -1726,7 +1767,7 @@ Citizen.CreateThread(function()
Citizen.Wait(0)
local playerPed = GetPlayerPed(-1)
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local closestDistance = -1
@@ -1780,7 +1821,7 @@ Citizen.CreateThread(function()
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlPressed(0, Keys['E']) and PlayerData.job ~= nil and PlayerData.job.name == 'police' and (GetGameTimer() - GUI.Time) > 150 then
if IsControlJustReleased(0, Keys['E']) and PlayerData.job ~= nil and PlayerData.job.name == 'police' then
if CurrentAction == 'menu_cloakroom' then
OpenCloakroomMenu()
@@ -1817,19 +1858,17 @@ Citizen.CreateThread(function()
end
CurrentAction = nil
GUI.Time = GetGameTimer()
end
end -- CurrentAction end
if IsControlPressed(0, Keys['F6']) and not isDead and PlayerData.job ~= nil and PlayerData.job.name == 'police' and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'police_actions') and (GetGameTimer() - GUI.Time) > 150 then
if IsControlJustReleased(0, Keys['F6']) and not isDead and PlayerData.job ~= nil and PlayerData.job.name == 'police' and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'police_actions') then
OpenPoliceActionsMenu()
GUI.Time = GetGameTimer()
end
if IsControlPressed(0, Keys['E']) and CurrentTask.Busy then
if IsControlJustReleased(0, Keys['E']) and CurrentTask.Busy then
ESX.ShowNotification(_U('impound_canceled'))
ESX.ClearTimeout(CurrentTask.Task)
ClearPedTasks(GetPlayerPed(-1))
ClearPedTasks(PlayerPedId())
CurrentTask.Busy = false
end
@@ -1871,7 +1910,7 @@ AddEventHandler('esx_policejob:updateBlip', function()
for i=1, #players, 1 do
if players[i].job.name == 'police' then
for id = 0, 32 do
if NetworkIsPlayerActive(id) and GetPlayerPed(id) ~= GetPlayerPed(-1) and GetPlayerName(id) == players[i].name then
if NetworkIsPlayerActive(id) and GetPlayerPed(id) ~= PlayerPedId() and GetPlayerName(id) == players[i].name then
createBlip(id)
end
end
@@ -1884,17 +1923,38 @@ end)
AddEventHandler('playerSpawned', function(spawn)
isDead = false
TriggerEvent('esx_policejob:unrestrain')
if not hasAlreadyJoined then
TriggerServerEvent('esx_policejob:spawned')
end
hasAlreadyJoined = true
IsHandcuffed = false
end)
AddEventHandler('esx:onPlayerDeath', function()
AddEventHandler('esx:onPlayerDeath', function(data)
isDead = true
end)
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
TriggerEvent('esx_policejob:unrestrain')
end
end)
-- handcuff timer, unrestrain the player after an certain amount of time
function StartHandcuffTimer()
if Config.EnableHandcuffTimer and HandcuffTimer then
ESX.ClearTimeout(HandcuffTimer)
end
HandcuffTimer = ESX.SetTimeout(Config.HandcuffTimer, function()
ESX.ShowNotification(_U('unrestrained_timer'))
TriggerEvent('esx_policejob:unrestrain')
end)
HandcuffTimer = nil
end
-- TODO
-- - return to garage if owned
-- - message owner that his vehicle has been impounded
+6
View File
@@ -1,14 +1,20 @@
Config = {}
Config.DrawDistance = 100.0
Config.MarkerType = 1
Config.MarkerSize = { x = 1.5, y = 1.5, z = 1.0 }
Config.MarkerColor = { r = 50, g = 50, b = 204 }
Config.EnablePlayerManagement = false
Config.EnableArmoryManagement = false
Config.EnableESXIdentity = false -- only turn this on if you are using esx_identity
Config.EnableNonFreemodePeds = false -- turn this on if you want custom peds
Config.EnableSocietyOwnedVehicles = false
Config.EnableLicenses = false -- only turn this on if you are using esx_license
Config.EnableHandcuffTimer = true -- enable handcuff timer? will unrestrain player after the time ends
Config.HandcuffTimer = 10 * 60000 -- 10 mins
Config.MaxInService = -1
Config.Locale = 'fr'
+1
View File
@@ -101,6 +101,7 @@ Locales['br'] = {
-- Misc
['remove_prop'] = 'Pressione ~INPUT_CONTEXT~ para remover o objeto',
['map_blip'] = 'Departamento de Polícia',
['unrestrained_timer'] = 'you feel your handcuffs slowly losing grip and fading away.',
-- Notifications
['alert_police'] = 'Alerta da Polícia',
}
+1
View File
@@ -101,6 +101,7 @@ Locales['de'] = {
-- Misc
['remove_prop'] = 'Drücke ~INPUT_CONTEXT~ um das Objekt zu entfernen',
['map_blip'] = 'Polizeistation',
['unrestrained_timer'] = 'you feel your handcuffs slowly losing grip and fading away.',
-- Notifications
['alert_police'] = 'Polizei alamieren',
}
+1
View File
@@ -109,6 +109,7 @@ Locales['en'] = {
-- Misc
['remove_prop'] = 'press ~INPUT_CONTEXT~ to delete the object',
['map_blip'] = 'police Station',
['unrestrained_timer'] = 'you feel your handcuffs slowly losing grip and fading away.',
-- Notifications
['alert_police'] = 'alert police',
}
+1
View File
@@ -107,6 +107,7 @@ Locales['es'] = {
-- Misc
['remove_prop'] = 'Presionar ~INPUT_CONTEXT~ para eliminar el objeto',
['map_blip'] = 'Comisaría de policía',
['unrestrained_timer'] = 'you feel your handcuffs slowly losing grip and fading away.',
-- Notifications
['alert_police'] = 'Alerta policia',
}
+1
View File
@@ -107,6 +107,7 @@ Locales['fi'] = {
-- Misc
['remove_prop'] = 'Paina ~INPUT_CONTEXT~ poistaaksesi objektin',
['map_blip'] = 'Poliisilaitos',
['unrestrained_timer'] = 'you feel your handcuffs slowly losing grip and fading away.',
-- Notifications
['alert_police'] = 'hälyytys Poliisi',
}
+1
View File
@@ -107,6 +107,7 @@ Locales['fr'] = {
-- Misc
['remove_prop'] = 'appuyez sur ~INPUT_CONTEXT~ pour enlever l\'objet',
['map_blip'] = 'Commissariat',
['unrestrained_timer'] = 'you feel your handcuffs slowly losing grip and fading away.',
-- Notifications
['alert_police'] = 'alerte police',
}
+1
View File
@@ -109,6 +109,7 @@ Locales['pl'] = {
-- Misc
['remove_prop'] = 'Naciśnij ~INPUT_CONTEXT~ aby usunąć ten obiekt',
['map_blip'] = 'Komisariat Policji',
['unrestrained_timer'] = 'you feel your handcuffs slowly losing grip and fading away.',
-- Notifications
['alert_police'] = 'Ostrzeż policję',
}
+1
View File
@@ -107,6 +107,7 @@ Locales['sv'] = {
-- Misc
['remove_prop'] = 'tryck ~INPUT_CONTEXT~ för att ta bort obejektet',
['map_blip'] = 'Polisstation',
['unrestrained_timer'] = 'dina handklovar har försvunnit',
-- Notifications
['alert_police'] = 'Meddela polisen',
}