Skip to content

Commit d0622bf

Browse files
authored
Merge pull request #1288 from bitpredator/dev-bitpredator
feat: new resource bpt_oxshops
2 parents adcbdfc + a92588d commit d0622bf

File tree

7 files changed

+1304
-0
lines changed

7 files changed

+1304
-0
lines changed

server-data/resources/[bpt_addons]/bpt_oxshops/LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
---@diagnostic disable: undefined-global
2+
3+
local ESX = exports["es_extended"]:getSharedObject()
4+
5+
-- =========================
6+
-- VARIABILI
7+
-- =========================
8+
local jobBlips = {}
9+
local shopBlips = {}
10+
local textUIVisible = false
11+
12+
-- =========================
13+
-- MARKER CONFIG
14+
-- =========================
15+
local MARKER_TYPE = 1
16+
local MARKER_DRAW_DIST = 10.0
17+
local MARKER_SIZE = vec3(0.45, 0.45, 0.45)
18+
19+
local MARKER_COLOR_SHOP = { r = 0, g = 180, b = 255, a = 150 }
20+
local MARKER_COLOR_STASH = { r = 255, g = 50, b = 50, a = 150 }
21+
22+
-- =========================
23+
-- ESX EVENTS
24+
-- =========================
25+
RegisterNetEvent("esx:playerLoaded", function(xPlayer)
26+
ESX.PlayerData = xPlayer
27+
ESX.PlayerLoaded = true
28+
refreshJobBlips()
29+
end)
30+
31+
RegisterNetEvent("esx:onPlayerLogout", function()
32+
ESX.PlayerLoaded = false
33+
ESX.PlayerData = {}
34+
end)
35+
36+
RegisterNetEvent("esx:setJob", function(job)
37+
ESX.PlayerData.job = job
38+
refreshJobBlips()
39+
end)
40+
41+
-- =========================
42+
-- BLIP FUNCTIONS
43+
-- =========================
44+
local function createBlip(data)
45+
local blip = AddBlipForCoord(data.coords.x, data.coords.y, data.coords.z)
46+
SetBlipSprite(blip, data.sprite)
47+
SetBlipDisplay(blip, 4)
48+
SetBlipScale(blip, data.scale)
49+
SetBlipColour(blip, data.color)
50+
SetBlipAsShortRange(blip, true)
51+
52+
BeginTextCommandSetBlipName("STRING")
53+
AddTextComponentString(data.label)
54+
EndTextCommandSetBlipName(blip)
55+
56+
return blip
57+
end
58+
59+
function refreshJobBlips()
60+
for _, blip in pairs(jobBlips) do
61+
RemoveBlip(blip)
62+
end
63+
jobBlips = {}
64+
65+
if not ESX.PlayerLoaded or not ESX.PlayerData.job then
66+
return
67+
end
68+
69+
for shopName, shop in pairs(Config.Shops) do
70+
if shop.blip.stash.enabled and ESX.PlayerData.job.name == shopName then
71+
jobBlips[#jobBlips + 1] = createBlip(shop.blip.stash)
72+
end
73+
end
74+
end
75+
76+
-- =========================
77+
-- CREATE SHOP BLIPS (PUBLIC)
78+
-- =========================
79+
CreateThread(function()
80+
for _, shop in pairs(Config.Shops) do
81+
if shop.blip.shop.enabled then
82+
shopBlips[#shopBlips + 1] = createBlip(shop.blip.shop)
83+
end
84+
end
85+
end)
86+
87+
-- =========================
88+
-- SET PRODUCT PRICE (SECURE)
89+
-- =========================
90+
RegisterNetEvent("bpt_oxshops:setProductPrice", function(shop, slot)
91+
if not ESX.PlayerLoaded or not ESX.PlayerData.job or ESX.PlayerData.job.name ~= shop then
92+
print("[ANTICHEAT] Tentativo setProductPrice non autorizzato")
93+
return
94+
end
95+
96+
local input = lib.inputDialog(Strings.sell_price, { Strings.amount_input })
97+
local price = tonumber(input and input[1])
98+
99+
if not price or price < 0 then
100+
return
101+
end
102+
103+
TriggerEvent("ox_inventory:closeInventory")
104+
TriggerServerEvent("bpt_oxshops:setData", shop, slot, math.floor(price))
105+
106+
lib.notify({
107+
title = Strings.success,
108+
description = (Strings.item_stocked_desc):format(price),
109+
type = "success",
110+
})
111+
end)
112+
113+
-- =========================
114+
-- MAIN LOOP (MARKER + UI)
115+
-- =========================
116+
CreateThread(function()
117+
while true do
118+
local sleep = 1500
119+
local ped = PlayerPedId()
120+
local coords = GetEntityCoords(ped)
121+
122+
for shopName, shopData in pairs(Config.Shops) do
123+
local stash = shopData.locations.stash
124+
local shop = shopData.locations.shop
125+
126+
local distStash = #(coords - stash.coords)
127+
local distShop = #(coords - shop.coords)
128+
129+
-- =====================
130+
-- STASH (JOB LOCKED)
131+
-- =====================
132+
if ESX.PlayerData.job and ESX.PlayerData.job.name == shopName then
133+
if distStash <= MARKER_DRAW_DIST then
134+
sleep = 0
135+
DrawMarker(
136+
MARKER_TYPE,
137+
stash.coords.x,
138+
stash.coords.y,
139+
stash.coords.z - 0.95,
140+
0.0,
141+
0.0,
142+
0.0,
143+
0.0,
144+
0.0,
145+
0.0,
146+
MARKER_SIZE.x,
147+
MARKER_SIZE.y,
148+
MARKER_SIZE.z,
149+
MARKER_COLOR_STASH.r,
150+
MARKER_COLOR_STASH.g,
151+
MARKER_COLOR_STASH.b,
152+
MARKER_COLOR_STASH.a,
153+
false,
154+
true,
155+
2,
156+
false,
157+
nil,
158+
nil,
159+
false
160+
)
161+
end
162+
163+
if distStash <= stash.range then
164+
if not textUIVisible then
165+
lib.showTextUI(stash.string)
166+
textUIVisible = true
167+
end
168+
169+
if IsControlJustReleased(0, 38) then
170+
exports.ox_inventory:openInventory("stash", shopName)
171+
end
172+
end
173+
end
174+
175+
-- =====================
176+
-- SHOP (PUBLIC)
177+
-- =====================
178+
if distShop <= MARKER_DRAW_DIST then
179+
sleep = 0
180+
DrawMarker(MARKER_TYPE, shop.coords.x, shop.coords.y, shop.coords.z - 0.95, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, MARKER_SIZE.x, MARKER_SIZE.y, MARKER_SIZE.z, MARKER_COLOR_SHOP.r, MARKER_COLOR_SHOP.g, MARKER_COLOR_SHOP.b, MARKER_COLOR_SHOP.a, false, true, 2, false, nil, nil, false)
181+
end
182+
183+
if distShop <= shop.range then
184+
if not textUIVisible then
185+
lib.showTextUI(shop.string)
186+
textUIVisible = true
187+
end
188+
189+
if IsControlJustReleased(0, 38) then
190+
exports.ox_inventory:openInventory("shop", {
191+
type = shopName,
192+
id = 1,
193+
})
194+
end
195+
end
196+
197+
-- =====================
198+
-- HIDE UI
199+
-- =====================
200+
if distStash > stash.range and distShop > shop.range and textUIVisible then
201+
lib.hideTextUI()
202+
textUIVisible = false
203+
end
204+
end
205+
206+
Wait(sleep)
207+
end
208+
end)
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
Config = {}
2+
3+
Config.Shops = {
4+
["ambulance"] = {
5+
label = "Farmacia Ospedale",
6+
7+
blip = {
8+
shop = {
9+
enabled = true,
10+
coords = vec3(308.281311, -592.588989, 43.282104),
11+
sprite = 61,
12+
color = 8,
13+
scale = 0.7,
14+
label = "Farmacia Ospedale",
15+
},
16+
stash = {
17+
enabled = true,
18+
coords = vec3(309.283508, -561.507690, 43.282104),
19+
sprite = 473,
20+
color = 1,
21+
scale = 0.6,
22+
label = "Deposito Ospedale",
23+
},
24+
},
25+
26+
locations = {
27+
stash = {
28+
string = "[E] - Deposito vendita",
29+
coords = vec3(309.283508, -561.507690, 43.282104),
30+
range = 1.0,
31+
},
32+
shop = {
33+
string = "[E] - Punto di acquisto",
34+
coords = vec3(308.281311, -592.588989, 43.282104),
35+
range = 1.0,
36+
},
37+
},
38+
},
39+
40+
["ammu"] = {
41+
label = "Negozio Armeria",
42+
43+
blip = {
44+
shop = {
45+
enabled = true,
46+
coords = vec3(811.147278, -2157.349365, 29.616821),
47+
sprite = 110,
48+
color = 8,
49+
scale = 0.7,
50+
label = "Armeria",
51+
},
52+
stash = {
53+
enabled = true,
54+
coords = vec3(826.641785, -2157.019775, 29.616821),
55+
sprite = 473,
56+
color = 1,
57+
scale = 0.6,
58+
label = "Deposito Armeria",
59+
},
60+
},
61+
62+
locations = {
63+
stash = {
64+
string = "[E] - Deposito vendita",
65+
coords = vec3(826.641785, -2157.019775, 29.616821),
66+
range = 1.0,
67+
},
68+
shop = {
69+
string = "[E] - Punto di acquisto",
70+
coords = vec3(812.584595, -2153.063721, 29.616821),
71+
range = 1.0,
72+
},
73+
},
74+
},
75+
76+
["unicorn"] = {
77+
label = "Negozio Unicorn",
78+
79+
blip = {
80+
shop = {
81+
enabled = true,
82+
coords = vec3(131.076920, -1286.136230, 29.263062),
83+
sprite = 59,
84+
color = 8,
85+
scale = 0.7,
86+
label = "Unicorn",
87+
},
88+
stash = {
89+
enabled = true,
90+
coords = vec3(131.076920, -1286.136230, 29.263062),
91+
sprite = 59,
92+
color = 1,
93+
scale = 0.6,
94+
label = "Deposito Unicorn",
95+
},
96+
},
97+
98+
locations = {
99+
stash = {
100+
string = "[E] - Deposito vendita",
101+
coords = vec3(131.076920, -1286.136230, 29.263062),
102+
range = 1.0,
103+
},
104+
shop = {
105+
string = "[E] - Punto di acquisto",
106+
coords = vec3(126.791214, -1282.905518, 29.263062),
107+
range = 1.0,
108+
},
109+
},
110+
},
111+
112+
["import"] = {
113+
label = "Negozio Import",
114+
115+
blip = {
116+
shop = {
117+
enabled = true,
118+
coords = vec3(899.723083, -1043.723022, 35.244629),
119+
sprite = 59,
120+
color = 8,
121+
scale = 0.7,
122+
label = "Import",
123+
},
124+
stash = {
125+
enabled = true,
126+
coords = vec3(899.723083, -1043.723022, 35.244629),
127+
sprite = 59,
128+
color = 1,
129+
scale = 0.6,
130+
label = "Deposito Import",
131+
},
132+
},
133+
134+
locations = {
135+
stash = {
136+
string = "[E] - Deposito vendita",
137+
coords = vec3(892.852722, -1031.789063, 35.244629),
138+
range = 1.0,
139+
},
140+
shop = {
141+
string = "[E] - Punto di acquisto",
142+
coords = vec3(899.564819, -1043.683472, 35.244629),
143+
range = 1.0,
144+
},
145+
},
146+
},
147+
148+
["mechanic"] = {
149+
label = "Negozio Meccanico",
150+
151+
blip = {
152+
shop = {
153+
enabled = true,
154+
coords = vec3(-328.575806, -157.582413, 39.002197),
155+
sprite = 59,
156+
color = 8,
157+
scale = 0.7,
158+
label = "Meccanico",
159+
},
160+
stash = {
161+
enabled = true,
162+
coords = vec3(-328.575806, -157.582413, 39.002197),
163+
sprite = 59,
164+
color = 1,
165+
scale = 0.6,
166+
label = "Deposito Meccanico",
167+
},
168+
},
169+
170+
locations = {
171+
stash = {
172+
string = "[E] - Deposito vendita",
173+
coords = vec3(-328.575806, -157.582413, 39.002197),
174+
range = 1.0,
175+
},
176+
shop = {
177+
string = "[E] - Punto di acquisto",
178+
coords = vec3(-330.039551, -162.567032, 39.002197),
179+
range = 1.0,
180+
},
181+
},
182+
},
183+
}

0 commit comments

Comments
 (0)