Skip to content

Commit

Permalink
v0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mobius1 committed Apr 8, 2023
1 parent 465c50f commit d26e3ba
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 29 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
# ms-spycams
Deployable spy cameras for QBCore


## Dependencies
* [qb-core](https://github.com/qbcore-framework/qb-core)
* [ox_target](https://github.com/overextended/ox_target)


## Install
* Drag `ms-spycams` into your `resources` directory
* Add `ensure ms-spycams` to your `server.cfg` AFTER `qb-core`
* The inventory images and items list are in the `INVENTORY` directory
* Adjust `config/config_client.lua` and `config/config_server.lua` to you liking
* Restart you server


## Usage
* Use the `spycam` item from your inventory to deploy a new spy camera
* Use the `spycam_tablet` item to connect to and control your deployed spy camera(s)
* Retrieve a spy camera by targeting it

If you don't want to utilise the `spycam_tablet` item, you can trigger the following events:
If you don't want to utilise the `spycam_tablet` item to connect to the deployed spy cameras, you can either use the command `spycams:connect` or ustilse the following exports from your scripts:

* `exports['ms-spycams']:Connect()` - Connects to deployed spy cameras
* `exports['ms-spycams']:Disconnect()` - Disconnects from deployed spy cameras

* `'spycams:client:connect'` - connects to the spy cameras (if any are deployed)
* `'spycams:client:disconnect'` - disconnects from the spy cameras

## Contributing
* Pull requests are welcome
97 changes: 76 additions & 21 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ local glm = require("glm")

-- Cache
local vec3 = vec3
local vec4 = vec4
local quat = quat
local glm_abs = glm.abs
local glm_deg = glm.deg
local glm_dot = glm.dot
local glm_rad = glm.rad
local glm_sign = glm.sign
local glm_approx = glm.approx
local glm_up = glm.up()
Expand Down Expand Up @@ -41,8 +38,11 @@ function Spycam.Add(entity, coords, rotation, onFloor)
SetEntityRotation(entity, rotation.x, rotation.y, rotation.z, 4)
FreezeEntityPosition(entity, true)
SetEntityCollision(entity, true, true)
SetEntityDrawOutline(entity, false)
SetEntityAlpha(entity, 0)

if Config.DrawOutline then
SetEntityDrawOutline(entity, false)
end

Streaming.RequestAnimDict(animDict)

Expand Down Expand Up @@ -125,10 +125,13 @@ function Spycam.StartPlacement()

Streaming.RequestModel(modelHash)
currentObject = CreateObject(modelHash, GetEntityCoords(player), true, true, true)
SetEntityDrawOutline(currentObject, true)
SetEntityDrawOutlineShader(1)
SetEntityCollision(currentObject, false, false)

if Config.DrawOutline then
SetEntityDrawOutline(currentObject, true)
SetEntityDrawOutlineShader(1)
end

placing = true

while placing do
Expand Down Expand Up @@ -158,21 +161,16 @@ function Spycam.StartPlacement()
(IsEntityAnObject(entity) and not Config.PlaceOnObjects) or
(isHorizontal and not Config.PlaceOnFloor)



local color = { r = 255, g = 255, b = 255, a = 255 }

if invalidSurface then
color.g = 0
color.b = 0
end

-- Limit height
if coords.z > pcoords.z + Config.MaxPlaceHeight then
coords = vec3(coords.x, coords.y, pcoords.z + Config.MaxPlaceHeight)
end

SetEntityDrawOutlineColor(color.r, color.g, color.b, color.a)
if Config.DrawOutline then
local color = { r = 255, g = invalidSurface and 0 or 255, b = invalidSurface and 0 or 255, a = 255 }
SetEntityDrawOutlineColor(color.r, color.g, color.b, color.a)
end

SetEntityCoordsNoOffset(currentObject, coords.x, coords.y, coords.z)
SetEntityRotation(currentObject, rotation.x, rotation.y, rotation.z, 4)

Expand Down Expand Up @@ -241,14 +239,30 @@ function Spycam.SelfDestruct(currentIndex, currentCam)
QBCore.Functions.Notify(Lang:t('general.destroy', { time = Config.SelfDestructTime }), 'error')

SetTimeout(Config.SelfDestructTime * 1000, function()
currentCam.destroyed = true

QBCore.Functions.Notify(Lang:t('general.destroyed'), 'success')
TriggerServerEvent('spycams:server:destroyed', currentCam.coords)
TriggerServerEvent('spycams:server:removed', true)

if currentIndex == Spycam.activeIndex then
SetTimecycleModifier("CAMERA_secuirity_FUZZ")
SetTimecycleModifierStrength(1.0)
SetExtraTimecycleModifier("NG_blackout")
SetExtraTimecycleModifierStrength(1.0)
end

Wait(3000)

Spycam.Remove(currentCam.entity)
TriggerServerEvent('spycams:server:removed', true)

Spycam.Disconnect()
Spycam.activeIndex = 1
if #ActiveCams == 0 then
Spycam.Disconnect()
Spycam.activeIndex = 1
else
Spycam.activeIndex = 1
Camera.Activate()
end
end)
end

Expand Down Expand Up @@ -300,15 +314,16 @@ function Camera.Activate()
ClearTimecycleModifier()
ClearExtraTimecycleModifier()

if dist > Config.SignalDistance then
if dist > Config.SignalDistance or currentCam.destroyed then
currentCam.inRange = false
SetTimecycleModifier("CAMERA_secuirity_FUZZ")
SetTimecycleModifierStrength(1.0)
SetExtraTimecycleModifier("NG_blackout")
SetExtraTimecycleModifierStrength(1.0)
else
currentCam.inRange = true
SetTimecycleModifier(Config.ScreenEffect)
SetTimecycleModifier(Config.ScreenEffect)
SetTimecycleModifierStrength(Config.EffectStrength)
end
end

Expand Down Expand Up @@ -507,6 +522,9 @@ function Raycast.RotationToDirection(rotation)
)
end


-- STREAMING

function Streaming.RequestAnimDict(dict)
if HasAnimDictLoaded(dict) then return end
RequestAnimDict(dict)
Expand All @@ -531,6 +549,9 @@ function Streaming.RequestPtfx(ptfx)
end
end


-- SCALEFORM

function Scaleform.SetInstructionalButtons(data)
if Scaleform.Buttons then
SetScaleformMovieAsNoLongerNeeded(Scaleform.Buttons)
Expand Down Expand Up @@ -583,6 +604,13 @@ function Scaleform.SetButtonMessage(text)
EndTextCommandScaleformString()
end


-- EVENT HANDLERS

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
TriggerEvent('chat:addSuggestion', '/spycams:connect', 'Connect to deployed spy cameras', {})
end)

RegisterNetEvent('spycams:client:place', function()
Spycam.StartPlacement()
end)
Expand All @@ -591,6 +619,10 @@ RegisterNetEvent('spycams:client:connect', function()
Spycam.Connect()
end)

RegisterNetEvent('spycams:client:diconnect', function()
Spycam.Disconnect()
end)

RegisterNetEvent('spycams:client:destroyed', function(coords)
Streaming.RequestPtfx('scr_xs_props')
UseParticleFxAssetNextCall('scr_xs_props')
Expand All @@ -609,3 +641,26 @@ AddEventHandler('onResourceStop', function(res)
if res ~= GetCurrentResourceName() then return end
Spycam.Disconnect()
end)


-- COMMANDS

RegisterCommand('spycams:connect', function()
Spycam.Connect()
end)

RegisterCommand('spycams:disconnect', function()
Spycam.Disconnect()
end)


-- EXPORTS

exports('Connect', function()
return Spycam.Connect()
end)

exports('Disconnect', function()
return Spycam.Disconnect()
end)

10 changes: 6 additions & 4 deletions config/config_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ Config = {}
-- Placement config
Config.MaxPlaceHeight = 0.6 -- Maximum allowed height above player in meters
Config.MaxPlaceDistance = 10.0 -- Maximum placement distance away from player in meters
Config.PlaceOnFloor = true -- Whether to allow spycams to be placed on the floor / horizontal surfaces
Config.PlaceOnObjects = true -- Whether to allow spycams to be placed on objects
Config.PlaceOnFloor = true -- Allows spycams to be placed on the floor / horizontal surfaces
Config.PlaceOnObjects = true -- Allows spycams to be placed on objects
Config.DrawOutline = true -- Draw outline during spy cam placement

-- Camera config
Config.ScreenEffect = "CAMERA_BW" -- Screen effect when viewing the camera
Config.SignalDistance = 50 -- Maximum distance in meters before signal loss occurs
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.DefaultFOV = 80.0 -- The default FOV of the camera
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lua54 'yes'

author 'Mobius1'
description 'Deployable spy cameras for QBCore'
version '0.1.0'
version '0.2.0'

shared_scripts {
'@qb-core/shared/locale.lua',
Expand Down

0 comments on commit d26e3ba

Please sign in to comment.