Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tweak(all): enable to use parkingmeter to park anywhere
  • Loading branch information
renzuzu committed Oct 12, 2021
1 parent d451c0d commit 9e9a39c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
28 changes: 22 additions & 6 deletions client/client.lua
Expand Up @@ -149,9 +149,9 @@ AddEventHandler('renzu_garage:update_parked', function(table,plate,p)
if p then
parkmeter = p
for k,v in pairs(meter_cars) do
if tostring(k, '^%s*(.-)%s*$', '%1'):upper() == plate then
if tostring(k, '^%s*(.-)%s*$', '%1'):upper() == tostring(plate, '^%s*(.-)%s*$', '%1'):upper() then
ent = v
meter_cars[k] = nil
meter_cars[tostring(k, '^%s*(.-)%s*$', '%1'):upper()] = nil
ReqAndDelete(ent)
end
end
Expand Down Expand Up @@ -3575,6 +3575,9 @@ function ReqAndDelete(object, detach)
SetEntityAsMissionEntity(object, true, true)
SetEntityAsNoLongerNeeded(object)
DeleteEntity(object)
if DoesEntityExist(object) then
SetEntityCoords(object, 0.0,0.0,0.0)
end
end
end

Expand Down Expand Up @@ -3690,14 +3693,19 @@ function Spawn_Vehicle_Forward(veh, coords)
end

meter_cars = {}
RegisterCommand('parkingmeter', function(source, args, rawCommand)

function Park()
local closestparkingmeter = nil
local vehicle = GetVehiclePedIsIn(PlayerPedId())
local loc = GetEntityCoords(vehicle)
local coord = vector4(loc.x,loc.y,loc.z,GetEntityHeading(vehicle))
for k,v in pairs(Config.MeterProp) do
closestparkingmeter = GetClosestObjectOfType(loc, 7.0, GetHashKey(v), false)
if closestparkingmeter ~= 0 then break end
if Config.ParkingAnywhere then
closestparkingmeter = GetVehiclePedIsIn(PlayerPedId())
else
for k,v in pairs(Config.MeterProp) do
closestparkingmeter = GetClosestObjectOfType(loc, 7.0, GetHashKey(v), false)
if closestparkingmeter ~= 0 then break end
end
end
if closestparkingmeter ~= 0 then
local vehicle_prop = GetVehicleProperties(vehicle)
Expand All @@ -3716,6 +3724,14 @@ RegisterCommand('parkingmeter', function(source, args, rawCommand)
end
end,GetEntityCoords(closestparkingmeter),coord,json.encode(vehicle_prop))
end
end

RegisterCommand('parkingmeter', function(source, args, rawCommand)
Park()
end)

RegisterCommand('park', function(source, args, rawCommand)
Park()
end)

CreateThread(function()
Expand Down
5 changes: 4 additions & 1 deletion config.lua
Expand Up @@ -946,7 +946,10 @@ Config.EnablePropertyCoordGarageCoord = false -- Enable / Disable Property Coord
Config.PropertyQuickPick = true -- quickpick
Config.UniqueProperty = true -- if enable , only stored vehicles in this Property ID will be show

Config.ParkingMeter = true
Config.ParkingMeter = true -- use configure parking props and park near by them
Config.ParkingAnywhere = true -- if this is true ParkingMeter Prop Feature will be replaced
-- ParkingAnywhere is like a realistic parking but by using /park command or /parkingmater
-- you can park anywhere using /park
Config.MeterProp = {
[1] = 'prop_parknmeter_01',
[2] = 'prop_parknmeter_02',
Expand Down
2 changes: 1 addition & 1 deletion garage.sql
Expand Up @@ -11,7 +11,7 @@ ALTER TABLE owned_vehicles
ADD `type` varchar(32) NOT NULL DEFAULT 'car';

ALTER TABLE owned_vehicles
ADD `job` varchar(32) NOT NULL;
ADD `job` varchar(32) NOT NULL DEFAULT 'civ';

ALTER TABLE owned_vehicles
ADD park_coord LONGTEXT NULL;
Expand Down
7 changes: 7 additions & 0 deletions server/server.lua
Expand Up @@ -615,6 +615,9 @@ ESX.RegisterServerCallback('renzu_garage:parkingmeter', function (source, cb, co
TriggerClientEvent('renzu_notify:Notify', src, 'error','Garage', 'Parking is occupied')
cb(false)
end
else
TriggerClientEvent('renzu_notify:Notify', src, 'error','Garage', 'Not Enough Money to pay parking')
cb(false)
end
end)

Expand Down Expand Up @@ -707,6 +710,7 @@ AddEventHandler('renzu_garage:park', function(plate,state,coord,model,props)
})
Wait(800)
parkedvehicles = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE isparked = 1', {}) or {}
parkmeter = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM parking_meter', {}) or {}
Wait(200)
TriggerClientEvent('renzu_garage:update_parked',-1,parkedvehicles, false, parkmeter)
else
Expand Down Expand Up @@ -748,6 +752,7 @@ AddEventHandler('renzu_garage:unpark', function(plate,state,model)
Wait(300)
parkedvehicles = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE isparked = 1', {}) or {}
Wait(200)
parkmeter = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM parking_meter', {}) or {}
TriggerClientEvent('renzu_garage:update_parked',-1,parkedvehicles,plate:upper(),parkmeter)
else
print('exploiting')
Expand Down Expand Up @@ -796,6 +801,7 @@ AddEventHandler('renzu_garage:changestate', function(plate,state,garage_id,model
Wait(300)
parkedvehicles = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE isparked = 1', {}) or {}
Wait(200)
parkmeter = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM parking_meter', {}) or {}
TriggerClientEvent('renzu_garage:update_parked',-1,parkedvehicles,plate:upper(),parkmeter)
end
if state == 1 then
Expand Down Expand Up @@ -839,6 +845,7 @@ AddEventHandler('renzu_garage:changestate', function(plate,state,garage_id,model
Wait(300)
parkedvehicles = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE isparked = 1', {}) or {}
Wait(200)
parkmeter = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM parking_meter', {}) or {}
TriggerClientEvent('renzu_garage:update_parked',-1,parkedvehicles,plate:upper(),parkmeter)
end
TriggerClientEvent('renzu_notify:Notify', source, 'success','Garage', 'You Take out the Vehicle')
Expand Down

0 comments on commit 9e9a39c

Please sign in to comment.