Skip to content

Commit

Permalink
Implemented processing license
Browse files Browse the repository at this point in the history
  • Loading branch information
ElPumpo committed Dec 8, 2018
1 parent 6291156 commit 7974aea
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 25 deletions.
58 changes: 51 additions & 7 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Keys = {
}

ESX = nil
local shopOpen = false
local menuOpen = false
local wasOpen = false

Citizen.CreateThread(function()
while ESX == nil do
Expand All @@ -33,19 +34,20 @@ Citizen.CreateThread(function()
local coords = GetEntityCoords(playerPed)

if GetDistanceBetweenCoords(coords, Config.CircleZones.DrugDealer.coords, true) < 0.5 then
if not shopOpen then
if not menuOpen then
ESX.ShowHelpNotification(_U('dealer_prompt'))

if IsControlJustReleased(0, Keys['E']) then
wasOpen = true
OpenDrugShop()
end
else
Citizen.Wait(500)
end
else
if shopOpen then
if wasOpen then
wasOpen = false
ESX.UI.Menu.CloseAll()
shopOpen = false
end

Citizen.Wait(500)
Expand All @@ -56,7 +58,7 @@ end)
function OpenDrugShop()
ESX.UI.Menu.CloseAll()
local elements = {}
shopOpen = true
menuOpen = true

for k, v in pairs(ESX.GetPlayerData().inventory) do
local price = Config.DrugDealerItems[v.name]
Expand Down Expand Up @@ -84,18 +86,60 @@ function OpenDrugShop()
TriggerServerEvent('esx_drugs:sellDrug', data.current.name, data.current.value)
end, function(data, menu)
menu.close()
shopOpen = false
menuOpen = false
end)
end

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

function OpenBuyLicenseMenu(licenseName)
menuOpen = true
local license = Config.LicensePrices[licenseName]

local elements = {
{
label = _U('license_no'),
value = 'no'
},

{
label = ('%s - <span style="color:green;">%s</span>'):format(license.label, _U('dealer_item', ESX.Math.GroupDigits(license.price))),
value = licenseName,
price = license.price,
licenseName = license.label
}
}

ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'license_shop', {
title = _U('license_title'),
align = 'top-left',
elements = elements
}, function(data, menu)

if data.current.value ~= 'no' then
ESX.TriggerServerCallback('esx_drugs:buyLicense', function(boughtLicense)
if boughtLicense then
ESX.ShowNotification(_U('license_bought', data.current.licenseName, ESX.Math.GroupDigits(data.current.price)))
else
ESX.ShowNotification(_U('license_bought_fail', data.current.licenseName))
end
end, data.current.value)
else
menu.close()
end

end, function(data, menu)
menu.close()
menuOpen = false
end)
end

function CreateBlipCircle(coords, text, radius, color, sprite)
local blip = AddBlipForRadius(coords, radius)

Expand Down
48 changes: 33 additions & 15 deletions client/weed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,48 @@ Citizen.CreateThread(function()
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

if Config.LicenseEnable then
ESX.TriggerServerCallback('esx_license:checkLicense', function(hasProcessingLicense)
if hasProcessingLicense then
ProcessWeed()
else
OpenBuyLicenseMenu('weed_processing')
end
end, GetPlayerServerId(PlayerId()), 'weed_processing')
else
ProcessWeed()
end

isProcessing = false
end
else
Citizen.Wait(500)
end
end
end)

function ProcessWeed()
isProcessing = true

ESX.ShowNotification(_U('weed_processingstarted'))
TriggerServerEvent('esx_drugs:processCannabis')
local timeLeft = Config.Delays.WeedProcessing / 1000
local playerPed = PlayerPedId()

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

Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
Expand Down
6 changes: 6 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Config.DrugDealerItems = {
marijuana = 91
}

Config.LicenseEnable = false -- enable processing licenses? The player will be required to buy a license in order to process drugs. Requires esx_license

Config.LicensePrices = {
weed_processing = {label = _U('license_weed'), price = 15000}
}

Config.GiveBlack = true -- give black money? if disabled it'll give regular cash.

Config.CircleZones = {
Expand Down
4 changes: 4 additions & 0 deletions esx_drugs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ INSERT INTO `items` (`name`, `label`, `limit`, `rare`, `can_remove`) VALUES
('cannabis', 'Cannabis', 40, 0, 1),
('marijuana', 'Marijuana', 14, 0, 1)
;

INSERT INTO `licenses` (`type`, `label`) VALUES
('weed_processing', 'Weed Processing License')
;
7 changes: 7 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Locales ['en'] = {
['dealer_notenough'] = 'you don\'t have enough of that to sell!',
['dealer_sold'] = 'you\'ve sold ~b~%sx~s~ ~y~%s~s~ for ~g~$%s~s~',

-- license
['license_title'] = 'you are required to own a processing license to process this product, it can be bought here.',
['license_no'] = 'no',
['license_bought'] = 'you bought the ~b~%s~s~ for ~r~$%s~s~',
['license_bought_fail'] = 'you cannot afford an ~b~%s~s~!',
['license_weed'] = 'weed Processing License',

-- blips
['blip_weedfield'] = 'weed Field',
['blip_weedprocessing'] = 'weed Processing',
Expand Down
13 changes: 10 additions & 3 deletions locales/sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Locales ['sv'] = {
['weed_pickupprompt'] = 'tryck ~INPUT_CONTEXT~ för att skörda ~g~Cannabisväxten~s~.',
['weed_inventoryfull'] = 'du har ingen mer plats för ~g~Cannabis~s~.',
['weed_processprompt'] = 'tryck ~INPUT_CONTEXT~ för att börja ~g~Processera Cannabis~s~.',
['weed_processingstarted'] = 'processera ~g~Cannabis~s~ till ~g~Marijuana~s~...',
['weed_processingstarted'] = 'processerar ~g~Cannabis~s~ till ~g~Marijuana~s~...',
['weed_processingfull'] = 'processeringen ~r~avbröts~s~ för att utrymmet är slut!',
['weed_processingenough'] = 'du måste ha ~b~3x~s~ ~g~Cannabis~s~ för att kunna bearbeta den.',
['weed_processingenough'] = 'du måste ha ~b~3x~s~ ~g~Cannabis~s~ för att kunna bearbeta det.',
['weed_processed'] = 'du har processerat ~b~3x~s~ ~g~Cannabis~s~ till ~b~1x~s~ ~g~Marijuana~s~',
['weed_processingtoofar'] = 'processeringen har ~r~har avbrutit~s~ på grund av att du lämnade området.',

Expand All @@ -14,7 +14,14 @@ Locales ['sv'] = {
['dealer_title'] = 'drogsäljare',
['dealer_item'] = '%s SEK',
['dealer_notenough'] = 'du har inte tillräckligt med det till salu!',
['dealer_sold'] = 'duhar sålt ~b~%sx~s~ ~y~%s~s~ för ~g~%s SEK~s~',
['dealer_sold'] = 'du har sålt ~b~%sx~s~ ~y~%s~s~ för ~g~%s SEK~s~',

-- license
['license_title'] = 'du måste ha ett visst processeringslicens för att kunna bearbeta denna produkt, detta kan dock köpas här.',
['license_no'] = 'nej',
['license_bought'] = 'du köpte ~b~%s~s~ för ~r~%s SEK~s~',
['license_bought_fail'] = 'du har inte råd för ~b~%s~s~!',
['license_weed'] = 'marijuana processeringslicens',

-- blips
['blip_weedfield'] = 'marijuana plock',
Expand Down
20 changes: 20 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ AddEventHandler('esx_drugs:sellDrug', function(itemName, amount)
TriggerClientEvent('esx:showNotification', source, _U('dealer_sold', amount, xItem.label, ESX.Math.GroupDigits(price)))
end)

ESX.RegisterServerCallback('esx_drugs:buyLicense', function(source, cb, licenseName)
local xPlayer = ESX.GetPlayerFromId(source)
local license = Config.LicensePrices[licenseName]

if license == nil then
print(('esx_drugs: %s attempted to buy an invalid license!'):format(xPlayer.identifier))
cb(false)
end

if xPlayer.getMoney() >= license.price then
xPlayer.removeMoney(license.price)

TriggerEvent('esx_license:addLicense', source, licenseName, function()
cb(true)
end)
else
cb(false)
end
end)

RegisterServerEvent('esx_drugs:pickedUpCannabis')
AddEventHandler('esx_drugs:pickedUpCannabis', function()
local xPlayer = ESX.GetPlayerFromId(source)
Expand Down

0 comments on commit 7974aea

Please sign in to comment.