From d26e3ba09f8c7c36468687262667deeb7ef05e0b Mon Sep 17 00:00:00 2001 From: Mobius1 Date: Sat, 8 Apr 2023 17:45:42 +0100 Subject: [PATCH] v0.2.0 --- README.md | 10 +++-- client/main.lua | 97 +++++++++++++++++++++++++++++++--------- config/config_client.lua | 10 +++-- fxmanifest.lua | 2 +- 4 files changed, 90 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index fd343b1..930e3f7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # 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` @@ -12,15 +14,17 @@ * 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 diff --git a/client/main.lua b/client/main.lua index b316e68..d22650f 100644 --- a/client/main.lua +++ b/client/main.lua @@ -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() @@ -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) @@ -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 @@ -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) @@ -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 @@ -300,7 +314,7 @@ 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) @@ -308,7 +322,8 @@ function Camera.Activate() SetExtraTimecycleModifierStrength(1.0) else currentCam.inRange = true - SetTimecycleModifier(Config.ScreenEffect) + SetTimecycleModifier(Config.ScreenEffect) + SetTimecycleModifierStrength(Config.EffectStrength) end end @@ -507,6 +522,9 @@ function Raycast.RotationToDirection(rotation) ) end + +-- STREAMING + function Streaming.RequestAnimDict(dict) if HasAnimDictLoaded(dict) then return end RequestAnimDict(dict) @@ -531,6 +549,9 @@ function Streaming.RequestPtfx(ptfx) end end + +-- SCALEFORM + function Scaleform.SetInstructionalButtons(data) if Scaleform.Buttons then SetScaleformMovieAsNoLongerNeeded(Scaleform.Buttons) @@ -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) @@ -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') @@ -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) + diff --git a/config/config_client.lua b/config/config_client.lua index 5452ce5..62fbb8d 100644 --- a/config/config_client.lua +++ b/config/config_client.lua @@ -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 diff --git a/fxmanifest.lua b/fxmanifest.lua index d347ca7..c6f9d5c 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -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',