Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

(need help) refactor, add v2 and mdt support #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions config_client.lua

This file was deleted.

4 changes: 0 additions & 4 deletions config_server.lua

This file was deleted.

49 changes: 49 additions & 0 deletions data/configuration.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
return {
shotSpotterDelay = 10, -- delay (in seconds) when cops will receive a notification after there has been a shooting.
shotSpotterCooldown = 30, -- Cooldown for the next time a player can trigger it again.

postalResourceName = 'nearest-postal', -- set to false to disable, the resource name of the nearest postal script, this is used for the export.

whitelistedJobs = { -- jobs that won't trigger shot spotter
["lspd"] = true,
["bcso"] = true,
["sahp"] = true
},

-- Weapon that won't be triggered by the shot spotter.
weaponBlackList = {
`weapon_flaregun`,
`weapon_stungun_mp`,
`weapon_grenade`,
`weapon_bzgas`,
`weapon_molotov`,
`weapon_stickybomb`,
`weapon_proxmine`,
`weapon_snowball`,
`weapon_pipebomb`,
`weapon_ball`,
`weapon_smokegrenade`,
`weapon_flare`,
`weapon_petrolcan`,
`weapon_fireextinguisher`,
`weapon_hazardcan`,
`weapon_fertilizercan`
},

realisticShotSpotter = { -- set to false to disable, this is if you want to enable the shot spotter only when the player is inside one of the zones below. The zones are in the city and a little around it.
{x = 653.4214, y = -648.7440, z = 57.1897},
{x = 1015.9837, y = -255.2573, z = 85.5857},
{x = 329.9973, y = 288.9604, z = 120.1029},
{x = -202.7689, y = -327.3490, z = 66.0497},
{x = 31.3205, y = -875.2959, z = 31.4629},
{x = 70.1372, y = -1718.3291, z = 34.2056},
{x = 1196.9178, y = -1624.6641, z = 50.3403},
{x = -852.9095, y = -1215.8782, z = 9.2463},
{x = -932.7648, y = -448.8844, z = 42.9436},
{x = -1713.6848, y = 478.4267, z = 130.3795},
{x = -596.5602, y = 515.0753, z = 109.675},
{x = 716.6274, y = -1958.7434, z = 44.7564}
},

testing = false -- if you're adding zones above and want to enable the blips on the map to see where the zone is then turn this on, otherwise turn it off.
}
35 changes: 20 additions & 15 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
-- For support join my discord: https://discord.gg/Z9Mxu72zZ6

author "Andyyy#7666, N1K0#0001"
description "Shot Spotter Script (ND Framework)"
version "2.1.0"
fx_version 'cerulean'
game 'gta5'
lua54 'yes'

fx_version "cerulean"
game "gta5"
lua54 "yes"
author 'Andyyy#7666, N1K0#0001'
description 'Shot Spotter Script (ND Framework)'
version '2.1.0'

server_scripts {
"config_server.lua",
"source/server.lua"
}
client_scripts {
"config_client.lua",
"source/client.lua"
}
shared_scripts {
'@ND_Core/init.lua',
'@ox_lib/init.lua',
'data/configuration.lua'
}

dependency "ND_Core"
server_script 'source/server/main.lua'

client_script 'source/client/main.lua'

dependencies {
'ND_Core',
'ND_MDT',
'ox_lib'
}
156 changes: 0 additions & 156 deletions source/client.lua

This file was deleted.

72 changes: 72 additions & 0 deletions source/client/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
-- For support join my discord: https://discord.gg/Z9Mxu72zZ6

local alreadyShot = false
local config = lib.load("data.configuration")

-- check if the players location is inside the shot spotter locations, this will only be used in the code when realistic shot spotter is turned on.
local function isInShotSpotterLocation(coords)
for _, location in pairs(config.realisticShotSpotter) do
if #(coords - vector3(location.x, location.y, location.z)) < 450.0 then return true end
end
return false
end

function triggerShotSpotter(ped)
local player = NDCore.getPlayer()
local job = player.job.name
local coords = GetEntityCoords(ped)
local suppressed = IsPedCurrentWeaponSilenced(ped)
local currentWeapon = cache.weapon
local zoneName = GetLabelText(GetNameOfZone(coords.x, coords.y, coords.z))
local street = GetStreetNameAtCoord(coords.x, coords.y, coords.z)
local streetHash = GetStreetNameFromHashKey(street)

if config.postalResourceName then postal = exports[config.postalResourceName]:getPostal()
else postal = false end

if config.realisticShotSpotter and not isInShotSpotterLocation(coords) then return end -- if the player isn't in the realistic shot spotter locations then the shot spotter won't trigger.

for _, weapon in pairs(config.weaponBlackList) do -- if the player has a blacklisted weapon then the shot spotter won't trigger.
if weapon == currentWeapon then return end
end

if suppressed then return end -- if the player has a suppresor attached to their weapon then the shot spotter won't trigger.

if config.whitelistedJobs[job] then return end -- if the player has the job then they won't trigger the shotspotter.

if alreadyShot then return end -- the alreadyShot variable is used for checking if the player has already shot and to add a cooldown until it turns to false.

alreadyShot = true
Wait(config.shotSpotterDelay * 1000)
TriggerServerEvent('ND_ShotSpotter:Trigger', streetHash, coords, postal, zoneName)
Wait(config.shotSpotterCooldown * 1000)
alreadyShot = false
end

--
-- NEED TO FIND BETTER METHOD OF THESE THREADS
--

CreateThread(function() -- Check if the player is shooting.
while true do
Wait(0)
local ped = cache.ped
if IsPedShooting(ped) then
triggerShotSpotter(ped)
end
end
end)

if config.testing then
CreateThread(function()
Wait(0)
for k, v in pairs(config.realisticShotSpotterLocations) do
k = AddBlipForRadius(v.x, v.y, v.z, 450.0)
SetBlipAlpha(k, 100)
end
end)
end

--
-- NEED TO FIND BETTER METHOD OF THESE THREADS
--
Loading