Skip to content

Commit

Permalink
Fixed Cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
Lachee committed Apr 28, 2021
1 parent 1d92607 commit a16a62e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 44 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,3 @@ This will replace the previous garage with this one.

**Dont forget to run the `.sql` in the `sql/` folder**

### TODO

- Fix camera
52 changes: 30 additions & 22 deletions client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ SpawnVehicle = function(data, isRecovery)
end

-- Always abort here cause the vehicle exists
return HandleCamera(cachedData["currentGarage"])
return
end

-- Close the menu
Expand Down Expand Up @@ -130,7 +130,6 @@ SpawnVehicle = function(data, isRecovery)
TriggerServerEvent('garage:addKeys', plate)
Citizen.Wait(100)
TriggerServerEvent('erp_garage:modifystate', vehicleProps, 0, nil)
HandleCamera(cachedData["currentGarage"])
end)

if isRecovery then
Expand Down Expand Up @@ -285,38 +284,47 @@ HandleAction = function(action)
end
end

HandleCamera = function(garage, toggle)
-- Detatches the camera from the garage
DetatchGarageCamera = function()
-- currentGarage = cachedData["currentGarage"]
-- if not currentGarage then
-- return false
-- end

print('Detatch Camera ')

-- Destroy the cam
if cachedData["cam"] then
DestroyCam(cachedData["cam"])
end

-- Revert
RenderScriptCams(0, 1, 750, 1, 0)
return true
end

-- Attaches the camera to a particular garage
AttachGarageCamera = function(garage)
if not garage then return; end
local Camerapos = Config.Garages[garage]["camera"]


local Camerapos = Config.Garages[garage]["camera"]
if not Camerapos then return end

if not toggle then
if cachedData["cam"] then
DestroyCam(cachedData["cam"])
end

if DoesEntityExist(cachedData["vehicle"]) then
DeleteEntity(cachedData["vehicle"])
end

RenderScriptCams(0, 1, 750, 1, 0)

return
end

print('Attach Camera Camera ' .. garage)

-- Clear previous camera
if cachedData["cam"] then
DestroyCam(cachedData["cam"])
end

-- Create the script and make it active
cachedData["cam"] = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)

SetCamCoord(cachedData["cam"], Camerapos["x"], Camerapos["y"], Camerapos["z"])
SetCamRot(cachedData["cam"], Camerapos["rotationX"], Camerapos["rotationY"], Camerapos["rotationZ"])
SetCamActive(cachedData["cam"], true)

-- Render the script
RenderScriptCams(1, 1, 750, 1, 1)

Citizen.Wait(500)
end

Expand Down Expand Up @@ -424,6 +432,6 @@ function tomoney(value)
if value == nil then
return '~g~FREE'
end

return '$' .. tostring(esx.Math.GroupDigits(value))
end
7 changes: 4 additions & 3 deletions client/garageMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ function MenuRecoveryList()
return
end

HandleCamera(currentGarage, true)
AttachGarageCamera(currentGarage)

ped = GetPlayerPed(-1);
MenuTitle = "Recovery"
ClearMenu()
Expand Down Expand Up @@ -167,13 +168,13 @@ end
-- Displays a list of vehicles
function MenuVehicleList()
currentGarage = cachedData["currentGarage"]

if not currentGarage then
CloseMenu()
return
end

HandleCamera(currentGarage, true)
AttachGarageCamera(currentGarage)

ped = GetPlayerPed(-1);
MenuTitle = "My vehicles :"
ClearMenu()
Expand Down
6 changes: 5 additions & 1 deletion client/gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,18 @@ end

--------------------------------------------------------------------------------------------------------------------
function CloseMenu()
if Menu.hidden then
return
end

-- Reset the camera, untrigger the inmenu
HandleCamera(currentGarage, false)
TriggerEvent("inmenu", false)

--Clear the menu
ClearMenu()

--Finally hide the menu
DetatchGarageCamera()
Menu.hidden = true
end

Expand Down
21 changes: 7 additions & 14 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Config.Garages = {
["heading"] = 160.0
}
},
["camera_fake"] = {
["camera"] = {
["x"] = 283.28225708008,
["y"] = -333.24017333984,
["z"] = 50.004745483398,
Expand All @@ -37,7 +37,7 @@ Config.Garages = {
["heading"] = 320.0
}
},
["camera_fake"] = {
["camera"] = {
["x"] = -1813.5513916016,
["y"] = -340.40087890625,
["z"] = 46.962894439697,
Expand All @@ -56,7 +56,6 @@ Config.Garages = {
["heading"] = 118.94
}
}

},
["F"] = {
["positions"] = {
Expand All @@ -68,8 +67,6 @@ Config.Garages = {
["heading"] = 45.58
}
}


},
["G"] = {
["positions"] = {
Expand Down Expand Up @@ -105,7 +102,7 @@ Config.Garages = {
["heading"] = 319.3
}
},
["camera_fake"] = {
["camera"] = {
["x"] = 1023.97,
["y"] = -756.88062744141,
["z"] = 59.571212768555,
Expand Down Expand Up @@ -174,8 +171,7 @@ Config.Garages = {
["heading"] = 159.29
}
},

["camera_fake"] = {
["camera"] = {
["x"] = 231.94,
["y"] = -803.61,
["z"] = 32.51,
Expand All @@ -194,7 +190,6 @@ Config.Garages = {
["heading"] = 162.14
}
}

},
["O"] = {
["positions"] = {
Expand All @@ -206,7 +201,6 @@ Config.Garages = {
["heading"] = 15.5
}
}

},
["P"] = {
["positions"] = {
Expand All @@ -218,7 +212,6 @@ Config.Garages = {
["heading"] = 164.31
}
}

},
["Q"] = {
["positions"] = {
Expand Down Expand Up @@ -276,7 +269,7 @@ Config.Garages = {
["text"] = "[ ~o~E~s~ ] Store Vehicle",
}
},
["camera_fake"] = {
["camera"] = {
["x"] = -709.066,
["y"] = -1348.404,
["z"] = 5.970,
Expand All @@ -297,7 +290,7 @@ Config.Garages = {
["text"] = "[ ~o~E~s~ ] Store Vehicle",
}
},
["camera_fake"] = {
["camera"] = {
["x"] = -1301.229,
["y"] = -3385.397,
["z"] = 24.265,
Expand All @@ -318,7 +311,7 @@ Config.Garages = {
["text"] = "[ ~o~E~s~ ] Store Vehicle",
}
},
["camera_fake"] = {
["camera"] = {
["x"] = 901.102,
["y"] = -1256.479,
["z"] = 31.271,
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version '1.0.5'
version '1.1.0'
author 'Lachee'
description 'Modified version of a garage script.'
repository 'https://github.com/lachee/fivem-garage'
Expand Down

0 comments on commit a16a62e

Please sign in to comment.