Skip to content

Commit

Permalink
use new esx carry limit code
Browse files Browse the repository at this point in the history
  • Loading branch information
ElPumpo committed Oct 26, 2019
1 parent 4220c14 commit a2daba0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 66 deletions.
15 changes: 1 addition & 14 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
Keys = {
["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57,
["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177,
["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18,
["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182,
["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81,
["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70,
["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178,
["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173,
["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118
}

ESX = nil
local menuOpen = false
local wasOpen = false
Expand Down Expand Up @@ -37,7 +25,7 @@ Citizen.CreateThread(function()
if not menuOpen then
ESX.ShowHelpNotification(_U('dealer_prompt'))

if IsControlJustReleased(0, Keys['E']) then
if IsControlJustReleased(0, 38) then
wasOpen = true
OpenDrugShop()
end
Expand Down Expand Up @@ -163,7 +151,6 @@ end

Citizen.CreateThread(function()
for k,zone in pairs(Config.CircleZones) do

CreateBlipCircle(zone.coords, zone.name, zone.radius, zone.color, zone.sprite)
end
end)
21 changes: 5 additions & 16 deletions client/weed.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ local spawnedWeeds = 0
local weedPlants = {}
local isPickingUp, isProcessing = false, false


Citizen.CreateThread(function()
while true do
Citizen.Wait(10)
Citizen.Wait(500)
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)
Expand All @@ -28,8 +24,7 @@ Citizen.CreateThread(function()
ESX.ShowHelpNotification(_U('weed_processprompt'))
end

if IsControlJustReleased(0, Keys['E']) and not isProcessing then

if IsControlJustReleased(0, 38) and not isProcessing then
if Config.LicenseEnable then
ESX.TriggerServerCallback('esx_license:checkLicense', function(hasProcessingLicense)
if hasProcessingLicense then
Expand All @@ -41,7 +36,6 @@ Citizen.CreateThread(function()
else
ProcessWeed()
end

end
else
Citizen.Wait(500)
Expand Down Expand Up @@ -74,6 +68,7 @@ end
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)

local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local nearbyObject, nearbyID
Expand All @@ -85,16 +80,14 @@ Citizen.CreateThread(function()
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
if IsControlJustReleased(0, 38) and not isPickingUp then
isPickingUp = true

ESX.TriggerServerCallback('esx_drugs:canPickUp', function(canPickUp)

if canPickUp then
TaskStartScenarioInPlace(playerPed, 'world_human_gardener_plant', 0, false)

Expand All @@ -113,16 +106,12 @@ Citizen.CreateThread(function()
end

isPickingUp = false

end, 'cannabis')
end

else
Citizen.Wait(500)
end

end

end)

AddEventHandler('onResourceStop', function(resource)
Expand Down Expand Up @@ -206,4 +195,4 @@ function GetCoordZ(x, y)
end

return 43.0
end
end
6 changes: 3 additions & 3 deletions localization/en_esx_drugs.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
USE `essentialmode`;

INSERT INTO `items` (`name`, `label`, `limit`, `rare`, `can_remove`) VALUES
('cannabis', 'Cannabis', 40, 0, 1),
('marijuana', 'Marijuana', 14, 0, 1)
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES
('cannabis', 'Cannabis', 3, 0, 1),
('marijuana', 'Marijuana', 2, 0, 1)
;

INSERT INTO `licenses` (`type`, `label`) VALUES
Expand Down
6 changes: 3 additions & 3 deletions localization/es_esx_drugs.sql
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
USE `essentialmode`;

INSERT INTO `items` (`name`, `label`, `limit`, `rare`, `can_remove`) VALUES
('cannabis', 'Marijuana húmeda', 40, 0, 1),
('marijuana', 'Marijuana', 14, 0, 1)
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES
('cannabis', 'Marijuana húmeda', 3, 0, 1),
('marijuana', 'Marijuana', 2, 0, 1)
;

INSERT INTO `licenses` (`type`, `label`) VALUES
Expand Down
52 changes: 22 additions & 30 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ AddEventHandler('esx_drugs:sellDrug', function(itemName, amount)
end

if xItem.count < amount then
TriggerClientEvent('esx:showNotification', source, _U('dealer_notenough'))
xPlayer.showNotification(_U('dealer_notenough'))
return
end

Expand All @@ -28,51 +28,43 @@ AddEventHandler('esx_drugs:sellDrug', function(itemName, amount)
end

xPlayer.removeInventoryItem(xItem.name, amount)

TriggerClientEvent('esx:showNotification', source, _U('dealer_sold', amount, xItem.label, ESX.Math.GroupDigits(price)))
xPlayer.showNotification(_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)
if license then
if xPlayer.getMoney() >= license.price then
xPlayer.removeMoney(license.price)

TriggerEvent('esx_license:addLicense', source, licenseName, function()
cb(true)
end)
else
cb(false)
end
else
print(('esx_drugs: %s attempted to buy an invalid license!'):format(xPlayer.identifier))
cb(false)
end
end)

RegisterServerEvent('esx_drugs:pickedUpCannabis')
AddEventHandler('esx_drugs:pickedUpCannabis', function()
local xPlayer = ESX.GetPlayerFromId(source)
local xItem = xPlayer.getInventoryItem('cannabis')

if xItem.limit ~= -1 and (xItem.count + 1) > xItem.limit then
TriggerClientEvent('esx:showNotification', _source, _U('weed_inventoryfull'))
if xPlayer.canCarryItem('cannabis', 1) then
xPlayer.showNotification(_U('weed_inventoryfull'))
else
xPlayer.addInventoryItem(xItem.name, 1)
xPlayer.addInventoryItem('cannabis', 1)
end
end)

ESX.RegisterServerCallback('esx_drugs:canPickUp', function(source, cb, item)
local xPlayer = ESX.GetPlayerFromId(source)
local xItem = xPlayer.getInventoryItem(item)

if xItem.limit ~= -1 and xItem.count >= xItem.limit then
cb(false)
else
cb(true)
end
cb(xPlayer.canCarryItem(item, 1))
end)

RegisterServerEvent('esx_drugs:processCannabis')
Expand All @@ -82,17 +74,17 @@ AddEventHandler('esx_drugs:processCannabis', function()

playersProcessingCannabis[_source] = ESX.SetTimeout(Config.Delays.WeedProcessing, function()
local xPlayer = ESX.GetPlayerFromId(_source)
local xCannabis, xMarijuana = xPlayer.getInventoryItem('cannabis'), xPlayer.getInventoryItem('marijuana')
local xCannabis = xPlayer.getInventoryItem('cannabis')

if xMarijuana.limit ~= -1 and (xMarijuana.count + 1) >= xMarijuana.limit then
TriggerClientEvent('esx:showNotification', _source, _U('weed_processingfull'))
if not xPlayer.canCarryItem('marijuana', 1) then
xPlayer.showNotification(_U('weed_processingfull'))
elseif xCannabis.count < 3 then
TriggerClientEvent('esx:showNotification', _source, _U('weed_processingenough'))
xPlayer.showNotification(_U('weed_processingenough'))
else
xPlayer.removeInventoryItem('cannabis', 3)
xPlayer.addInventoryItem('marijuana', 1)

TriggerClientEvent('esx:showNotification', _source, _U('weed_processed'))
xPlayer.showNotification(_U('weed_processed'))
end

playersProcessingCannabis[_source] = nil
Expand Down

0 comments on commit a2daba0

Please sign in to comment.