Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move to modules, ox_lib, style fixes #34

Merged
merged 14 commits into from
Sep 25, 2023
39 changes: 18 additions & 21 deletions client/binoculars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@ local zoomspeed = 10.0 -- camera zoom speed
local speed_lr = 8.0 -- speed by which the camera pans left-right
local speed_ud = 8.0 -- speed by which the camera pans up-down
local binoculars = false
local fov = (fov_max+fov_min)*0.5
local fov = (fov_max + fov_min) * 0.5
local storeBinoclarKey = 177 -- Backspace

--FUNCTIONS--

local function CheckInputRotation(cam, zoomvalue)
local function checkInputRotation(cam, zoomvalue)
local rightAxisX = GetControlNormal(0, 220)
local rightAxisY = GetControlNormal(0, 221)
local rotation = GetCamRot(cam, 2)
if rightAxisX ~= 0.0 or rightAxisY ~= 0.0 then
local new_z = rotation.z + rightAxisX*-1.0*(speed_ud)*(zoomvalue+0.1)
local new_x = math.max(math.min(20.0, rotation.x + rightAxisY*-1.0*(speed_lr)*(zoomvalue+0.1)), -89.5)
local new_z = rotation.z + rightAxisX * -1.0 * (speed_ud) * (zoomvalue + 0.1)
local new_x = math.max(math.min(20.0, rotation.x + rightAxisY * -1.0 * (speed_lr) * (zoomvalue + 0.1)), -89.5)
SetCamRot(cam, new_x, 0.0, new_z, 2)
SetEntityHeading(cache.ped,new_z)
SetEntityHeading(cache.ped, new_z)
end
end

local function HandleZoom(cam)
local function handleZoom(cam)
if not IsPedSittingInAnyVehicle(cache.ped) then
if IsControlJustPressed(0,241) then -- Scrollup
if IsControlJustPressed(0, 241) then -- Scrollup
fov = math.max(fov - zoomspeed, fov_min)
end
if IsControlJustPressed(0,242) then
if IsControlJustPressed(0, 242) then
fov = math.min(fov + zoomspeed, fov_max) -- ScrollDown
end
local current_fov = GetCamFov(cam)
if math.abs(fov-current_fov) < 0.1 then
fov = current_fov
end
SetCamFov(cam, current_fov + (fov - current_fov)*0.05)
SetCamFov(cam, current_fov + (fov - current_fov) * 0.05)
else
if IsControlJustPressed(0,17) then -- Scrollup
if IsControlJustPressed(0, 17) then -- Scrollup
fov = math.max(fov - zoomspeed, fov_min)
end
if IsControlJustPressed(0,16) then
if IsControlJustPressed(0, 16) then
fov = math.min(fov + zoomspeed, fov_max) -- ScrollDown
end
local current_fov = GetCamFov(cam)
if math.abs(fov-current_fov) < 0.1 then -- the difference is too small, just set the value directly to avoid unneeded updates to FOV of order 10^-5
fov = current_fov
end
SetCamFov(cam, current_fov + (fov - current_fov)*0.05) -- Smoothing of camera zoom
SetCamFov(cam, current_fov + (fov - current_fov) * 0.05) -- Smoothing of camera zoom
end
end

Expand All @@ -61,8 +61,8 @@ RegisterNetEvent('binoculars:Toggle', function()
if binoculars then
TaskStartScenarioInPlace(cache.ped, 'WORLD_HUMAN_BINOCULARS', 0, true)
cam = CreateCam('DEFAULT_SCRIPTED_CAMERA', true)
AttachCamToEntity(cam, cache.ped, 0.0,0.0,1.0, true)
SetCamRot(cam, 0.0,0.0, GetEntityHeading(cache.ped), 2)
AttachCamToEntity(cam, cache.ped, 0.0, 0.0, 1.0, true)
SetCamRot(cam, 0.0, 0.0, GetEntityHeading(cache.ped), 2)
RenderScriptCams(true, false, 5000, true, false)
else
ClearPedTasks(cache.ped)
Expand All @@ -74,10 +74,7 @@ RegisterNetEvent('binoculars:Toggle', function()

while binoculars do

scaleform = RequestScaleformMovie('BINOCULARS')
while not HasScaleformMovieLoaded(scaleform) do
Wait(10)
end
scaleform = lib.requestScaleformMovie('BINOCULARS')

BeginScaleformMovieMethod(scaleform, 'SET_CAM_LOGO')
ScaleformMovieMethodAddParamInt(0) -- 0 for nothing, 1 for LSPD logo
Expand All @@ -92,9 +89,9 @@ RegisterNetEvent('binoculars:Toggle', function()
cam = nil
end

local zoomvalue = (1.0/(fov_max-fov_min))*(fov-fov_min)
CheckInputRotation(cam, zoomvalue)
HandleZoom(cam)
local zoomvalue = (1.0 / (fov_max-fov_min)) * (fov-fov_min)
checkInputRotation(cam, zoomvalue)
handleZoom(cam)
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
Wait(0)
end
Expand Down
22 changes: 3 additions & 19 deletions client/carwash.lua
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
local QBCore = exports['qbx-core']:GetCoreObject()
local washingVehicle = false

local function DrawText3Ds(x, y, z, text)
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(true)
SetTextColour(255, 255, 255, 215)
BeginTextCommandDisplayText('STRING')
SetTextCentre(true)
AddTextComponentSubstringPlayerName(text)
SetDrawOrigin(x,y,z, 0)
EndTextCommandDisplayText(0.0, 0.0)
local factor = (string.len(text)) / 370
DrawRect(0.0, 0.0+0.0125, 0.017+ factor, 0.03, 0, 0, 0, 75)
ClearDrawOrigin()
end

RegisterNetEvent('qb-carwash:client:washCar', function()
washingVehicle = true
if lib.progressBar({
Expand All @@ -35,7 +19,7 @@ RegisterNetEvent('qb-carwash:client:washCar', function()
WashDecalsFromVehicle(cache.vehicle, 1.0)
washingVehicle = false
else -- if cancel
QBCore.Functions.Notify('Washing canceled ..', 'error')
QBCore.Functions.Notify('Washing canceled...', 'error')
washingVehicle = false
end
end)
Expand All @@ -53,7 +37,7 @@ CreateThread(function()
if dist <= 7.5 and driver then
sleep = 0
if not washingVehicle then
DrawText3Ds(carWashCoords.x, carWashCoords.y, carWashCoords.z, '~g~E~w~ - Wash the car ($'..Config.CarWash.defaultPrice..')')
DrawText3D('~g~E~w~ - Wash the car ($'..Config.CarWash.defaultPrice..')', carWashCoords)
if IsControlJustPressed(0, 38) then
if dirtLevel > Config.CarWash.dirtLevel then
TriggerServerEvent('qb-carwash:server:washCar')
Expand All @@ -62,7 +46,7 @@ CreateThread(function()
end
end
else
DrawText3Ds(carWashCoords.x, carWashCoords.y, carWashCoords.z, 'The car wash is not available...')
DrawText3D('The car wash is not available...', carWashCoords)
end
end
end
Expand Down
Loading
Loading