Skip to content

Commit

Permalink
Added new options
Browse files Browse the repository at this point in the history
* Allow for enabling / disabling keys
* Allow custom notifications with `Config.SendNotification`
* Allow camera offset with `Config.CamOffset`
  • Loading branch information
Mobius1 committed Nov 8, 2023
1 parent e8fb66d commit 64719ee
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 69 deletions.
79 changes: 31 additions & 48 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ function Spycam.Place(entity, coords, rotation)
Spycam.Add(entity, coords, rotation, uuid)

TriggerServerEvent('spycams:server:placed', uuid, coords, rotation, onFloor)
Config.SendNotification(Lang:t('notifications.placed'), 'info')
end
end)
end
Expand Down Expand Up @@ -239,7 +240,7 @@ function Spycam.StartPlacement()
SetEntityRotation(currentObject, rotation.x, rotation.y, rotation.z, 4)

-- Place the spycam
if IsDisabledControlJustPressed(0, keys.place.button) then
if IsDisabledControlJustPressed(0, keys.place.key) then
if invalidSurface then
QBCore.Functions.Notify(Lang:t('errors.invalid'), 'error', 7500)
else
Expand All @@ -249,7 +250,7 @@ function Spycam.StartPlacement()
end
end

if IsDisabledControlJustPressed(0, keys.cancel.button) then
if IsDisabledControlJustPressed(0, keys.cancel.key) then
SetScaleformMovieAsNoLongerNeeded(Scaleform.Buttons)
SetEntityAsMissionEntity(currentObject, true, true)
DeleteEntity(currentObject)
Expand Down Expand Up @@ -394,6 +395,14 @@ function Camera.Activate()
end
end

function Camera.IsControlPressed(control)
return IsDisabledControlPressed(0, control.key) and control.enabled
end

function Camera.IsControlJustPressed(control)
return IsDisabledControlJustPressed(0, control.key) and control.enabled
end

function Camera.Create()
local keys = Config.Controls.camera
local buttons = Scaleform.SetInstructionalButtons(keys)
Expand All @@ -410,21 +419,23 @@ function Camera.Create()
DisableAllControlActions(0)

-- Display instructional buttons
DrawScaleformMovieFullscreen(buttons, 255, 255, 255, 255, 0)
if not takingPhoto then
DrawScaleformMovieFullscreen(buttons, 255, 255, 255, 255, 0)
end

if not currentCam.inRange then
DrawMessage(0.5, 0.5, 0.8, 255, 255, 255, 255, Lang:t('general.nosignal'))
end

if IsDisabledControlJustPressed(0, 174) then
if Camera.IsControlJustPressed(keys.prev) then
if Spycam.activeIndex > 1 then
Spycam.activeIndex = Spycam.activeIndex - 1
else
Spycam.activeIndex = #ActiveCams
end

Camera.Activate()
elseif IsDisabledControlJustPressed(0, 175) then
elseif Camera.IsControlJustPressed(keys.next) then
if Spycam.activeIndex < #ActiveCams then
Spycam.activeIndex = Spycam.activeIndex + 1
else
Expand All @@ -435,52 +446,52 @@ function Camera.Create()
end

-- Exit the camera view
if IsDisabledControlJustPressed(0, keys.disconnect.button) then
if Camera.IsControlJustPressed(keys.disconnect)then
Spycam.Disconnect()
end

-- Self-destruct
if IsDisabledControlJustPressed(0, keys.destroy.button) then
if Camera.IsControlJustPressed(keys.destroy) then
Spycam.SelfDestruct(Spycam.activeIndex, currentCam)
end

if currentCam.inRange then
-- Camera movement controls
local camMoving = false

if IsDisabledControlPressed(0, keys.moveup.button) then
if Camera.IsControlPressed(keys.moveup) then
camMoving = true
currentCam.currentRotation.x = currentCam.currentRotation.x + Config.MoveStep
end

if IsDisabledControlPressed(0, keys.movedown.button) then
if Camera.IsControlPressed(keys.movedown) then
camMoving = true
currentCam.currentRotation.x = currentCam.currentRotation.x - Config.MoveStep
end

if IsDisabledControlPressed(0, keys.moveleft.button) then
if Camera.IsControlPressed(keys.moveleft) then
camMoving = true
currentCam.currentRotation.z = currentCam.currentRotation.z + Config.MoveStep
end

if IsDisabledControlPressed(0, keys.moveright.button) then
if Camera.IsControlPressed(keys.moveright) then
camMoving = true
currentCam.currentRotation.z = currentCam.currentRotation.z - Config.MoveStep
end
end

-- Camera zoom controls
if IsDisabledControlJustPressed(0, keys.zoomin.button) then
if Camera.IsControlJustPressed(keys.zoomin) then
currentCam.currentZoom = currentCam.currentZoom - Config.ZoomStep
currentCam.currentZoom = math.max(currentCam.currentZoom, Config.MinFOV)
SetCamFov(Spycam.Cam, currentCam.currentZoom)
elseif IsDisabledControlJustPressed(0, keys.zoomout.button) then
elseif Camera.IsControlJustPressed(keys.zoomout) then
currentCam.currentZoom = currentCam.currentZoom + Config.ZoomStep
currentCam.currentZoom = math.min(currentCam.currentZoom, Config.MaxFOV)
SetCamFov(Spycam.Cam, currentCam.currentZoom)
end
end

-- Camera vision mode controls
if IsDisabledControlJustPressed(0, keys.mode.button) then
if Camera.IsControlJustPressed(keys.mode) then
if currentCam.mode == 'normal' then
currentCam.mode = 'night'
SetNightvision(true)
Expand Down Expand Up @@ -639,8 +650,10 @@ function Scaleform.SetInstructionalButtons(data)
local index = 0

for id, btn in orderedPairs(data) do
Scaleform.AddInstuctionalButton(btn.label, btn.button, index)
index = index + 1
if btn.enabled then
Scaleform.AddInstuctionalButton(btn.label, btn.key, index)
index = index + 1
end
end

PushScaleformMovieFunction(Scaleform.Buttons, "DRAW_INSTRUCTIONAL_BUTTONS")
Expand Down Expand Up @@ -670,14 +683,6 @@ function Scaleform.SetButtonMessage(text)
EndTextCommandScaleformString()
end

function generateUUID()
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return string.gsub(template, '[xy]', function (c)
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
return string.format('%x', v)
end)
end


-- EVENT HANDLERS

Expand Down Expand Up @@ -749,25 +754,3 @@ end)
exports('Disconnect', function()
return Spycam.Disconnect()
end)


RegisterCommand('spycams:clean', function()
local hashes = {
[joaat('prop_cs_tablet')] = true,
[joaat('prop_spycam')] = true
}

local objects = GetGamePool('CObject')
local hash = joaat('prop_spycam')
for i = 1, #objects do
if hashes[GetEntityModel(objects[i])] then
print(hashes[GetEntityModel(objects[i])])
SetEntityAsMissionEntity(objects[i], true, true)
DeleteEntity(objects[i])
end
end
end)

RegisterCommand('spycams:place', function()
Spycam.StartPlacement()
end)
35 changes: 21 additions & 14 deletions config/config_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ Config.PlaceOnObjects = true -- Allows spycams to be placed on ob
Config.DrawOutline = true -- Draw outline during spy cam placement

-- Camera
Config.AllowRotation = true -- Enable the option to rotate the camera
Config.ScreenEffect = "heliGunCam" -- Screen effect when viewing the camera
Config.EffectStrength = 1.0 -- The strenght of the ScreenEffect between 0.0 and 1.0
Config.SignalDistance = 100 -- Maximum distance in meters before signal loss occurs
Config.MaxRotationX = 60.0 -- Maximum camera rotation on the x axis
Config.MaxRotationZ = 60.0 -- Maximum camera rotation on the z axis
Config.MaxRotationX = 20.0 -- Maximum camera rotation on the x axis
Config.MaxRotationZ = 20.0 -- Maximum camera rotation on the z axis
Config.DefaultFOV = 80.0 -- The default FOV of the camera
Config.MinFOV = 10.0 -- Minimum allowed FOV of the camera
Config.MaxFOV = 80.0 -- Maximum allowed FOV of the camera
Expand All @@ -32,28 +33,34 @@ Config.SelfDestructTime = 5 -- Time in seconds before spycam sel

-- Controls
Config.Controls = {
--!!!! DO NOT CHANGE THE TABLE KEYS UNLESS YOU KNOW WHAT YOU'RE DOING !!!!--
--!!!! DO NOT CHANGE THE TABLE KEYS !!!!--

-- Placement controls
['place'] = {
['cancel'] = { button = 25, label = Lang:t('controls.cancel') },
['place'] = { button = 24, label = Lang:t('controls.place') }
['cancel'] = { key = 25, enabled = true, label = Lang:t('controls.cancel') },
['place'] = { key = 24, enabled = true, label = Lang:t('controls.place') }
},

-- Camera controls
['camera'] = {
['disconnect'] = { button = 194, label = Lang:t('controls.disconnect') },
['destroy'] = { button = 73, label = Lang:t('controls.destroy') },
['mode'] = { button = 23, label = Lang:t('controls.mode') },
['zoomin'] = { button = 96, label = Lang:t('controls.zoomin') },
['zoomout'] = { button = 97, label = Lang:t('controls.zoomout') },
['moveright'] = { button = 35, label = Lang:t('controls.moveright') },
['movedown'] = { button = 33, label = Lang:t('controls.moveright') },
['moveleft'] = { button = 34, label = Lang:t('controls.moveleft') },
['moveup'] = { button = 32, label = Lang:t('controls.moveup')},
['disconnect'] = { key = 194, enabled = true, label = Lang:t('controls.disconnect') },
['destroy'] = { key = 73, enabled = true, label = Lang:t('controls.destroy') },
['mode'] = { key = 23, enabled = true, label = Lang:t('controls.mode') },
['zoomin'] = { key = 96, enabled = true, label = Lang:t('controls.zoomin') },
['zoomout'] = { key = 97, enabled = true, label = Lang:t('controls.zoomout') },
['moveright'] = { key = 35, enabled = Config.AllowRotation, label = Lang:t('controls.moveright') },
['movedown'] = { key = 33, enabled = Config.AllowRotation, label = Lang:t('controls.movedown') },
['moveleft'] = { key = 34, enabled = Config.AllowRotation, label = Lang:t('controls.moveleft') },
['moveup'] = { key = 32, enabled = Config.AllowRotation, label = Lang:t('controls.moveup')},
['next'] = { key = 175, enabled = true, label = Lang:t('controls.next')},
['prev'] = { key = 174, enabled = true, label = Lang:t('controls.prev')},
}
}

Config.SendNotification = function(message, notificationType)
exports['qb-core']:GetCoreObject().Functions.Notify(message, notificationType)
end

-- Callback fired when entering the camera view
Config.OnEnterCam = function()
TriggerEvent('hud:client:DisableHud')
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version '0.4.0'
shared_scripts {
'@qb-core/shared/locale.lua',
'locales/en.lua',
'shared/utils.lua',
}

server_scripts {
Expand All @@ -19,7 +20,6 @@ server_scripts {

client_scripts {
'config/config_client.lua',
'client/utils.lua',
'client/main.lua'
}

Expand Down
16 changes: 11 additions & 5 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ local Translations = {
place = "Place Spycam",
disconnect = "Disconnect",
destroy = "Self-destruct",
mode = "Vision Mode",
mode = "Mode",
zoomin = "Zoom In",
zoomout = "Zoom Out",
moveright = "Move Right",
movedown = "Move Down",
moveleft = "Move Left",
moveup = "Move Up",
moveright = "Right",
movedown = "Down",
moveleft = "Left",
moveup = "Up",
prev = "Previous Cam",
next = "Next Cam",
},

errors = {
Expand All @@ -24,6 +26,10 @@ local Translations = {
range = "Camera out of range - cannot send self-destruct signal",
},

notifications = {
placed = 'Camera Placed'
},

general = {
destroy = "Spy camera will self-destruct in %{time} seconds",
destroyed = "Spy camera destroyed",
Expand Down
10 changes: 9 additions & 1 deletion client/utils.lua → shared/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ end

function orderedPairs(t)
return orderedNext, t, nil
end
end

function generateUUID()
local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'
return string.gsub(template, '[xy]', function (c)
local v = (c == 'x') and math.random(0, 0xf) or math.random(8, 0xb)
return string.format('%x', v)
end)
end

0 comments on commit 64719ee

Please sign in to comment.