Merge pull request #9 from newt74/main

[esx_holdup] Optimized and fixed bug when the robbery has been canceled.
This commit is contained in:
ESXCrackhead
2021-07-07 15:12:33 -05:00
committed by GitHub
3 changed files with 65 additions and 84 deletions
+21 -27
View File
@@ -1,18 +1,19 @@
local holdingUp = false
local store = ""
local store = ''
local blipRobbery = nil
function drawTxt(x,y, width, height, scale, text, r,g,b,a, outline)
function DrawTxt(x,y, width, height, scale, text, r, g, b, a, outline)
SetTextFont(0)
SetTextScale(scale, scale)
SetTextColour(r, g, b, a)
SetTextDropshadow(0, 0, 0, 0,255)
SetTextDropShadow()
if outline then SetTextOutline() end
if outline then
SetTextOutline()
end
BeginTextCommandDisplayText('STRING')
AddTextComponentSubstringPlayerName(text)
EndTextCommandDisplayText(x - width/2, y - height/2 + 0.005)
EndTextCommandDisplayText(x - width / 2, y - height / 2 + 0.005)
end
RegisterNetEvent('esx_holdup:currentlyRobbing')
@@ -27,12 +28,10 @@ end)
RegisterNetEvent('esx_holdup:setBlip')
AddEventHandler('esx_holdup:setBlip', function(position)
blipRobbery = AddBlipForCoord(position.x, position.y, position.z)
blipRobbery = AddBlipForCoord(position)
SetBlipSprite(blipRobbery, 161)
SetBlipScale(blipRobbery, 2.0)
SetBlipColour(blipRobbery, 3)
PulseBlip(blipRobbery)
end)
@@ -51,33 +50,29 @@ end)
RegisterNetEvent('esx_holdup:startTimer')
AddEventHandler('esx_holdup:startTimer', function()
local timer = Stores[store].secondsRemaining
Citizen.CreateThread(function()
while timer > 0 and holdingUp do
Citizen.Wait(1000)
if timer > 0 then
timer = timer - 1
end
end
end)
Citizen.CreateThread(function()
while holdingUp do
Citizen.Wait(0)
drawTxt(0.66, 1.44, 1.0, 1.0, 0.4, _U('robbery_timer', timer), 255, 255, 255, 255)
Citizen.Wait(1)
DrawTxt(0.66, 1.44, 1.0, 1.0, 0.4, _U('robbery_timer', timer), 255, 255, 255, 255)
end
end)
end)
Citizen.CreateThread(function()
for k,v in pairs(Stores) do
local blip = AddBlipForCoord(v.position.x, v.position.y, v.position.z)
local blip = AddBlipForCoord(v.position)
SetBlipSprite(blip, 156)
SetBlipScale(blip, 0.8)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
BeginTextCommandSetBlipName('STRING')
AddTextComponentString(_U('shop_robbery'))
EndTextCommandSetBlipName(blip)
end
@@ -86,19 +81,15 @@ end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local playerPos = GetEntityCoords(PlayerPedId(), true)
local playerPos, letSleep = GetEntityCoords(PlayerPedId()), true
for k,v in pairs(Stores) do
local storePos = v.position
local distance = Vdist(playerPos.x, playerPos.y, playerPos.z, storePos.x, storePos.y, storePos.z)
local distance = #(playerPos - v.position)
if distance < Config.Marker.DrawDistance then
if not holdingUp then
DrawMarker(Config.Marker.Type, storePos.x, storePos.y, storePos.z - 1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Marker.x, Config.Marker.y, Config.Marker.z, Config.Marker.r, Config.Marker.g, Config.Marker.b, Config.Marker.a, false, false, 2, false, false, false, false)
letSleep = false
DrawMarker(Config.Marker.Type, v.position, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Marker.x, Config.Marker.y, Config.Marker.z, Config.Marker.r, Config.Marker.g, Config.Marker.b, Config.Marker.a, false, false, 2, false, false, false, false)
if distance < 0.5 then
ESX.ShowHelpNotification(_U('press_to_rob', v.nameOfStore))
if IsControlJustReleased(0, 38) then
if IsPedArmed(PlayerPedId(), 4) then
TriggerServerEvent('esx_holdup:robberyStarted', k)
@@ -108,14 +99,17 @@ Citizen.CreateThread(function()
end
end
end
break
end
end
if holdingUp then
local storePos = Stores[store].position
if Vdist(playerPos.x, playerPos.y, playerPos.z, storePos.x, storePos.y, storePos.z) > Config.MaxDistance then
letSleep = false
if #(playerPos - Stores[store].position) > Config.MaxDistance then
TriggerServerEvent('esx_holdup:tooFar', store)
end
end
if letSleep then
Citizen.Wait(500)
end
end
end)
+27 -27
View File
@@ -14,66 +14,66 @@ Config.MaxDistance = 20 -- max distance from the robbary, going any longer
Config.GiveBlackMoney = true -- give black money? If disabled it will give cash instead
Stores = {
["paleto_twentyfourseven"] = {
position = { x = 1736.32, y = 6419.47, z = 35.03 },
['paleto_twentyfourseven'] = {
position = vector3(1736.32, 6419.47, 34.03),
reward = math.random(5000, 35000),
nameOfStore = "24/7. (Paleto Bay)",
nameOfStore = '24/7. (Paleto Bay)',
secondsRemaining = 350, -- seconds
lastRobbed = 0
},
["sandyshores_twentyfoursever"] = {
position = { x = 1961.24, y = 3749.46, z = 32.34 },
['sandyshores_twentyfoursever'] = {
position = vector3(1961.24, 3749.46, 31.34),
reward = math.random(3000, 20000),
nameOfStore = "24/7. (Sandy Shores)",
nameOfStore = '24/7. (Sandy Shores)',
secondsRemaining = 200, -- seconds
lastRobbed = 0
},
["littleseoul_twentyfourseven"] = {
position = { x = -709.17, y = -904.21, z = 19.21 },
['littleseoul_twentyfourseven'] = {
position = vector3(-709.17, -904.21, 18.21),
reward = math.random(3000, 20000),
nameOfStore = "24/7. (Little Seoul)",
nameOfStore = '24/7. (Little Seoul)',
secondsRemaining = 200, -- seconds
lastRobbed = 0
},
["bar_one"] = {
position = { x = 1990.57, y = 3044.95, z = 47.21 },
['bar_one'] = {
position = vector3(1990.57, 3044.95, 46.21),
reward = math.random(5000, 35000),
nameOfStore = "Yellow Jack. (Sandy Shores)",
nameOfStore = 'Yellow Jack. (Sandy Shores)',
secondsRemaining = 300, -- seconds
lastRobbed = 0
},
["ocean_liquor"] = {
position = { x = -2959.33, y = 388.21, z = 14.00 },
['ocean_liquor'] = {
position = vector3(-2959.33, 388.21, 13.00),
reward = math.random(3000, 30000),
nameOfStore = "Robs Liquor. (Great Ocean Highway)",
nameOfStore = 'Robs Liquor. (Great Ocean Highway)',
secondsRemaining = 200, -- seconds
lastRobbed = 0
},
["rancho_liquor"] = {
position = { x = 1126.80, y = -980.40, z = 45.41 },
['rancho_liquor'] = {
position = vector3(1126.80, -980.40, 44.41),
reward = math.random(3000, 50000),
nameOfStore = "Robs Liquor. (El Rancho Blvd)",
nameOfStore = 'Robs Liquor. (El Rancho Blvd)',
secondsRemaining = 200, -- seconds
lastRobbed = 0
},
["sanandreas_liquor"] = {
position = { x = -1219.85, y = -916.27, z = 11.32 },
['sanandreas_liquor'] = {
position = vector3(-1219.85, -916.27, 10.32),
reward = math.random(3000, 30000),
nameOfStore = "Robs Liquor. (San Andreas Avenue)",
nameOfStore = 'Robs Liquor. (San Andreas Avenue)',
secondsRemaining = 200, -- seconds
lastRobbed = 0
},
["grove_ltd"] = {
position = { x = -43.40, y = -1749.20, z = 29.42 },
['grove_ltd'] = {
position = vector3(-43.40, -1749.20, 28.42),
reward = math.random(3000, 15000),
nameOfStore = "LTD Gasoline. (Grove Street)",
nameOfStore = 'LTD Gasoline. (Grove Street)',
secondsRemaining = 200, -- seconds
lastRobbed = 0
},
["mirror_ltd"] = {
position = { x = 1160.67, y = -314.40, z = 69.20 },
['mirror_ltd'] = {
position = vector3(1160.67, -314.40, 68.20),
reward = math.random(3000, 15000),
nameOfStore = "LTD Gasoline. (Mirror Park Boulevard)",
nameOfStore = 'LTD Gasoline. (Mirror Park Boulevard)',
secondsRemaining = 200, -- seconds
lastRobbed = 0
}
+17 -30
View File
@@ -9,10 +9,10 @@ AddEventHandler('esx_holdup:tooFar', function(currentStore)
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('robbery_cancelled_at', Stores[currentStore].nameOfStore))
TriggerClientEvent('esx_holdup:killBlip', xPlayer.source)
end
if robbers[_source] then
TriggerClientEvent('esx_holdup:tooFar', _source)
robbers[_source] = nil
ESX.ClearTimeout(robbers[_source])
robbers[_source] = nil
TriggerClientEvent('esx:showNotification', _source, _U('robbery_cancelled_at', Stores[currentStore].nameOfStore))
end
end)
@@ -21,53 +21,40 @@ RegisterServerEvent('esx_holdup:robberyStarted')
AddEventHandler('esx_holdup:robberyStarted', function(currentStore)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
if Stores[currentStore] then
local store = Stores[currentStore]
if (os.time() - store.lastRobbed) < Config.TimerBeforeNewRob and store.lastRobbed ~= 0 then
TriggerClientEvent('esx:showNotification', _source, _U('recently_robbed', Config.TimerBeforeNewRob - (os.time() - store.lastRobbed)))
return
end
if not rob then
local xPlayers = ESX.GetExtendedPlayers('job', 'police')
if #xPlayers >= Config.PoliceNumberRequired then
rob = true
for _, xPlayer in pairs(xPlayers) do
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('rob_in_prog', store.nameOfStore))
TriggerClientEvent('esx_holdup:setBlip', xPlayer.source, Stores[currentStore].position)
end
TriggerClientEvent('esx:showNotification', _source, _U('started_to_rob', store.nameOfStore))
TriggerClientEvent('esx:showNotification', _source, _U('alarm_triggered'))
TriggerClientEvent('esx_holdup:currentlyRobbing', _source, currentStore)
TriggerClientEvent('esx_holdup:startTimer', _source)
Stores[currentStore].lastRobbed = os.time()
robbers[_source] = currentStore
SetTimeout(store.secondsRemaining * 1000, function()
if robbers[_source] then
rob = false
if xPlayer then
TriggerClientEvent('esx_holdup:robberyComplete', _source, store.reward)
if Config.GiveBlackMoney then
xPlayer.addAccountMoney('black_money', store.reward)
else
xPlayer.addMoney(store.reward)
end
local xPlayers = ESX.GetExtendedPlayers('job', 'police')
for _, xPlayer in pairs(xPlayers) do
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('robbery_complete_at', store.nameOfStore))
TriggerClientEvent('esx_holdup:killBlip', xPlayer.source)
end
end
end
robbers[_source] = ESX.SetTimeout(store.secondsRemaining * 1000, function()
rob = false
if xPlayer then
TriggerClientEvent('esx_holdup:robberyComplete', _source, store.reward)
if Config.GiveBlackMoney then
xPlayer.addAccountMoney('black_money', store.reward)
else
xPlayer.addMoney(store.reward)
end
local xPlayers = ESX.GetExtendedPlayers('job', 'police')
for _, xPlayer in pairs(xPlayers) do
TriggerClientEvent('esx:showNotification', xPlayer.source, _U('robbery_complete_at', store.nameOfStore))
TriggerClientEvent('esx_holdup:killBlip', xPlayer.source)
end
end
end)
else
TriggerClientEvent('esx:showNotification', _source, _U('min_police', Config.PoliceNumberRequired))