Merge pull request #104 from Mycroft-Studios/master

[Refactor] Lots of changes
This commit is contained in:
ESXCrackhead
2021-04-27 09:56:04 -05:00
committed by GitHub
4 changed files with 75 additions and 75 deletions
+10 -18
View File
@@ -10,18 +10,6 @@ Citizen.CreateThread(function()
Citizen.Wait(5000)
ESX.TriggerServerCallback('esx_shops:requestDBItems', function(ShopItems)
for k,v in pairs(ShopItems) do
if (Config.Zones[k] == nil) then
Config.Zones[k] = {
Items = {},
Pos = {}
}
end
Config.Zones[k].Items = v
end
end)
end)
function OpenShopMenu(zone)
@@ -32,7 +20,7 @@ function OpenShopMenu(zone)
table.insert(elements, {
label = ('%s - <span style="color:green;">%s</span>'):format(item.label, _U('shop_item', ESX.Math.GroupDigits(item.price))),
itemLabel = item.label,
item = item.item,
item = item.name,
price = item.price,
-- menu properties
@@ -89,11 +77,12 @@ end)
Citizen.CreateThread(function()
for k,v in pairs(Config.Zones) do
for i = 1, #v.Pos, 1 do
if v.ShowBlip then
local blip = AddBlipForCoord(v.Pos[i])
SetBlipSprite (blip, 52)
SetBlipScale (blip, 1.0)
SetBlipColour (blip, 2)
SetBlipSprite (blip, v.Type)
SetBlipScale (blip, v.Size)
SetBlipColour (blip, v.Color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
@@ -101,6 +90,7 @@ Citizen.CreateThread(function()
EndTextCommandSetBlipName(blip)
end
end
end
end)
-- Enter / Exit marker events
@@ -115,10 +105,12 @@ Citizen.CreateThread(function()
local distance = #(playerCoords - v.Pos[i])
if distance < Config.DrawDistance then
DrawMarker(Config.Type, v.Pos[i], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.Size.x, Config.Size.y, Config.Size.z, Config.Color.r, Config.Color.g, Config.Color.b, 100, false, true, 2, false, nil, nil, false)
if v.ShowMarker then
DrawMarker(Config.MarkerType, v.Pos[i], 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.MarkerSize.x, Config.MarkerSize.y, Config.MarkerSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, nil, nil, false)
end
letSleep = false
if distance < Config.Size.x then
if distance < 2.0 then
isInMarker = true
currentZone = k
lastZone = k
+60 -9
View File
@@ -1,14 +1,25 @@
Config = {}
Config.DrawDistance = 100
Config.Size = {x = 1.5, y = 1.5, z = 1.5}
Config.Color = {r = 0, g = 128, b = 255}
Config.Type = 1
Config.MarkerSize = {x = 1.1, y = 1.1, z = 0.9}
Config.MarkerType = 21
Config.MarkerColor = {r = 102, g = 102, b = 204, a = 255}
Config.Locale = 'en'
Config.Zones = {
TwentyFourSeven = {
Items = {},
Items = {
{
name = "bread",
label = "bread",
price = 100
},
{
name = "water",
label = "water",
price = 100
}
},
Pos = {
vector3(373.8, 325.8, 102.5),
vector3(2557.4, 382.2, 107.6),
@@ -18,10 +29,27 @@ Config.Zones = {
vector3(1961.4, 3740.6, 31.3),
vector3(2678.9, 3280.6, 54.2),
vector3(1729.2, 6414.1, 34.0)
}},
},
Size = 1.0,
Type = 59,
Color = 25,
ShowBlip = true,
ShowMarker = true
},
RobsLiquor = {
Items = {},
Items = {
{
name = "bread",
label = "bread",
price = 100
},
{
name = "water",
label = "water",
price = 100
}
},
Pos = {
vector3(1135.8, -982.2, 45.4),
vector3(-1222.9, -906.9, 11.3),
@@ -32,15 +60,38 @@ Config.Zones = {
vector3(127.8, -1284.7, 28.2), --StripClub
vector3(-1393.4, -606.6, 29.3), --Tequila la
vector3(-559.9, 287.0, 81.1) --Bahamamas
}},
},
Size = 1.0,
Type = 59,
Color = 25,
ShowBlip = true,
ShowMarker = true
},
LTDgasoline = {
Items = {},
Items = {
{
name = "bread",
label = "bread",
price = 100
},
{
name = "water",
label = "water",
price = 100
}
},
Pos = {
vector3(-48.5, -1757.5, 28.4),
vector3(1163.3, -323.8, 68.2),
vector3(-707.5, -914.2, 18.2),
vector3(-1820.5, 792.5, 137.1),
vector3(1698.3, 4924.4, 41.0)
}}
},
Size = 1.0,
Type = 59,
Color = 25,
ShowBlip = true,
ShowMarker = true
}
}
-19
View File
@@ -1,19 +0,0 @@
USE `es_extended`;
CREATE TABLE `shops` (
`id` int NOT NULL AUTO_INCREMENT,
`store` varchar(100) NOT NULL,
`item` varchar(100) NOT NULL,
`price` int NOT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `shops` (store, item, price) VALUES
('TwentyFourSeven','bread',30),
('TwentyFourSeven','water',15),
('RobsLiquor','bread',30),
('RobsLiquor','water',15),
('LTDgasoline','bread',30),
('LTDgasoline','water',15)
;
+5 -29
View File
@@ -3,30 +3,6 @@ local ShopItems = {}
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
MySQL.ready(function()
MySQL.Async.fetchAll('SELECT * FROM shops LEFT JOIN items ON items.name = shops.item', {}, function(shopResult)
for i=1, #shopResult, 1 do
if shopResult[i].name then
if ShopItems[shopResult[i].store] == nil then
ShopItems[shopResult[i].store] = {}
end
table.insert(ShopItems[shopResult[i].store], {
label = shopResult[i].label,
item = shopResult[i].item,
price = shopResult[i].price,
})
else
print(('esx_shops: invalid item "%s" found!'):format(shopResult[i].item))
end
end
end)
end)
ESX.RegisterServerCallback('esx_shops:requestDBItems', function(source, cb)
cb(ShopItems)
end)
RegisterServerEvent('esx_shops:buyItem')
AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone)
local _source = source
@@ -34,7 +10,6 @@ AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone)
amount = ESX.Math.Round(amount)
-- is the player trying to exploit?
if amount < 0 then
print('esx_shops: ' .. xPlayer.identifier .. ' attempted to exploit the shop!')
return
@@ -44,10 +19,11 @@ AddEventHandler('esx_shops:buyItem', function(itemName, amount, zone)
local price = 0
local itemLabel = ''
for i=1, #ShopItems[zone], 1 do
if ShopItems[zone][i].item == itemName then
price = ShopItems[zone][i].price
itemLabel = ShopItems[zone][i].label
for i=1, #Config.Zones[zone].Items, 1 do
local item = Config.Zones[zone].Items[i]
if item.name == itemName then
price = item.price
itemLabel = item.label
break
end
end