Skip to content

Commit

Permalink
ver 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
swkeep committed Jun 5, 2022
1 parent 81eb0c8 commit 1ccfd3a
Show file tree
Hide file tree
Showing 8 changed files with 738 additions and 317 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Lua.diagnostics.disable": ["undefined-global"]
}
244 changes: 161 additions & 83 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ local onDuty = false
local receivedDoorData = false
local receivedData = nil

-- Events
local function isVehicleExistInRealLife(plate)
-- Functions

local function doesVehicleExist(plate)
local gameVehicles = QBCore.Functions.GetVehicles()
local check = false
for i = 1, #gameVehicles do
Expand Down Expand Up @@ -68,61 +69,6 @@ local function GetNearSpawnPoint() -- Get nearest spawn point
return near
end

local displayNUIText = function(text)
SendNUIMessage({ type = "display", text = text, color = '#f2b502' })
Wait(1)
end

local hideNUI = function()
SendNUIMessage({ type = "hide" })
Wait(1)
end

CreateThread(function() -- Get nearest spawn point
while true do
Wait(1000)
if IsOnDuty() and GetJobInfo().name == 'police' and inGarageStation and currentgarage ~= nil then
nearspawnpoint = GetNearSpawnPoint()
displayNUIText('Parking')
else
hideNUI()
end
end
end)

CreateThread(function() -- Check if the player is in the garage area or not
while true do
local Ped = PlayerPedId()
local coord = GetEntityCoords(Ped)
if Ped and coord and GarageLocation and next(GarageLocation) ~= nil then
for k, v in pairs(GarageLocation) do
if GarageLocation[k] then
if GarageLocation[k]:isPointInside(coord) then
inGarageStation = true
currentgarage = k
while inGarageStation do
local InZoneCoordS = GetEntityCoords(Ped)
if not GarageLocation[k]:isPointInside(InZoneCoordS) then
inGarageStation = false
currentgarage = nil
end
Wait(1000)
end
end
end
end
end
Wait(1000)
end
end)

local closeNUI = function()
SetNuiFocus(false, false)
SendNUIMessage({ type = "newDoorSetup", enable = false })
Wait(10)
receivedDoorData = nil
end

local function isWhitelisted(currentgarage, model)
if type(model) == "number" then model = tostring(model) end
local list = Config.JobGarages[currentgarage].WhiteList
Expand Down Expand Up @@ -151,6 +97,7 @@ local function saveVehicle(d)
name = d.vehiclename,
grades = d.grades,
cids = d.cids,
job = d.job,
hash = GetHashKey(veh),
garage = currentgarage,
info = info
Expand All @@ -161,17 +108,116 @@ local function saveVehicle(d)
while IsPedInAnyVehicle(plyPed, false) do
Wait(100)
end
QBCore.Functions.DeleteVehicle(veh)
local plate = QBCore.Functions.GetPlate(veh)
TriggerServerEvent('keep-jobgarages:client:delete_if_exist', plate, veh)
end
end, required_data)
end

function IsOnDuty()
return true
-- return onDuty
end

function GetJobInfo()
return PlayerJob
end

function GetNearspawnpoint()
return nearspawnpoint
end

function GetCurrentgarage()
return currentgarage
end

function GetCurrentgarageData()
return Config.JobGarages[GetCurrentgarage()]
end

function GetInGarageStation()
return inGarageStation
end

local function getCurrentgarageType()
if Config.JobGarages[GetCurrentgarage()] then
return Config.JobGarages[GetCurrentgarage()].type
end
return false
end

local function is_garage_a_job_garage()
if getCurrentgarageType() == 'job' then
return true
end
return false
end

local function has_player_same_job_as_garage()
local current_garage = GetCurrentgarageData()
local job_name = GetJobInfo().name

for key, value in pairs(current_garage.job) do
if value == job_name then
return true
end
end
return false
end

local function does_player_need_to_be_on_duty()
if GetCurrentgarageData().onDuty then return true end
return false
end

local function check_player_duty()
if does_player_need_to_be_on_duty() then
if IsOnDuty() then return true end
return false
end
return true
end

local function can_player_use_garage()
if is_garage_a_job_garage() then
-- is a job garage
if has_player_same_job_as_garage() then
return check_player_duty()
else
return false
end
end
return true
end

function CanPlayerUseGarage()
return can_player_use_garage()
end

-- NUI

local function displayNUIText(text)
SendNUIMessage({ type = "display", text = text, color = '#f2b502' })
Wait(1)
end

local function hideNUI()
SendNUIMessage({ type = "hide" })
Wait(1)
end

local function closeNUI()
SetNuiFocus(false, false)
SendNUIMessage({ type = "newDoorSetup", enable = false })
Wait(10)
receivedDoorData = nil
end

RegisterNUICallback('saveNewVehicle', function(data, cb)
receivedDoorData = true
receivedData = data
if saveVehicle(receivedData) == false then
cb(false)

end
closeNUI()
cb('ok')
Expand All @@ -182,6 +228,52 @@ RegisterNUICallback('close', function(data, cb)
cb('ok')
end)

-- script Threads

CreateThread(function() -- Get nearest spawn point
while true do
Wait(1000)
if not can_player_use_garage() then
goto skip
end
if inGarageStation and currentgarage ~= nil then
displayNUIText('Parking')
nearspawnpoint = GetNearSpawnPoint()
else
hideNUI()
end
::skip::
end
end)

CreateThread(function() -- Check if the player is in the garage area or not
while true do
local Ped = PlayerPedId()
local coord = GetEntityCoords(Ped)
if Ped and coord and GarageLocation and next(GarageLocation) ~= nil then
for k, v in pairs(GarageLocation) do
if GarageLocation[k] then
if GarageLocation[k]:isPointInside(coord) then
inGarageStation = true
currentgarage = k
while inGarageStation do
local InZoneCoordS = GetEntityCoords(Ped)
if not GarageLocation[k]:isPointInside(InZoneCoordS) then
inGarageStation = false
currentgarage = nil
end
Wait(1000)
end
end
end
end
end
Wait(1000)
end
end)

-- Events

RegisterNetEvent('keep-jobgarages:client:newVehicleSetup', function()
local plyPed = PlayerPedId()
if not IsPedInAnyVehicle(plyPed, false) then
Expand All @@ -195,8 +287,7 @@ RegisterNetEvent('keep-jobgarages:client:newVehicleSetup', function()
if receivedDoorData == nil then return end
end)


AddEventHandler('onResourceStart', function(resourceName)
RegisterNetEvent('onResourceStart', function(resourceName)
if resourceName == GetCurrentResourceName() then
QBCore.Functions.GetPlayerData(function(PlayerData)
PlayerJob = PlayerData.job
Expand All @@ -209,7 +300,7 @@ AddEventHandler('onResourceStart', function(resourceName)
name = 'GarageStation ' .. k,
minZ = v.minz,
maxZ = v.maxz,
debugPoly = false
debugPoly = true
})
end
end
Expand All @@ -222,6 +313,14 @@ RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
onDuty = PlayerData.job.onduty
end
end)
for k, v in pairs(Config.JobGarages) do
GarageLocation[k] = PolyZone:Create(v.zones, {
name = 'GarageStation ' .. k,
minZ = v.minz,
maxZ = v.maxz,
debugPoly = true
})
end
end)

RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
Expand All @@ -236,29 +335,8 @@ RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
end
end)


RegisterNetEvent('QBCore:Client:SetDuty', function(duty)
if PlayerJob.name == 'police' and duty ~= onDuty then
onDuty = duty
end
end)

function IsOnDuty()
return onDuty
end

function GetJobInfo()
return PlayerJob
end

function GetNearspawnpoint()
return nearspawnpoint
end

function GetCurrentgarage()
return currentgarage
end

function GetInGarageStation()
return inGarageStation
end
Loading

0 comments on commit 1ccfd3a

Please sign in to comment.