Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rdopaa authored May 5, 2023
1 parent 5e8c609 commit 012e05f
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 0 deletions.
94 changes: 94 additions & 0 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
local isRunningWorkaround = false

ESX = exports['es_extended']:getSharedObject()

function StartWorkaroundTask()
if isRunningWorkaround then
return
end
local timer = 0
local playerPed = PlayerPedId()
isRunningWorkaround = true

while timer < 100 do
Citizen.Wait(0)
timer = timer + 1

local vehicle = GetVehiclePedIsTryingToEnter(playerPed)

if DoesEntityExist(vehicle) then
local lockStatus = GetVehicleDoorLockStatus(vehicle)

if lockStatus == 4 then
ClearPedTasks(playerPed)
end
end
end
isRunningWorkaround = false
end

function ToggleVehicleLock()
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local vehicle
local dict = "anim@mp_player_intmenu@key_fob@"

Citizen.CreateThread(function()
StartWorkaroundTask()
end)
RequestAnimDict(dict)
while not HasAnimDictLoaded(dict) do
Citizen.Wait(5)
end

if IsPedInAnyVehicle(playerPed, false) then
vehicle = GetVehiclePedIsIn(playerPed, false)
else
vehicle = GetClosestVehicle(coords, 8.0, 0, 71)
end

if not DoesEntityExist(vehicle) then
return
end

ESX.TriggerServerCallback('fx_vehiclelock:Cars', function(isOwnedVehicle)
if isOwnedVehicle then
local lockStatus = GetVehicleDoorLockStatus(vehicle)
local vehicleLabel = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
vehicleLabel = GetLabelText(vehicleLabel)
if lockStatus == 1 then -- unlocked
SetVehicleDoorsLocked(vehicle, 2)
PlayVehicleDoorCloseSound(vehicle, 1)
StartVehicleHorn(vehicle, "NORMAL")
ESX.ShowNotification('~r~Cerraste~s~ tu ~b~'..vehicleLabel..'~b~.')
if not IsPedInAnyVehicle(PlayerPedId(), true) then
TaskPlayAnim(PlayerPedId(), dict, "fob_click_fp", 8.0, 8.0, -1, 48, 1, false, false, false)
end
elseif lockStatus == 2 then -- locked
SetVehicleDoorsLocked(vehicle, 1)
PlayVehicleDoorOpenSound(vehicle, 0)
StartVehicleHorn(vehicle, "NORMAL")
ESX.ShowNotification('~g~Abriste~s~ tu ~b~'..vehicleLabel..'~b~.')
if not IsPedInAnyVehicle(PlayerPedId(), true) then
TaskPlayAnim(PlayerPedId(), dict, "fob_click_fp", 8.0, 8.0, -1, 48, 1, false, false, false)
end
end
end
end, ESX.Math.Trim(GetVehicleNumberPlateText(vehicle)))
end

Citizen.CreateThread(function()
while true do
Citizen.Wait(0)

if IsControlJustReleased(0, 244) and IsInputDisabled(0) then
ToggleVehicleLock()
Citizen.Wait(300)

-- D-pad down on controllers works, too!
elseif IsControlJustReleased(0, 173) and not IsInputDisabled(0) then
ToggleVehicleLock()
Citizen.Wait(300)
end
end
end)
6 changes: 6 additions & 0 deletions locales/br.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Locales ['br'] = {
['message_title'] = '^3Veículo Fechado',
['message_locked'] = 'fechado',
['message_unlocked'] = 'aberto',
}

5 changes: 5 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Locales ['en'] = {
['message_title'] = '^3Vehicle lock',
['message_locked'] = 'locked',
['message_unlocked'] = 'unlocked',
}
5 changes: 5 additions & 0 deletions locales/es.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Locales ['es'] = {
['message_title'] = '^3Sistema de alarma',
['message_locked'] = 'Alarma Activada',
['message_unlocked'] = 'Alarma Desactivada',
}
5 changes: 5 additions & 0 deletions locales/fr.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Locales ['fr'] = {
['message_title'] = '^3Verrou véhicule',
['message_locked'] = 'ouvert',
['message_unlocked'] = 'fermé',
}
5 changes: 5 additions & 0 deletions locales/sv.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Locales ['sv'] = {
['message_title'] = '^3Fordonslås',
['message_locked'] = 'du låste fordonet',
['message_unlocked'] = 'du låste upp fordonet',
}
6 changes: 6 additions & 0 deletions locales/tr.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Locales ['tr'] = {
['message_title'] = '^3Araç kilidi',
['message_locked'] = 'kilitli',
['message_unlocked'] = 'açık',
}

16 changes: 16 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ESX = exports['es_extended']:getSharedObject()

ESX.RegisterServerCallback('fx_vehiclelock:Cars', function(source, cb, plate)
local xPlayer = ESX.GetPlayerFromId(source)

MySQL.Async.fetchAll('SELECT owner FROM owned_vehicles WHERE owner = @owner AND plate = @plate', {
['@owner'] = xPlayer.identifier,
['@plate'] = plate
}, function(result)
if result[1] then
cb(result[1].owner == xPlayer.identifier)
else
cb(false)
end
end)
end)

0 comments on commit 012e05f

Please sign in to comment.