Skip to content

Commit

Permalink
v1.7.5
Browse files Browse the repository at this point in the history
Client sided cooldown
  • Loading branch information
lenzh authored May 27, 2019
1 parent 9f31320 commit fc0654f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 107 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ Chop shop for ESX
Feel free to edit the resource but make sure to pass it through and give me credits ;)

Credit:
I took Cooldown code from esx_carthief and made the necessary modification to make it work.
https://github.com/KlibrDM/esx_carthief
I took npc code from esx_cargodelivery
https://github.com/apoiat/esx_cargodelivery
and https://github.com/XxFri3ndlyxX for all his help ;)
Expand All @@ -16,7 +14,7 @@ So Big special thanks to those guys.
## Requirements
- es_extended (https://github.com/ESX-Org/es_extended)
- pNotify (https://github.com/Nick78111/pNotify)
- ProgressBars (https://github.com/chipsahoy6/progressBars/releases)
- progressBars (https://github.com/chipsahoy6/progressBars/releases)

## Download & Installation

Expand Down
3 changes: 2 additions & 1 deletion __resource.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

description 'Lenzh Chop Shop'

version '1.2.0'
version '1.7.5'

server_scripts {
'@es_extended/locale.lua',
Expand All @@ -21,6 +21,7 @@ client_scripts {
'client/main.lua',
}


dependency {
'es_extended',
'pNotify',
Expand Down
127 changes: 39 additions & 88 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Citizen.CreateThread(function()
end
else
if wasOpen then
--wasOpen = false
wasOpen = false
ESX.UI.Menu.CloseAll()
end

Expand All @@ -60,7 +60,6 @@ Citizen.CreateThread(function()
end)

function OpenShop()
ESX.UI.Menu.CloseAll()
local elements = {}
menuOpen = true

Expand Down Expand Up @@ -94,105 +93,57 @@ function OpenShop()
end)
end

AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
if menuOpen then
ESX.UI.Menu.CloseAll()
end
end
end)


function IsDriver()
return GetPedInVehicleSeat(GetVehiclePedIsIn(PlayerPedId(), false), -1) == PlayerPedId()
end

function MaxSeat()
local veh = GetVehiclePedIsIn(PlayerPedId())
if GetVehicleMaxNumberOfPassengers(veh) >= 1 then
NoPassengerAllowed()
end
if GetVehicleMaxNumberOfPassengers(veh) <= 1 then
NoPassengerAllowed1()
end
end

function NoPassengerAllowed()
local veh1 = GetVehiclePedIsIn(PlayerPedId())
local veh2 = GetPedInVehicleSeat(PlayerPedId())
if veh2 then
if IsVehicleSeatFree(veh1,0) and IsVehicleSeatFree(veh1,1) and IsVehicleSeatFree(veh1,2) and not IsVehicleSeatFree(veh1,-1) then
ChopVehicle()
end
end
end

function NoPassengerAllowed1()
local veh3 = GetVehiclePedIsIn(PlayerPedId())
local veh4 = GetPedInVehicleSeat(PlayerPedId())
if veh3 then
if IsVehicleSeatFree(veh3,0) then
ChopVehicle()
end
end
end

function MaxSeat()
local veh = GetVehiclePedIsIn(GetPlayerPed(-1))
if GetVehicleMaxNumberOfPassengers(veh) >= 1 then
NoPassengerAllowed()
end
if GetVehicleMaxNumberOfPassengers(veh) <= 1 then
NoPassengerAllowed1()
end
function MaxSeats(vehicle)
local vehpas = GetVehicleNumberOfPassengers(vehicle)
return vehpas
end

function NoPassengerAllowed()
local veh1 = GetVehiclePedIsIn(GetPlayerPed(-1))
local veh2 = GetPedInVehicleSeat(GetPlayerPed(-1))
if veh2 then
if IsVehicleSeatFree(veh1,0) and IsVehicleSeatFree(veh1,1) and IsVehicleSeatFree(veh1,2) and not IsVehicleSeatFree(veh1,-1) then
ChopVehicle()
else
exports.pNotify:SendNotification({text = "Cannot Chop if passenger abord", type = "error", timeout = 5000, layout = "centerRight", queue = "right", animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
local lastTested = 0
function ChopVehicle()
local seats = MaxSeats(vehicle)
if seats ~= 0 then
TriggerEvent('chat:addMessage', { args = { '[^1Chopshop^0]: Cannot chop with passengers' } })
elseif
GetGameTimer() - lastTested > Config.CooldownMinutes * 60000 then
lastTested = GetGameTimer()
if Config.CallCops then
local randomReport = math.random(1, Config.CallCopsPercent)

if randomReport == Config.CallCopsPercent then
TriggerServerEvent('chopNotify')
end
end
end
end

function NoPassengerAllowed1()
local veh3 = GetVehiclePedIsIn(GetPlayerPed(-1))
local veh4 = GetPedInVehicleSeat(GetPlayerPed(-1))
if veh3 then
if IsVehicleSeatFree(veh3,0) then
ChopVehicle()
else
exports.pNotify:SendNotification({text = "Cannot Chop if passenger abord", type = "error", timeout = 5000, layout = "centerRight", queue = "right", animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn( ped, false )
ChoppingInProgress = true
VehiclePartsRemoval()
if not HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = true
ChoppingInProgress = false
exports.pNotify:SendNotification({text = "You Left The Zone. No Rewards For You", type = "error", timeout = 1000, layout = "centerRight", queue = "right", killer = true, animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
SetVehicleAlarmTimeLeft(vehicle, 60000)
end
else
ESX.ShowNotification('Comeback at a later time')
end
end




--if GetVehicleMaxNumberOfPassengers(veh) > 1 then
function ChopVehicle()
ESX.TriggerServerCallback('Lenzh_chopshop:isCooldown', function(cooldown)
if cooldown <= 0 then
if Config.CallCops then
local randomReport = math.random(1, Config.CallCopsPercent)

if randomReport == Config.CallCopsPercent then
TriggerServerEvent('chopNotify')
end
end
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn( ped, false )
ChoppingInProgress = true
VehiclePartsRemoval()
if not HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = true
ChoppingInProgress = false
exports.pNotify:SendNotification({text = "You Left The Zone. No Rewards For You", type = "error", timeout = 1000, layout = "centerRight", queue = "right", killer = true, animation = {open = "gta_effects_fade_in", close = "gta_effects_fade_out"}})
SetVehicleAlarmTimeLeft(vehicle, 60000)
end
else
ESX.ShowNotification(_U('cooldown', math.ceil(cooldown/1000)))
end

end)
end

function VehiclePartsRemoval()
local ped = PlayerPedId()
local vehicle = GetVehiclePedIsIn( ped, false )
Expand Down Expand Up @@ -409,7 +360,7 @@ Citizen.CreateThread(function()
if IsControlJustReleased(0, 38) then
if IsDriver() then
if CurrentAction == 'Chopshop' then
MaxSeat()
ChopVehicle()
end
end
CurrentAction = nil
Expand Down
18 changes: 3 additions & 15 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
ESX = nil
local cooldown = 0


TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

ESX.RegisterServerCallback('Lenzh_chopshop:isCooldown',function(source, cb)
cb(cooldown)
end)


RegisterServerEvent("lenzh_chopshop:rewards")
AddEventHandler("lenzh_chopshop:rewards", function(rewards)
Expand All @@ -17,8 +15,7 @@ AddEventHandler("lenzh_chopshop:rewards", function(rewards)
local randomCount = math.random(0, 3)
xPlayer.addInventoryItem(v, randomCount)
end
--Add cooldown
cooldown = Config.CooldownMinutes * 60000 --DO NOT EDIT

end)

--[[ function Rewards(rewards)
Expand Down Expand Up @@ -79,12 +76,3 @@ AddEventHandler('lenzh_chopshop:sell', function(itemName, amount)
TriggerClientEvent('esx:showNotification', source, _U('sold', amount, xItem.label, ESX.Math.GroupDigits(price)))
end)

--Cooldown manager
AddEventHandler('onResourceStart', function(resource)
while true do
Wait(5000)
if cooldown > 0 then
cooldown = cooldown - 5000
end
end
end)

0 comments on commit fc0654f

Please sign in to comment.