Scripts/resources/[qb]/[qb_jobs]/qb-gardening/client/client.lua

306 lines
8.8 KiB
Lua
Raw Permalink Normal View History

2024-12-29 20:06:22 +00:00
QBCore = exports['qb-core']:GetCoreObject()
local canwork = false
local vezes = 0
local amount = Config.paymentbybush
local total = 0
local Blip = nil
local Ped = nil
AddEventHandler('onResourceStarting', function(resourceName)
if resourceName == 'qb-gardening' then
CancelEvent()
end
end)
local function hasItem()
if QBCore.Functions.HasItem('shears') then
return true
else
return false
end
end
local function ds()
if Ped ~= nil then
DeleteEntity(Ped)
exports['qb-target']:RemoveZone("Ped")
Ped = nil
end
end
local function Startup()
--Blip
if Config.Coords['WantBlip'] == 'yes' then
Blip = AddBlipForCoord(Config.Coords['Blip'])
SetBlipSprite(Blip, 541)
SetBlipDisplay(Blip, 4)
SetBlipScale(Blip, 0.5)
SetBlipAsShortRange(Blip, true)
SetBlipColour(Blip, 2)
BeginTextCommandSetBlipName("STRING")
AddTextComponentSubstringPlayerName(Config.Coords['BlipName'])
EndTextCommandSetBlipName(Blip)
elseif Config.Coords['WantBlip'] == 'no' then
RemoveBlip(Blip)
end
--Ped
RequestModel(Config.Coords['PedModel'])
while not HasModelLoaded(Config.Coords['PedModel']) do
Wait(1)
end
Ped = CreatePed(2, Config.Coords['PedModel'], Config.Coords['Ped'], false, false)
SetPedFleeAttributes(Ped, 0, 0)
SetPedDiesWhenInjured(Ped, false)
SetPedKeepTask(Ped, true)
SetBlockingOfNonTemporaryEvents(Ped, true)
SetEntityInvincible(Ped, true)
FreezeEntityPosition(Ped, true)
-- TaskStartScenarioInPlace(Ped, 'WORLD_HUMAN_GARDENER_PLANT', 0, true)
exports['qb-target']:AddBoxZone("Ped", GetEntityCoords(Ped), 1.5, 1.5, {
name = "Ped",
heading = GetEntityHeading(Ped),
minZ = Config.Coords['Ped']['z'],
maxZ = Config.Coords['Ped']['z'] + 2.0,
debugPoly = false
}, {
options = {
{
event = "nc-gardening:startwork",
icon = Lang.workicon,
label = Lang.getwork,
-- job = Config.job,
},
{
event = 'nc-gardening:client:payment',
icon = Lang.paymenticon,
label = Lang.paymentlabel,
-- job = Config.job,
}
},
distance = 2.5
})
end
Startup()
local animDict = "rcmnigel1b"
local anim = "idle_gardener"
local function Anim()
local playerPed = PlayerPedId()
if not HasAnimDictLoaded(animDict) then
RequestAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
Wait(100)
end
end
TaskPlayAnim(playerPed, animDict, anim, 8.0, 8.0, 5000, 0, 0, false, false, false)
end
local function startingWork()
if canwork == false then
QBCore.Functions.Notify(Lang.givesomespots, 'info')
canwork = true
vezes = 0
SetNewWaypoint(-510.19, -261.66)
loc1()
else
QBCore.Functions.Notify(Lang.alreadyhavework, 'error')
end
end
RegisterNetEvent('nc-gardening:startwork', function()
QBCore.Functions.TriggerCallback("nc-gardening:cooldown", function(cooldown)
if cooldown then
QBCore.Functions.Notify(Lang.ontimeout, 'error')
return
end
startingWork()
end, 'lmao')
end)
RegisterNetEvent('nc-gardening:workbushes1', function()
if not hasItem then return QBCore.Functions.Notify(Lang.donthaveitem, 'error') end
Anim()
QBCore.Functions.Progressbar('workbushes', Lang.workbushes, 5000, false, true,
{ -- Name | Label | Time | useWhileDead | canCancel
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
}, {}, {}, function()
exports['qb-target']:RemoveZone('loc1')
loc2()
vezes = vezes + 1
QBCore.Functions.Notify(Lang.leftone, 'info')
end)
end)
RegisterNetEvent('nc-gardening:workbushes2', function()
if not hasItem then return QBCore.Functions.Notify(Lang.donthaveitem, 'error') end
Anim()
QBCore.Functions.Progressbar('workbushes', Lang.workbushes, 5000, false, true,
{ -- Name | Label | Time | useWhileDead | canCancel
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
}, {}, {}, function()
exports['qb-target']:RemoveZone('loc2')
loc3()
vezes = vezes + 1
QBCore.Functions.Notify(Lang.infrontofyou, 'info')
end)
end)
RegisterNetEvent('nc-gardening:workbushes3', function()
if not hasItem then return QBCore.Functions.Notify(Lang.donthaveitem, 'error') end
Anim()
QBCore.Functions.Progressbar('workbushes', Lang.workbushes, 5000, false, true,
{ -- Name | Label | Time | useWhileDead | canCancel
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
}, {}, {}, function()
exports['qb-target']:RemoveZone('loc3')
loc4()
vezes = vezes + 1
QBCore.Functions.Notify(Lang.therest, 'info')
end)
end)
RegisterNetEvent('nc-gardening:workbushes4', function()
if not hasItem then return QBCore.Functions.Notify(Lang.donthaveitem, 'error') end
Anim()
QBCore.Functions.Progressbar('workbushes', Lang.workbushes, 5000, false, true,
{ -- Name | Label | Time | useWhileDead | canCancel
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
}, {}, {}, function()
exports['qb-target']:RemoveZone('loc4')
loc5()
vezes = vezes + 1
end)
end)
RegisterNetEvent('nc-gardening:workbushes5', function()
if not hasItem then return QBCore.Functions.Notify(Lang.donthaveitem, 'error') end
Anim()
QBCore.Functions.Progressbar('workbushes', Lang.workbushes, 5000, false, true,
{ -- Name | Label | Time | useWhileDead | canCancel
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
}, {}, {}, function()
exports['qb-target']:RemoveZone('loc5')
loc6()
vezes = vezes + 1
end)
end)
RegisterNetEvent('nc-gardening:workbushes6', function()
if not hasItem then return QBCore.Functions.Notify(Lang.donthaveitem, 'error') end
Anim()
QBCore.Functions.Progressbar('workbushes', Lang.workbushes, 5000, false, true,
{ -- Name | Label | Time | useWhileDead | canCancel
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
}, {}, {}, function()
exports['qb-target']:RemoveZone('loc6')
loc7()
vezes = vezes + 1
end)
end)
RegisterNetEvent('nc-gardening:workbushes7', function()
if not hasItem then return QBCore.Functions.Notify(Lang.donthaveitem, 'error') end
Anim()
QBCore.Functions.Progressbar('workbushes', Lang.workbushes, 5000, false, true,
{ -- Name | Label | Time | useWhileDead | canCancel
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
}, {}, {}, function()
exports['qb-target']:RemoveZone('loc7')
loc8()
vezes = vezes + 1
end)
end)
RegisterNetEvent('nc-gardening:workbushes8', function()
if not hasItem then return QBCore.Functions.Notify(Lang.donthaveitem, 'error') end
Anim()
QBCore.Functions.Progressbar('workbushes', Lang.workbushes, 5000, false, true,
{ -- Name | Label | Time | useWhileDead | canCancel
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
}, {}, {}, function()
exports['qb-target']:RemoveZone('loc8')
loc9()
vezes = vezes + 1
end)
end)
RegisterNetEvent('nc-gardening:workbushes9', function()
if not hasItem then return QBCore.Functions.Notify(Lang.donthaveitem, 'error') end
Anim()
QBCore.Functions.Progressbar('workbushes', Lang.workbushes, 5000, false, true,
{ -- Name | Label | Time | useWhileDead | canCancel
disableMovement = true,
disableCarMovement = true,
disableMouse = false,
disableCombat = true,
}, {
}, {}, {}, function()
exports['qb-target']:RemoveZone('loc9')
vezes = vezes + 1
QBCore.Functions.Notify(Lang.cometome, 'info')
SetNewWaypoint(Config.Coords['Ped']['x'], Config.Coords['Ped']['y'])
end)
end)
RegisterNetEvent('nc-gardening:client:payment', function()
if vezes > 0 then
total = vezes * amount
TriggerServerEvent('nc-gardening:server:pagamento', total)
canwork = false
exports['qb-target']:RemoveZone('loc1')
exports['qb-target']:RemoveZone('loc2')
exports['qb-target']:RemoveZone('loc3')
exports['qb-target']:RemoveZone('loc4')
exports['qb-target']:RemoveZone('loc5')
exports['qb-target']:RemoveZone('loc6')
exports['qb-target']:RemoveZone('loc7')
exports['qb-target']:RemoveZone('loc8')
exports['qb-target']:RemoveZone('loc9')
else
QBCore.Functions.Notify(Lang.didntwork, 'error')
end
end)
AddEventHandler('onResourceStop', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then
return
end
ds()
end)