mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-31 10:18:54 +00:00
modified processing weed (#126)
* modified processing weed now you can process all the weed by pressing E * cleaned code
This commit is contained in:
+11
-5
@@ -34,7 +34,10 @@ Citizen.CreateThread(function()
|
||||
end
|
||||
end, GetPlayerServerId(PlayerId()), 'weed_processing')
|
||||
else
|
||||
ProcessWeed()
|
||||
ESX.TriggerServerCallback('esx_drugs:cannabis_count', function(xCannabis)
|
||||
ProcessWeed(xCannabis)
|
||||
end)
|
||||
|
||||
end
|
||||
end
|
||||
else
|
||||
@@ -43,12 +46,14 @@ Citizen.CreateThread(function()
|
||||
end
|
||||
end)
|
||||
|
||||
function ProcessWeed()
|
||||
function ProcessWeed(xCannabis)
|
||||
isProcessing = true
|
||||
|
||||
ESX.ShowNotification(_U('weed_processingstarted'))
|
||||
TriggerServerEvent('esx_drugs:processCannabis')
|
||||
local timeLeft = Config.Delays.WeedProcessing / 1000
|
||||
if(xCannabis<3) then
|
||||
xCannabis=0
|
||||
end
|
||||
local timeLeft = (Config.Delays.WeedProcessing * xCannabis) / 1000
|
||||
local playerPed = PlayerPedId()
|
||||
|
||||
while timeLeft > 0 do
|
||||
@@ -58,6 +63,7 @@ function ProcessWeed()
|
||||
if GetDistanceBetweenCoords(GetEntityCoords(playerPed), Config.CircleZones.WeedProcessing.coords, false) > 4 then
|
||||
ESX.ShowNotification(_U('weed_processingtoofar'))
|
||||
TriggerServerEvent('esx_drugs:cancelProcessing')
|
||||
TriggerServerEvent('esx_drugs:outofbound')
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -184,7 +190,7 @@ function GenerateWeedCoords()
|
||||
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 }
|
||||
local groundCheckHeights = { 48.0, 49.0, 50.0, 51.0, 52.0, 53.0, 54.0, 55.0, 56.0, 57.0, 58.0 }
|
||||
|
||||
for i, height in ipairs(groundCheckHeights) do
|
||||
local foundGround, z = GetGroundZFor_3dCoord(x, y, height)
|
||||
|
||||
+4
-4
@@ -3,7 +3,7 @@ Config = {}
|
||||
Config.Locale = 'en'
|
||||
|
||||
Config.Delays = {
|
||||
WeedProcessing = 1000 * 10
|
||||
WeedProcessing = 1000 * 7
|
||||
}
|
||||
|
||||
Config.DrugDealerItems = {
|
||||
@@ -19,8 +19,8 @@ Config.LicensePrices = {
|
||||
Config.GiveBlack = true -- give black money? if disabled it'll give regular cash.
|
||||
|
||||
Config.CircleZones = {
|
||||
WeedField = {coords = vector3(310.91, 4290.87, 45.15), name = _U('blip_weedfield'), color = 25, sprite = 496, radius = 100.0},
|
||||
WeedProcessing = {coords = vector3(2329.02, 2571.29, 46.68), name = _U('blip_weedprocessing'), color = 25, sprite = 496, radius = 100.0},
|
||||
WeedField = {coords = vector3(2220.72, 5582.52, 53.81), name = _U('blip_weedfield'), color = 25, sprite = 496, radius = 100.0},
|
||||
WeedProcessing = {coords = vector3(2329.02, 2571.29, 46.68), name = _U('blip_weedprocessing'), color = 25, sprite = 496},
|
||||
|
||||
DrugDealer = {coords = vector3(-1172.02, -1571.98, 4.66), name = _U('blip_drugdealer'), color = 6, sprite = 378, radius = 25.0},
|
||||
DrugDealer = {coords = vector3(-1172.02, -1571.98, 4.66), name = _U('blip_drugdealer'), color = 6, sprite = 378},
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
Locales ['en'] = {
|
||||
-- weed
|
||||
['weed_pickupprompt'] = 'press ~INPUT_CONTEXT~ to harvest the ~g~Cannabis~s~ plant.',
|
||||
['weed_quitprocess'] = 'press ~INPUT_CONTEXT~ to stop ~g~Process Cannabis~s~.',
|
||||
['weed_inventoryfull'] = 'you do not have any more inventory space for ~g~Cannabis~s~.',
|
||||
['weed_processprompt'] = 'press ~INPUT_CONTEXT~ to start ~g~Process Cannabis~s~.',
|
||||
['weed_processingstarted'] = 'processing ~g~Cannabis~s~ into ~g~Marijuana~s~...',
|
||||
|
||||
+54
-19
@@ -1,5 +1,7 @@
|
||||
ESX = nil
|
||||
local playersProcessingCannabis = {}
|
||||
local outofbound = true
|
||||
local alive = true
|
||||
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
@@ -54,9 +56,10 @@ end)
|
||||
RegisterServerEvent('esx_drugs:pickedUpCannabis')
|
||||
AddEventHandler('esx_drugs:pickedUpCannabis', function()
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local cime = math.random(5,10)
|
||||
|
||||
if xPlayer.canCarryItem('cannabis', 1) then
|
||||
xPlayer.addInventoryItem('cannabis', 1)
|
||||
if xPlayer.canCarryItem('cannabis', cime) then
|
||||
xPlayer.addInventoryItem('cannabis', cime)
|
||||
else
|
||||
xPlayer.showNotification(_U('weed_inventoryfull'))
|
||||
end
|
||||
@@ -67,30 +70,62 @@ ESX.RegisterServerCallback('esx_drugs:canPickUp', function(source, cb, item)
|
||||
cb(xPlayer.canCarryItem(item, 1))
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_drugs:outofbound')
|
||||
AddEventHandler('esx_drugs:outofbound', function()
|
||||
outofbound = true
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_drugs:quitprocess')
|
||||
AddEventHandler('esx_drugs:quitprocess', function()
|
||||
can = false
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_drugs:cannabis_count', function(source, cb)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
local xCannabis = xPlayer.getInventoryItem('cannabis').count
|
||||
cb(xCannabis)
|
||||
end)
|
||||
|
||||
RegisterServerEvent('esx_drugs:processCannabis')
|
||||
AddEventHandler('esx_drugs:processCannabis', function()
|
||||
if not playersProcessingCannabis[source] then
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local xCannabis = xPlayer.getInventoryItem('cannabis')
|
||||
TriggerClientEvent('esx_drugs:getPlayer',xCannabis.count,_source)
|
||||
local can = true
|
||||
outofbound = false
|
||||
if xCannabis.count >=3 then
|
||||
while outofbound == false and can and GetEntityHealth(GetPlayerPed(_source))>0 do
|
||||
if playersProcessingCannabis[_source] == nil then
|
||||
playersProcessingCannabis[_source] = ESX.SetTimeout(Config.Delays.WeedProcessing , function()
|
||||
if xCannabis.count >= 3 then
|
||||
if xPlayer.canSwapItem('cannabis', 3, 'marijuana', 1) then
|
||||
xPlayer.removeInventoryItem('cannabis', 3)
|
||||
xPlayer.addInventoryItem('marijuana', 1)
|
||||
xPlayer.showNotification(_U('weed_processed'))
|
||||
else
|
||||
can = false
|
||||
xPlayer.showNotification(_U('weed_processingfull'))
|
||||
TriggerEvent('esx_drugs:cancelProcessing')
|
||||
end
|
||||
else
|
||||
can = false
|
||||
xPlayer.showNotification(_U('weed_processingenough'))
|
||||
TriggerEvent('esx_drugs:cancelProcessing')
|
||||
end
|
||||
|
||||
playersProcessingCannabis[_source] = ESX.SetTimeout(Config.Delays.WeedProcessing, function()
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
local xCannabis = xPlayer.getInventoryItem('cannabis')
|
||||
|
||||
if xCannabis.count > 3 then
|
||||
if xPlayer.canSwapItem('cannabis', 3, 'marijuana', 1) then
|
||||
xPlayer.removeInventoryItem('cannabis', 3)
|
||||
xPlayer.addInventoryItem('marijuana', 1)
|
||||
|
||||
xPlayer.showNotification(_U('weed_processed'))
|
||||
playersProcessingCannabis[_source] = nil
|
||||
end)
|
||||
else
|
||||
xPlayer.showNotification(_U('weed_processingfull'))
|
||||
end
|
||||
else
|
||||
xPlayer.showNotification(_U('weed_processingenough'))
|
||||
Wait(Config.Delays.WeedProcessing)
|
||||
end
|
||||
end
|
||||
|
||||
playersProcessingCannabis[_source] = nil
|
||||
end)
|
||||
else
|
||||
xPlayer.showNotification(_U('weed_processingenough'))
|
||||
TriggerEvent('esx_drugs:cancelProcessing')
|
||||
end
|
||||
|
||||
else
|
||||
print(('esx_drugs: %s attempted to exploit weed processing!'):format(GetPlayerIdentifiers(source)[1]))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user