forked from Pgmbru/fxserver-esx_drugs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
indent_size = 4 | ||
indent_style = tab | ||
end_of_line = crlf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# esx_drugs | ||
|
||
This is a WIP re-write of the resource. Currently feautures a weed farm with actual weed plant objects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937' | ||
|
||
description 'ESX Drugs' | ||
|
||
version '0.1.0' | ||
|
||
server_scripts { | ||
'@mysql-async/lib/MySQL.lua', | ||
'@es_extended/locale.lua', | ||
'locales/en.lua', | ||
'locales/sv.lua', | ||
'config.lua', | ||
'server/main.lua' | ||
} | ||
|
||
client_scripts { | ||
'@es_extended/locale.lua', | ||
'locales/en.lua', | ||
'locales/sv.lua', | ||
'config.lua', | ||
'client/main.lua', | ||
'client/weed.lua' | ||
} | ||
|
||
dependencies { | ||
'es_extended' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
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 shopOpen = false | ||
|
||
Citizen.CreateThread(function() | ||
while ESX == nil do | ||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) | ||
Citizen.Wait(0) | ||
end | ||
|
||
while ESX.GetPlayerData().job == nil do | ||
Citizen.Wait(100) | ||
end | ||
|
||
ESX.PlayerData = ESX.GetPlayerData() | ||
end) | ||
|
||
Citizen.CreateThread(function() | ||
while true do | ||
Citizen.Wait(0) | ||
local playerPed = PlayerPedId() | ||
local coords = GetEntityCoords(playerPed) | ||
|
||
if GetDistanceBetweenCoords(coords, Config.CircleZones.DrugDealer.coords, true) < 0.5 then | ||
if not shopOpen then | ||
ESX.ShowHelpNotification(_U('dealer_prompt')) | ||
|
||
if IsControlJustReleased(0, Keys['E']) then | ||
OpenDrugShop() | ||
end | ||
else | ||
Citizen.Wait(500) | ||
end | ||
else | ||
if shopOpen then | ||
ESX.UI.Menu.CloseAll() | ||
shopOpen = false | ||
end | ||
|
||
Citizen.Wait(500) | ||
end | ||
end | ||
end) | ||
|
||
function OpenDrugShop() | ||
ESX.UI.Menu.CloseAll() | ||
local elements = {} | ||
shopOpen = true | ||
|
||
for k, v in pairs(ESX.GetPlayerData().inventory) do | ||
local price = Config.DrugDealerItems[v.name] | ||
|
||
if price and v.count > 0 then | ||
table.insert(elements, { | ||
label = ('%s - <span style="color:green;">%s</span>'):format(v.label, _U('dealer_item', ESX.Math.GroupDigits(price))), | ||
name = v.name, | ||
price = price, | ||
|
||
-- menu properties | ||
type = 'slider', | ||
value = 1, | ||
min = 1, | ||
max = v.count | ||
}) | ||
end | ||
end | ||
|
||
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'drug_shop', { | ||
title = _U('dealer_title'), | ||
align = 'top-left', | ||
elements = elements | ||
}, function(data, menu) | ||
TriggerServerEvent('esx_drugs:sellDrug', data.current.name, data.current.value) | ||
end, function(data, menu) | ||
menu.close() | ||
shopOpen = false | ||
end) | ||
end | ||
|
||
AddEventHandler('onResourceStop', function(resource) | ||
if resource == GetCurrentResourceName() then | ||
if shopOpen then | ||
ESX.UI.Menu.CloseAll() | ||
end | ||
end | ||
end) | ||
|
||
function CreateBlipCircle(coords, text, radius, color, sprite) | ||
local blip = AddBlipForRadius(coords, radius) | ||
|
||
SetBlipHighDetail(blip, true) | ||
SetBlipColour(blip, 1) | ||
SetBlipAlpha (blip, 128) | ||
|
||
-- create a blip in the middle | ||
blip = AddBlipForCoord(coords) | ||
|
||
SetBlipHighDetail(blip, true) | ||
SetBlipSprite (blip, sprite) | ||
SetBlipScale (blip, 1.0) | ||
SetBlipColour (blip, color) | ||
SetBlipAsShortRange(blip, true) | ||
|
||
BeginTextCommandSetBlipName("STRING") | ||
AddTextComponentString(text) | ||
EndTextCommandSetBlipName(blip) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Config = {} | ||
|
||
Config.Locale = 'en' | ||
|
||
Config.Delays = { | ||
WeedProcessing = 1000 * 10 | ||
} | ||
|
||
Config.DrugDealerItems = { | ||
marijuana = 91 | ||
} | ||
|
||
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}, | ||
|
||
DrugDealer = {coords = vector3(-1172.02, -1571.98, 4.66), name = _U('blip_drugdealer'), color = 6, sprite = 378, radius = 25.0}, | ||
} |
Oops, something went wrong.