Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
tweak(client/server): housing , private garage
Browse files Browse the repository at this point in the history
  • Loading branch information
renzuzu committed Nov 23, 2021
1 parent 1dbfbb8 commit 980fad5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 57 deletions.
65 changes: 34 additions & 31 deletions client/private.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function AntiDupe(coords, hash,x,y,z,w,prop)
Wait(10)
local move_coords = coords
local vehicle = IsAnyVehicleNearPoint(coords.x,coords.y,coords.z,1.1)
if not vehicle then v = CreateVehicle(hash,x,y,z,w,true,true) private_garages[v] = v SetVehicleProp(v, prop) SetVehicleBobo(v) SetEntityCollision(v,true) FreezeEntityPosition(v, false) end
if not vehicle then v = CreateVehicle(hash,x,y,z,w,true,false) private_garages[v] = v SetVehicleProp(v, prop) SetEntityCollision(v,true) FreezeEntityPosition(v, false) SetVehicleAsNoLongerNeeded(v) end
end

RegisterNetEvent('renzu_garage:ingarage')
Expand Down Expand Up @@ -448,17 +448,6 @@ RegisterNetEvent('renzu_garage:choose')
AddEventHandler('renzu_garage:choose', function(table,garage)
DoScreenFadeOut(1)
insidegarage = false
local closestplayer, dis = GetClosestPlayer()
local empty = true
for k,v in pairs(private_garages) do
empty = false
ReqAndDelete(v)
end
if empty then
for k,v in pairs(vehicleinarea) do
ReqAndDelete(v)
end
end
vehicleinarea = {}
private_garages = {}
Wait(2000)
Expand Down Expand Up @@ -509,31 +498,45 @@ function GetClosestPlayer()
end

RegisterNetEvent('renzu_garage:exitgarage')
AddEventHandler('renzu_garage:exitgarage', function(table,exit)
AddEventHandler('renzu_garage:exitgarage', function(t,exit)
if not exit then
insidegarage = false
local closestplayer, dis = GetClosestPlayer()
if closestplayer == -1 and dis < 33 then
local empty = true
for k,v in pairs(private_garages) do
empty = false
ReqAndDelete(v)
end
if empty then
for k,v in pairs(vehicleinarea) do
insidegarage = false
local closestplayer, dis = GetClosestPlayer()
if closestplayer == -1 and dis < 33 then
local empty = true
for k,v in pairs(private_garages) do
empty = false
ReqAndDelete(v)
end
if empty then
for k,v in pairs(vehicleinarea) do
ReqAndDelete(v)
end
end
vehicleinarea = {}
private_garages = {}
end
TriggerServerEvent('renzu_garage:exitgarage',t)
else
local empty = true
local closestplayer, dis = GetClosestPlayer()
if closestplayer == -1 and dis > 33 or closestplayer ~= -1 and dis > 33 then
for k,vehicle in pairs(GetGamePool('CVehicle')) do -- unreliable
vehicleinarea[string.gsub(GetVehicleNumberPlateText(vehicle), '^%s*(.-)%s*$', '%1'):upper()] = vehicle
end
if empty then
for k,v in pairs(vehicleinarea) do
ReqAndDelete(v)
end
end
end
vehicleinarea = {}
private_garages = {}
end
TriggerServerEvent('renzu_garage:exitgarage',table)
else
DoScreenFadeOut(1)
if housingcustom then
SetEntityCoords(PlayerPedId(),housingcustom.housing.x,housingcustom.housing.y,housingcustom.housing.z,true)
else
SetEntityCoords(PlayerPedId(),table.buycoords.x,table.buycoords.y,table.buycoords.z,true)
SetEntityCoords(PlayerPedId(),t.buycoords.x,t.buycoords.y,t.buycoords.z,true)
end
Wait(3500)
housingcustom = nil
Expand All @@ -543,9 +546,9 @@ end)

RegisterNetEvent('renzu_garage:opengaragemenu')
AddEventHandler('renzu_garage:opengaragemenu', function(garageid,v)
local garage,table = garageid,v
local garage,t = garageid,v
print(garage,t)
ESX.TriggerServerCallback("renzu_garage:isgarageowned",function(owned,share)
print(owned,share)
local multimenu = {}
if not owned then
firstmenu = {
Expand All @@ -554,7 +557,7 @@ AddEventHandler('renzu_garage:opengaragemenu', function(garageid,v)
['fa'] = '<i class="fad fa-question-square"></i>',
['type'] = 'event', -- event / export
['content'] = 'renzu_garage:buygarage',
['variables'] = {server = true, send_entity = false, onclickcloseui = true, custom_arg = {garage,table}, arg_unpack = true},
['variables'] = {server = true, send_entity = false, onclickcloseui = true, custom_arg = {garage,t}, arg_unpack = true},
},
}
multimenu[Message[29]] = firstmenu
Expand Down Expand Up @@ -588,7 +591,7 @@ AddEventHandler('renzu_garage:opengaragemenu', function(garageid,v)
['fa'] = '<i class="fad fa-garage"></i>',
['type'] = 'event', -- event / export
['content'] = 'renzu_garage:gotogarage',
['variables'] = {server = true, send_entity = false, onclickcloseui = true, custom_arg = {garage,table}, arg_unpack = true},
['variables'] = {server = true, send_entity = false, onclickcloseui = true, custom_arg = {garage,t,false}, arg_unpack = true},
},
}
multimenu['My Garage'] = secondmenu
Expand Down
2 changes: 2 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
fx_version 'cerulean'
games {'common'}
ui_page 'html/index.html'
lua54 'yes'
use_fxv2_oal 'yes'

shared_scripts {
'conf/locale/*.lua',
Expand Down
71 changes: 45 additions & 26 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ Citizen.CreateThread(function()
print("^2 Checking parking_meter table ^7")
parkmeter = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM parking_meter', {}) or {}
print("^2 parking_meter table ok ^7")
print("^2 Caching Vehicles Please Wait.. ^7")
print("^2 Caching #"..#globalvehicles.." Vehicles Please Wait.. ^7")
local vehiclescount = #globalvehicles
local tempvehicles = {}
for k,v in ipairs(globalvehicles) do
if v.plate then
Expand All @@ -98,7 +99,9 @@ Citizen.CreateThread(function()
tempvehicles[plate].plate = v.plate
tempvehicles[plate].name = 'NULL'
end
Wait(0) -- neccessary for large table avoid hitch
if vehiclescount > 5000 then
Wait(0) -- neccessary for large table avoid hitch
end
end
for k,v in pairs(globalvehicles) do
local plate = string.gsub(v.plate, '^%s*(.-)%s*$', '%1')
Expand All @@ -111,7 +114,9 @@ Citizen.CreateThread(function()
end
end
end
Wait(0) -- neccessary for large table avoid hitch
if vehiclescount > 5000 then
Wait(0) -- neccessary for large table avoid hitch
end
end
GlobalState.GVehicles = tempvehicles
tempvehicles = nil
Expand Down Expand Up @@ -435,7 +440,6 @@ AddEventHandler('renzu_garage:buygarage', function(id,v)
local houseid = string.gsub(id, 'garage_', '')
for k,v in pairs(HousingGarages) do
if tonumber(houseid) == tonumber(k) then
print(v.shell,HouseGarageCost[v.shell])
shellcost = HouseGarageCost[v.shell] or 10000
end
end
Expand Down Expand Up @@ -477,6 +481,9 @@ end

RegisterServerEvent('renzu_garage:storeprivate')
AddEventHandler('renzu_garage:storeprivate', function(id,v,prop, shell)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local identifier = xPlayer.identifier
if not private_garage[id] then
local shelltype = shell or 'small'
local houseid = string.gsub(id, 'garage_', '')
Expand All @@ -486,19 +493,22 @@ AddEventHandler('renzu_garage:storeprivate', function(id,v,prop, shell)
end
end
housegarage[id] = {shell = shelltype, id = id, housing = housing}
local owned = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM private_garage WHERE garage = @garage', {
['@garage'] = id
})
if owned[1] and owned[1].identifier then
identifier = owned[1].identifier
end
end
local id = housegarage[id] ~= nil and housegarage[id].id or id
local prop = prop
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local identifier = xPlayer.identifier
local result = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM owned_vehicles WHERE owner = @owner and TRIM(UPPER(plate)) = @plate LIMIT 1', {
['@owner'] = xPlayer.identifier,
['@plate'] = string.gsub(prop.plate:upper(), '^%s*(.-)%s*$', '%1')
})
if not Config.Allowednotowned and result[1] == nil then TriggerClientEvent('renzu_notify:Notify', src, 'error',Message[2], Message[69]) return end
local garage = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM private_garage WHERE identifier = @identifier and garage = @garage', {
['@identifier'] = xPlayer.identifier,
['@identifier'] = identifier,
['@garage'] = id
})
local vehiclesgarage = {}
Expand Down Expand Up @@ -532,17 +542,16 @@ AddEventHandler('renzu_garage:storeprivate', function(id,v,prop, shell)
end
end
if success and not newgarage or newgarage then
MysqlGarage(Config.Mysql,'execute','UPDATE owned_vehicles SET `stored` = @stored, garage_id = @garage_id, vehicle = @vehicle WHERE TRIM(UPPER(plate)) = @plate and owner = @owner', {
MysqlGarage(Config.Mysql,'execute','UPDATE owned_vehicles SET `stored` = @stored, garage_id = @garage_id, vehicle = @vehicle WHERE TRIM(UPPER(plate)) = @plate', {
['@vehicle'] = json.encode(prop),
['@garage_id'] = 'private',
['@plate'] = string.gsub(prop.plate:upper(), '^%s*(.-)%s*$', '%1'),
['@owner'] = xPlayer.identifier,
['@stored'] = 0
})
MysqlGarage(Config.Mysql,'execute','UPDATE private_garage SET `vehicles` = @vehicles WHERE garage = @garage and identifier = @identifier', {
['@vehicles'] = json.encode(vehiclesgarage),
['@garage'] = id,
['@identifier'] = xPlayer.identifier,
['@identifier'] = identifier,
})
TriggerClientEvent('renzu_notify:Notify', src, 'success',Message[2], Message[67])
vehiclesgarage = {}
Expand All @@ -561,8 +570,7 @@ AddEventHandler('renzu_garage:gotohousegarage', function(id,var)
if share and not DoiOwnthis(xPlayer,houseid) then
identifier = v.owner or xPlayer.identifier
end
local result = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM private_garage WHERE identifier = @identifier and garage = @garage', {
['@identifier'] = identifier,
local result = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM private_garage WHERE garage = @garage', {
['@garage'] = houseid
})
if not result[1] then
Expand Down Expand Up @@ -591,7 +599,7 @@ AddEventHandler('renzu_garage:gotohousegarage', function(id,var)
break
end
end
elseif share then
elseif share and v and v.route then
routing = v.route
end
garagehouseid = houseid:gsub('garage_','')
Expand All @@ -607,7 +615,8 @@ AddEventHandler('renzu_garage:gotohousegarage', function(id,var)
end
housegarage[houseid] = {shell = id, id = houseid, housing = housing}
TriggerClientEvent('renzu_garage:ingarage',source, result[1],private_garage[id],houseid, vehicle_,housegarage[houseid])

result = {}
vehicle_ = {}
end)

RegisterServerEvent('renzu_garage:gotogarage')
Expand Down Expand Up @@ -640,8 +649,8 @@ AddEventHandler('renzu_garage:gotogarage', function(id,v,share)
break
end
end
elseif share then
routing = v.route
elseif share and v and v.route and not DoiOwnthis(xPlayer,id) then
routing = v.route or routing
end
SetPlayerRoutingBucket(source,routing)
if not share and not haveworld then
Expand All @@ -660,17 +669,26 @@ AddEventHandler('renzu_garage:gotogarage', function(id,v,share)
end)

RegisterServerEvent('renzu_garage:exitgarage')
AddEventHandler('renzu_garage:exitgarage', function(table,prop,id,choose,share)
AddEventHandler('renzu_garage:exitgarage', function(t,prop,id,choose,share)
local source = source
local xPlayer = ESX.GetPlayerFromId(source)
local id = id
local identifier = xPlayer.identifier
if not private_garage[id] then -- housing garages
local owned = MysqlGarage(Config.Mysql,'fetchAll','SELECT * FROM private_garage WHERE garage = @garage', {
['@garage'] = id
})
if owned[1] and owned[1].identifier then
identifier = owned[1].identifier
end
end
if not choose then
--SetEntityCoords(GetPlayerPed(source),table.buycoords.x,table.buycoords.y,table.buycoords.z,true)
TriggerClientEvent('renzu_garage:exitgarage',source, table, true)
TriggerClientEvent('renzu_garage:exitgarage',source, t, true)
Wait(1000)
SetPlayerRoutingBucket(source,default_routing[source])
--current_routing[default_routing[source]] = nil
else
local identifier = xPlayer.identifier
if share and not DoiOwnthis(xPlayer,id) then
identifier = share.owner
end
Expand All @@ -689,11 +707,10 @@ AddEventHandler('renzu_garage:exitgarage', function(table,prop,id,choose,share)
break
end
end
local result = MysqlGarage(Config.Mysql,'execute','UPDATE owned_vehicles SET `stored` = @stored, garage_id = @garage_id, vehicle = @vehicle WHERE TRIM(UPPER(plate)) = @plate and owner = @owner', {
local result = MysqlGarage(Config.Mysql,'execute','UPDATE owned_vehicles SET `stored` = @stored, garage_id = @garage_id, vehicle = @vehicle WHERE TRIM(UPPER(plate)) = @plate', {
['@vehicle'] = json.encode(prop),
['@garage_id'] = 'A',
['@plate'] = string.gsub(prop.plate:upper(), '^%s*(.-)%s*$', '%1'),
['@owner'] = identifier,
['@stored'] = 0
})
local result = MysqlGarage(Config.Mysql,'execute','UPDATE private_garage SET `vehicles` = @vehicles WHERE garage = @garage and identifier = @identifier', {
Expand All @@ -703,13 +720,16 @@ AddEventHandler('renzu_garage:exitgarage', function(table,prop,id,choose,share)
})
TriggerClientEvent('renzu_notify:Notify', source, 'success',Message[2], Message[70])
--SetEntityCoords(GetPlayerPed(source),table.buycoords.x,table.buycoords.y,table.buycoords.z,true)
TriggerClientEvent('renzu_garage:exitgarage',source, table, true)
TriggerClientEvent('renzu_garage:exitgarage',source, t, true)
Wait(500)
--current_routing[default_routing[source]] = nil
TriggerClientEvent('renzu_garage:choose',source,prop,table)
Wait(1000)
TriggerClientEvent('renzu_garage:choose',source,prop,t)
Wait(2000)
SetPlayerRoutingBucket(source,default_routing[source])
TriggerClientEvent('renzu_garage:syncstate',-1,string.gsub(prop.plate:upper(), '^%s*(.-)%s*$', '%1'),source)
t = {}
vehicles = {}
result = {}
end
lastgarage[source] = nil
end)
Expand Down Expand Up @@ -774,7 +794,6 @@ ESX.RegisterServerCallback('renzu_garage:parkingmeter', function (source, cb, co
end
end
if canpark then
print(globalkeys[plate],plate,globalkeys[plate] and globalkeys[plate][xPlayer.identifier])
MysqlGarage(Config.Mysql,'execute','INSERT INTO parking_meter (identifier, coord, park_coord, vehicle, plate) VALUES (@identifier, @coord, @park_coord, @vehicle, @plate)', {
['@identifier'] = globalkeys[plate] and globalkeys[plate][xPlayer.identifier] and globalkeys[plate][xPlayer.identifier] ~= true and globalkeys[plate][xPlayer.identifier] or xPlayer.identifier,
['@coord'] = json.encode(coord),
Expand Down

0 comments on commit 980fad5

Please sign in to comment.