Skip to content

Commit

Permalink
Update v1.5
Browse files Browse the repository at this point in the history
* Added Job Blips if break through the door
* Added Events for other Scripts when blackout is triggered
  • Loading branch information
Musiker15 committed Mar 11, 2023
1 parent 50f4d24 commit 9dfe371
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 14 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,38 @@ Preview: https://streamable.com/mzvoe5

If you don't want to use the `ox_lib` Skillbar then remove it from `fxmanifest.lua`

## Events
If you want to implement a Listener to other Scripts, so the Job Notifications f.e. Robberies won't get triggert then add this to your scripts.

**It works clientside and serverside**
```lua
local isBlackout = false -- Add this at the TOP of your client file

blackoutPowerOn = function()
isBlackout = false
end

blackoutPowerOff = function()
isBlackout = true
end

AddEventHandler('msk_blackout:powerOn', blackoutPowerOn)
AddEventHandler('msk_blackout:powerOff', blackoutPowerOff)
```
**Example**
```lua
if not isBlackout then -- Only if Power is ON the Notification to Cops will be triggered
TriggerClientEvent('notifyCops', -1)
end
```

## Requirements
* [ESX 1.2 and above](https://github.com/esx-framework/esx_core) or [QBCore](https://github.com/qbcore-framework)
* [msk_core](https://github.com/MSK-Scripts/msk_core)
* [oxmysql](https://github.com/overextended/oxmysql) - *ox_doorlock*
* [ox_lib](https://github.com/overextended/ox_lib) - *Skillbar*
* [datacrack by utkuali](https://github.com/utkuali/datacrack) - *Hacking Minigame*
* [oxmysql](https://github.com/overextended/oxmysql) - *ox_doorlock*

## Optional Requirements
* [doors_creator by Jaksam](https://www.jaksam-scripts.com/) - *To unlock all doors while blackout*
* [ox_doorlock](https://github.com/overextended/ox_doorlock) - *To unlock all doors while blackout*
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.1
1.5
49 changes: 42 additions & 7 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ end

local startedBlackout, startBlackoutTeleport, hackedLaptop = false, false, false
local showHackLaptopHelp, teleportedOutOfBuilding, startedSabotage = false, false, false
local setBlackout = false
local Blips, SabotageLocations = {}, {}
local addTimeout, setBlackout, sendJobNotify, sendJobBlip = false, false, true, true
local Blips, JobBlips, SabotageLocations = {}, {}, {}

CreateThread(function()
local blip = Config.startPoint.blip
Expand Down Expand Up @@ -97,8 +97,8 @@ CreateThread(function()
end

if success then
TriggerServerEvent('msk_blackout:removeItem', hasItem.name)
startedBlackout = true
TriggerServerEvent('msk_blackout:removeItem', hasItem.name)
blackoutTeleport()
end
else
Expand Down Expand Up @@ -171,6 +171,7 @@ CreateThread(function()
exports["datacrack"]:Start(4)
else
teleportOutOfBuilding('return')
sendJobBlipNotify(true)
Config.Notification(nil, Translation[Config.Locale]['no_items']:format(hasItem.label))
end
end
Expand Down Expand Up @@ -346,25 +347,59 @@ stopBlackoutTask = function(success)
end

stopBlackout = function()
sendJobBlip = false
TriggerServerEvent('msk_blackout:syncBlackout', false)
end

RegisterCommand('blackouton', function(source, args, raw)
stopBlackoutTask(true)
end)

RegisterNetEvent('msk_blackout:setBlackout')
AddEventHandler('msk_blackout:setBlackout', function(state)
setBlackout = state

if state then
TriggerEvent('msk_blackout:powerOff')
TriggerServerEvent('msk_blackout:powerOff')

addTimeout = MSK.AddTimeout(Config.Blackout.duration * 60000, function()
stopBlackout()
MSK.DelTimeout(addTimeout)
end)
else
stopBlackout()
MSK.DelTimeout(addTimeout)
TriggerEvent('msk_blackout:powerOn')
TriggerServerEvent('msk_blackout:powerOn')
end
end)

AddEventHandler('msk_blackout:powerOff', function()
sendJobBlipNotify(true)
end)

RegisterNetEvent('msk_blackout:sendJobBlipNotify')
AddEventHandler('msk_blackout:sendJobBlipNotify', function()
sendJobBlipNotify()
end)

sendJobBlipNotify = function(notify)
CreateThread(function()
for k, v in pairs(JobBlips) do
RemoveBlip(v)
JobBlips = {}
end

if notify then return end

if Config.Cops.blip.enable then
local blip = AddBlipForRadius(Config.startPoint.coords.x, Config.startPoint.coords.y, Config.startPoint.coords.z, 50.0)

SetBlipColour(blip, Config.Cops.blip.color)
SetBlipAlpha(blip, 128)

table.insert(JobBlips, blip)
end
end)
end

if not Config.useWeatherScript then
CreateThread(function()
while true do
Expand Down
6 changes: 3 additions & 3 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Config.Items = { -- Add those items to your database or inventory
Config.Blackout = {
generalLights = true, -- Set to true turns off all artificial light sources in the map
vehicleLights = true, -- Set to false ignores Vehicles

duration = 1 -- in minutes // Blackout Time
}

Expand All @@ -41,9 +40,10 @@ Config.weatherScript = function(state) -- This is a Server Event
end
----------------------------------------------------------------
Config.Cops = {
enable = false,
enable = true,
jobs = {'police', 'fib', 'sheriff'},
amount = 2 -- Minimum amount of Online Players with Police Job
amount = 1, -- Minimum amount of Online Players with Police Job
blip = {enable = true, color = 1},
}

Config.blacklistedJobs = {
Expand Down
4 changes: 2 additions & 2 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ games { 'gta5' }
author 'Musiker15 - MSK Scripts'
name 'msk_blackout'
description 'Weather Blackout Miniheist'
version '1.4.1'
version '1.5'

lua54 'yes'

shared_script {
shared_scripts {
'@msk_core/import.lua',
'@ox_lib/init.lua',
'config.lua',
Expand Down
5 changes: 5 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ AddEventHandler('msk_blackout:notifyJobs', function()

if MSK.Table_Contains(Config.notifyJobs.jobs, xPlayer.job.name) then
Config.Notification(xPlayer.source, Translation[Config.Locale]['job_notify_blackout_started'])
TriggerClientEvent('msk_blackout:sendJobBlipNotify', xPlayer.source)
end
end
elseif Config.Framework:match('QBCore') then
Expand All @@ -34,6 +35,7 @@ AddEventHandler('msk_blackout:notifyJobs', function()

if MSK.Table_Contains(Config.notifyJobs.jobs, Player.PlayerData.job.name) then
Config.Notification(Player.PlayerData.source, Translation[Config.Locale]['job_notify_blackout_started'])
TriggerClientEvent('msk_blackout:sendJobBlipNotify', Player.PlayerData.source)
end
end
end
Expand All @@ -47,6 +49,9 @@ AddEventHandler('msk_blackout:syncBlackout', function(state)
TriggerClientEvent('msk_blackout:setBlackout', -1, state)

if not Config.useDoorlock then return end
if not (GetResourceState(Config.DoorlockScript) == "started") then
return logging('error', 'Doorlock script ' .. Config.DoorlockScript .. ' not found')
end

if state then -- If Blackout is enabled
if Config.DoorlockScript:match('doors_creator') then
Expand Down

0 comments on commit 9dfe371

Please sign in to comment.