mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-02 19:28:52 +00:00
Add new files
This commit is contained in:
+198
@@ -0,0 +1,198 @@
|
||||
local spawnedWeeds = 0
|
||||
local weedPlants = {}
|
||||
local isPickingUp, isProcessing = false, false
|
||||
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(10)
|
||||
local coords = GetEntityCoords(PlayerPedId())
|
||||
|
||||
if GetDistanceBetweenCoords(coords, Config.CircleZones.WeedField.coords, true) < 50 then
|
||||
SpawnWeedPlants()
|
||||
Citizen.Wait(500)
|
||||
else
|
||||
Citizen.Wait(500)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(10)
|
||||
local playerPed = PlayerPedId()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
|
||||
if GetDistanceBetweenCoords(coords, Config.CircleZones.WeedProcessing.coords, true) < 1 then
|
||||
if not isProcessing then
|
||||
ESX.ShowHelpNotification(_U('weed_processprompt'))
|
||||
end
|
||||
|
||||
if IsControlJustReleased(0, Keys['E']) and not isProcessing then
|
||||
isProcessing = true
|
||||
ESX.ShowNotification(_U('weed_processingstarted'))
|
||||
TriggerServerEvent('esx_drugs:processCannabis')
|
||||
local timeLeft = Config.Delays.WeedProcessing / 1000
|
||||
|
||||
while timeLeft > 0 do
|
||||
Citizen.Wait(1000)
|
||||
timeLeft = timeLeft - 1
|
||||
|
||||
if GetDistanceBetweenCoords(GetEntityCoords(playerPed), Config.CircleZones.WeedProcessing.coords, false) > 4 then
|
||||
ESX.ShowNotification(_U('weed_processingtoofar'))
|
||||
TriggerServerEvent('esx_drugs:cancelProcessing')
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
isProcessing = false
|
||||
end
|
||||
else
|
||||
Citizen.Wait(500)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while true do
|
||||
Citizen.Wait(10)
|
||||
local playerPed = PlayerPedId()
|
||||
local coords = GetEntityCoords(playerPed)
|
||||
local nearbyObject, nearbyID = nil, nil
|
||||
|
||||
for i=1, #weedPlants, 1 do
|
||||
if GetDistanceBetweenCoords(coords, GetEntityCoords(weedPlants[i]), false) < 1 then
|
||||
nearbyObject, nearbyID = weedPlants[i], i
|
||||
end
|
||||
end
|
||||
|
||||
if nearbyObject and IsPedOnFoot(playerPed) then
|
||||
|
||||
if not isPickingUp then
|
||||
ESX.ShowHelpNotification(_U('weed_pickupprompt'))
|
||||
end
|
||||
|
||||
if IsControlJustReleased(0, Keys['E']) and not isPickingUp then
|
||||
isPickingUp = true
|
||||
|
||||
ESX.TriggerServerCallback('esx_drugs:canPickUp', function(canPickUp)
|
||||
|
||||
if canPickUp then
|
||||
TaskStartScenarioInPlace(playerPed, 'world_human_gardener_plant', 0, false)
|
||||
|
||||
Citizen.Wait(2000)
|
||||
ClearPedTasks(playerPed)
|
||||
Citizen.Wait(1500)
|
||||
|
||||
ESX.Game.DeleteObject(nearbyObject)
|
||||
|
||||
table.remove(weedPlants, nearbyID)
|
||||
spawnedWeeds = spawnedWeeds - 1
|
||||
|
||||
TriggerServerEvent('esx_drugs:pickedUpCannabis')
|
||||
else
|
||||
ESX.ShowNotification(_U('weed_inventoryfull'))
|
||||
end
|
||||
|
||||
isPickingUp = false
|
||||
|
||||
end, 'cannabis')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
AddEventHandler('onResourceStop', function(resource)
|
||||
if resource == GetCurrentResourceName() then
|
||||
for k, v in pairs(weedPlants) do
|
||||
ESX.Game.DeleteObject(v)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function SpawnWeedPlants()
|
||||
while spawnedWeeds < 25 do
|
||||
Citizen.Wait(0)
|
||||
local weedCoords = GenerateWeedCoords()
|
||||
|
||||
ESX.Game.SpawnLocalObject('prop_weed_02', weedCoords, function(obj)
|
||||
PlaceObjectOnGroundProperly(obj)
|
||||
FreezeEntityPosition(obj, true)
|
||||
|
||||
table.insert(weedPlants, obj)
|
||||
spawnedWeeds = spawnedWeeds + 1
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function ValidateWeedCoord(plantCoord)
|
||||
if spawnedWeeds > 0 then
|
||||
local validate = true
|
||||
|
||||
for k, v in pairs(weedPlants) do
|
||||
if GetDistanceBetweenCoords(plantCoord, GetEntityCoords(v), true) < 5 then
|
||||
validate = false
|
||||
end
|
||||
end
|
||||
|
||||
if GetDistanceBetweenCoords(plantCoord, Config.CircleZones.WeedField.coords, false) > 50 then
|
||||
validate = false
|
||||
end
|
||||
|
||||
return validate
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function GenerateWeedCoords()
|
||||
while true do
|
||||
Citizen.Wait(1)
|
||||
|
||||
local weedCoordX, weedCoordY
|
||||
|
||||
math.randomseed(GetGameTimer())
|
||||
local modX = math.random(-90, 90)
|
||||
|
||||
Citizen.Wait(100)
|
||||
|
||||
math.randomseed(GetGameTimer())
|
||||
local modY = math.random(-90, 90)
|
||||
|
||||
if modX > 0 then
|
||||
weedCoordX = Config.CircleZones.WeedField.coords.x + modX
|
||||
else
|
||||
weedCoordX = Config.CircleZones.WeedField.coords.x - modX
|
||||
end
|
||||
|
||||
if modY > 0 then
|
||||
weedCoordY = Config.CircleZones.WeedField.coords.y + modY
|
||||
else
|
||||
weedCoordY = Config.CircleZones.WeedField.coords.y - modY
|
||||
end
|
||||
|
||||
local coordZ = GetCoordZ(weedCoordX, weedCoordY)
|
||||
local coord = vector3(weedCoordX, weedCoordY, coordZ)
|
||||
|
||||
if ValidateWeedCoord(coord) then
|
||||
return coord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function GetCoordZ(x, y)
|
||||
local groundCheckHeights = { 40.0, 41.0, 42.0, 43.0, 44.0, 45.0, 46.0, 47.0, 48.0, 49.0, 50.0 }
|
||||
|
||||
for i, height in ipairs(groundCheckHeights) do
|
||||
local foundGround, z = GetGroundZFor_3dCoord(x, y, height)
|
||||
|
||||
if foundGround then
|
||||
return z
|
||||
end
|
||||
end
|
||||
|
||||
return 43.0
|
||||
end
|
||||
Reference in New Issue
Block a user