Skip to content

Commit

Permalink
Merge pull request #808 from bitpredator/dev
Browse files Browse the repository at this point in the history
refactor: reconstruction of the drug system
  • Loading branch information
bitpredator authored Aug 27, 2024
2 parents 222bd95 + bcdc713 commit d319642
Show file tree
Hide file tree
Showing 35 changed files with 573 additions and 1,963 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ server-data/cache/files/BasicItem
server-data/cache/chat
server-data/cache/yarn-cache
server-data/db/default
server-data/imgui.ini

# Resources
server-data/resources/\[gameplay]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ INSERT INTO `bpt_items` (`name`, `label`) VALUES
('plastic_bag', 'Plastic bag'),
('recycled_plastic', 'Recycled plastic'),
('WEAPON_NIGHTSTICK', 'NIGHTSTICK'),
('WEAPON_PISTOL', 'Pistol')
('WEAPON_PISTOL', 'Pistol'),
('marijuana', 'marijuana'),
('cannabis', 'Cannabis'),
('diamond_tip', 'Diamond tip'),
('diamond', 'Diamond')
;
39 changes: 36 additions & 3 deletions server-data/resources/[bpt_addons]/bpt_crafting/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ Config = {
},
},

["marijuana"] = {
Level = 0,
Category = "medical",
isGun = false,
Jobs = { "ambulance" },
JobGrades = {},
Amount = 1,
SuccessRate = 100,
requireBlueprint = false,
Time = 20,
Ingredients = {
["cannabis"] = 2,
["diamond_tip"] = 1,
},
},

["cottonforbandages"] = {
Level = 0, -- From what level this item will be craftable
Category = "import", -- The category item will be put in
Expand Down Expand Up @@ -98,6 +114,23 @@ Config = {
},
},

["diamond_tip"] = {
Level = 0,
Category = "import",
isGun = false,
Jobs = { "import" },
JobGrades = {},
Amount = 1,
SuccessRate = 100,
requireBlueprint = false,
Time = 60,
Ingredients = {
["diamond"] = 1,
["hammer"] = 1,
["steel"] = 1,
},
},

["recycled_paper"] = {
Level = 0,
Category = "import",
Expand Down Expand Up @@ -426,14 +459,14 @@ Config = {
coords = vector3(1020.936279, -2404.628662, 30.122314),
jobs = { "import" },
blip = false,
recipes = { "cottonforbandages", "hammer", "ironsheet", "recycled_paper", "paper", "recycled_plastic", "iron" },
recipes = { "cottonforbandages", "hammer", "ironsheet", "recycled_paper", "paper", "recycled_plastic", "iron", "diamond_tip" },
radius = 1.0,
},
{
coords = vector3(311.314301, -565.213196, 43.282104),
jobs = { "ambulance" },
blip = false,
recipes = { "bandage" },
recipes = { "bandage", "marijuana" },
radius = 1.0,
},
{
Expand Down Expand Up @@ -469,7 +502,7 @@ Config = {
coords = vector3(83.156044, -1960.259277, 18.041016),
jobs = { "ballas" },
blip = false,
recipes = { "cigarette_paper" },
recipes = { "cigarette_paper", "marijuana" },
radius = 1.0,
},
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ INSERT INTO `bpt_items` (`name`, `label`) VALUES
('plastic_bag', 'Sacchetto di plastica'),
('recycled_plastic', 'Plastica riciclata'),
('WEAPON_NIGHTSTICK', 'Manganello'),
('WEAPON_PISTOL', 'Pistola 9mm')
('WEAPON_PISTOL', 'Pistola 9mm'),
('marijuana', 'marijuana'),
('cannabis', 'Cannabis'),
('diamond_tip', 'Punta di diamante'),
('diamond', 'Diamond')
;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -631,8 +631,7 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2023-2024 bitpredator
bpt_drugs Copyright (C) 2024 bitpredator

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -645,14 +644,14 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

esx_uteknark Copyright (C) 2023-2024 bitpredator
bpt_drugs Copyright (C) 2024 bitpredator
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand All @@ -664,11 +663,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<https://www.gnu.org/licenses/>.
<http://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>.
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
19 changes: 19 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_drugs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h1 align='center'>bpt_drugs</a></h1>
<p align='center'><a href='https://discord.gg/ksGfNvDEfq'>Discord</a>

Copyright (C) 2024 bitpredator

This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.

This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.

ATTENTION:
You are not authorized to change the name of the resource and the resources within it.

If you want to contribute you can open a pull request.

You are not authorized to sell this software (this is free project).

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
4 changes: 4 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_drugs/bpt_drugs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES
('cannabis', 'Cannabis', 3, 0, 1),
('marijuana', 'Marijuana', 2, 0, 1)
;
136 changes: 136 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_drugs/client/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
local menuOpen = false
local inZoneDrugShop = false
local inRangeMarkerDrugShop = false
local cfgMarker = Config.Marker

--slow loop
CreateThread(function()
while true do
local playerPed = PlayerPedId()
local coords = GetEntityCoords(playerPed)
local distDrugShop = #(coords - Config.CircleZones.DrugDealer.coords)

inRangeMarkerDrugShop = false
if distDrugShop <= Config.Marker.Distance then
inRangeMarkerDrugShop = true
end

if distDrugShop < 1 then
inZoneDrugShop = true
else
inZoneDrugShop = false
if menuOpen then
menuOpen = false
end
end

Wait(500)
end
end)

--drawk marker
CreateThread(function()
while true do
local Sleep = 1500
if inRangeMarkerDrugShop then
Sleep = 0
local coordsMarker = Config.CircleZones.DrugDealer.coords
local color = cfgMarker.Color
DrawMarker(cfgMarker.Type, coordsMarker.x, coordsMarker.y, coordsMarker.z - 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, cfgMarker.Size, color.r, color.g, color.b, color.a, false, true, 2, false, nil, nil, false)
end
Wait(Sleep)
end
end)

--main loop
CreateThread(function()
while true do
local Sleep = 1500
if inZoneDrugShop and not menuOpen then
Sleep = 0
ESX.ShowHelpNotification(TranslateCap("dealer_prompt"), true)
if IsControlJustPressed(0, 38) then
OpenDrugShop()
end
end
Wait(Sleep)
end
end)

function OpenDrugShop()
local elements = {
{ unselectable = true, icon = "fas fa-cannabis", title = TranslateCap("dealer_title") },
}
menuOpen = true

for _, v in pairs(ESX.GetPlayerData().inventory) do
local price = Config.DrugDealerItems[v.name]

if price and v.count > 0 then
elements[#elements + 1] = {
icon = "fas fa-shopping-basket",
title = ('%s - <span style="color:green;">%s</span>'):format(v.label, TranslateCap("dealer_item", ESX.Math.GroupDigits(price))),
name = v.name,
price = price,
}
end
end

ESX.OpenContext("right", elements, function(menu, element)
local elements2 = {
{ unselectable = true, icon = "fas fa-shopping-basket", title = element.title },
{ icon = "fas fa-shopping-basket", title = "Amount", input = true, inputType = "number", inputPlaceholder = "Amount you want to sell", inputValue = 0, inputMin = Config.SellMenu.Min, inputMax = Config.SellMenu.Max },
{ icon = "fas fa-check-double", title = "Confirm", val = "confirm" },
}

ESX.OpenContext("right", elements2, function(menu2, element2)
ESX.CloseContext()
local count = tonumber(menu2.eles[2].inputValue)

if count < 1 then
return
end

TriggerServerEvent("bpt_drugs:sellDrug", tostring(element.name), count)
end, function()
menuOpen = false
end)
end, function(menu)
menuOpen = false
end)
end

AddEventHandler("onResourceStop", function(resource)
if resource == GetCurrentResourceName() then
if menuOpen then
ESX.CloseContext()
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")
AddTextComponentSubstringPlayerName(text)
EndTextCommandSetBlipName(blip)
end

CreateThread(function()
for _, zone in pairs(Config.CircleZones) do
CreateBlipCircle(zone.coords, zone.name, zone.radius, zone.color, zone.sprite)
end
end)
Loading

0 comments on commit d319642

Please sign in to comment.