2026-01-16 02:57:26 -07:00
Locations = Locations or {}
2023-12-07 15:45:48 -08:00
2024-11-23 15:33:17 -08:00
local dloc = {
{ coords = vector4 ( 282.48 , - 1814.32 , 27.23 , 145.11 )},
{ coords = vector4 ( - 296.11 , - 1300.65 , 31.31 , 270.87 )},
{ coords = vector4 ( - 36.64 , - 1492.04 , 31.22 , 151.91 )},
{ coords = vector4 ( 282.48 , - 1814.32 , 27.23 , 232.19 )},
{ coords = vector4 ( 54.54 , - 1873.22 , 22.81 , 131.47 )},
{ coords = vector4 ( - 269.34 , - 2437.25 , 6.40 , 252.67 )},
{ coords = vector4 ( 269.19 , - 3248.55 , 5.79 , 252.67 )},
{ coords = vector4 ( 632.94 , - 3015.44 , 7.34 , 3.44 )},
{ coords = vector4 ( 1049.55 , - 2427.88 , 30.30 , 79.52 )},
{ coords = vector4 ( 853.16 , - 2207.32 , 30.68 , 284.88 )},
{ coords = vector4 ( 903.10 , - 1721.98 , 32.25 , 168.71 )},
{ coords = vector4 ( 1289.30 , - 1710.49 , 55.48 , 208.57 )},
{ coords = vector4 ( 1412.01 , - 1490.53 , 60.66 , 132.46 )},
{ coords = vector4 ( 734.26 , - 1311.26 , 27.01 , 102.99 )},
{ coords = vector4 ( 1231.60 , - 1083.06 , 38.53 , 102.99 )},
{ coords = vector4 ( 1143.55 , - 1000.19 , 45.32 , 257.05 )},
{ coords = vector4 ( 1264.82 , - 702.87 , 64.72 , 257.05 )},
{ coords = vector4 ( 1119.65 , - 639.76 , 56.81 , 284.53 )},
{ coords = vector4 ( 1129.59 , - 462.59 , 66.49 , 79.23 )},
{ coords = vector4 ( 42.80 , - 811.45 , 31.43 , 79.23 )},
{ coords = vector4 ( - 509.48 , - 1001.66 , 23.55 , 79.23 )},
{ coords = vector4 ( - 830.97 , - 862.41 , 20.69 , 13.72 )},
{ coords = vector4 ( - 1320.26 , - 1177.34 , 4.89 , 74.29 )},
{ coords = vector4 ( - 1097.63 , - 1673.24 , 8.40 , 136.51 )},
{ coords = vector4 ( - 1147.61 , - 1452.10 , 4.60 , 51.50 )},
{ coords = vector4 ( - 1241.69 , - 1208.39 , 8.52 , 107.56 )},
{ coords = vector4 ( - 1876.92 , - 584.44 , 11.85 , 329.54 )},
{ coords = vector4 ( - 1303.94 , - 441.39 , 35.22 , 128.73 )},
{ coords = vector4 ( - 1705.48 , - 433.46 , 42.17 , 128.73 )},
{ coords = vector4 ( - 1305.99 , 336.35 , 65.50 , 35.13 )},
{ coords = vector4 ( - 741.80 , 484.84 , 109.47 , 110.85 )},
{ coords = vector4 ( - 409.57 , 341.49 , 108.91 , 270.45 )},
{ coords = vector4 ( - 126.44 , 588.18 , 204.71 , 8.12 )},
{ coords = vector4 ( 211.42 , - 101.42 , 73.28 , 174.10 )},
{ coords = vector4 ( 490.61 , - 95.04 , 66.44 , 273.57 )},
{ coords = vector4 ( 387.19 , - 993.59 , 29.42 , 273.57 )},
{ coords = vector4 ( - 500.47 , - 712.37 , 33.21 , 273.57 )},
{ coords = vector4 ( 2572.20 , 479.97 , 108.68 , 80.27 )},
{ coords = vector4 ( - 430.10 , 1205.41 , 325.76 , 169.25 )},
{ coords = vector4 ( - 126.06 , 1896.58 , 197.33 , 169.25 )},
{ coords = vector4 ( - 2521.08 , 2310.31 , 33.22 , 276.87 )},
{ coords = vector4 ( 1129.01 , 2125.14 , 55.55 , 276.87 )},
{ coords = vector4 ( 1546.64 , 2166.56 , 78.72 , 100.37 )},
{ coords = vector4 ( 404.34 , 2584.54 , 43.52 , 100.37 )},
{ coords = vector4 ( 180.15 , 2792.99 , 45.66 , 283.04 )},
{ coords = vector4 ( 287.67 , 2843.89 , 44.70 , 118.41 )},
{ coords = vector4 ( 2030.23 , 3184.42 , 45.13 , 146.06 )},
{ coords = vector4 ( 2175.33 , 3321.92 , 46.13 , 214.53 )},
{ coords = vector4 ( 2389.61 , 3340.98 , 47.34 , 214.52 )},
{ coords = vector4 ( 1716.25 , 3295.08 , 41.26 , 196.21 )},
{ coords = vector4 ( 1779.38 , 3640.83 , 34.50 , 24.16 )},
{ coords = vector4 ( 1894.59 , 3715.34 , 32.75 , 127.89 )},
{ coords = vector4 ( 1861.90 , 3857.15 , 36.27 , 293.45 )},
{ coords = vector4 ( 996.38 , 3575.07 , 34.61 , 328.30 )},
{ coords = vector4 ( 387.45 , 3584.73 , 33.29 , 351.41 )},
{ coords = vector4 ( 68.08 , 3693.22 , 40.66 , 63.98 )},
{ coords = vector4 ( 15.55 , 3688.70 , 39.81 , 230.89 )},
{ coords = vector4 ( 2566.59 , 4283.34 , 41.97 , 348.53 )},
{ coords = vector4 ( 2570.82 , 4667.95 , 34.08 , 135.30 )},
{ coords = vector4 ( 2882.05 , 4511.72 , 48.02 , 66.58 )},
{ coords = vector4 ( 2243.78 , 5154.02 , 57.89 , 139.42 )},
{ coords = vector4 ( 1642.91 , 4846.08 , 45.51 , 109.83 )},
{ coords = vector4 ( 1308.87 , 4362.17 , 41.55 , 256.01 )},
{ coords = vector4 ( - 1090.27 , 4940.57 , 214.13 , 256.01 )},
{ coords = vector4 ( - 552.37 , 5348.37 , 74.76 , 62.18 )},
{ coords = vector4 ( - 679.02 , 5834.27 , 17.33 , 137.18 )},
{ coords = vector4 ( - 481.97 , 6276.93 , 13.35 , 323.16 )},
{ coords = vector4 ( - 24.92 , 6472.60 , 31.49 , 144.42 )},
{ coords = vector4 ( 36.03 , 6549.18 , 31.43 , 287.85 )},
{ coords = vector4 ( 406.08 , 6526.43 , 27.75 , 97.45 )},
{ coords = vector4 ( 1522.39 , 6329.23 , 24.61 , 331.71 )},
{ coords = vector4 ( 1741.39 , 6419.62 , 35.04 , 331.71 )},
{ coords = vector4 ( 3426.72 , 5174.42 , 7.40 , 112.64 )},
{ coords = vector4 ( 2525.99 , 2586.62 , 38.94 , 257.02 )},
{ coords = vector4 ( 2696.29 , 1664.44 , 24.52 , 70.12 )},
{ coords = vector4 ( 106.24 , - 1280.32 , 29.24 , 350.89 )},
{ coords = vector4 ( 223.98 , 121.53 , 102.76 , 259.68 )},
{ coords = vector4 ( 102.19 , - 255.02 , 50.05 , 83.59 )},
}
2025-08-09 03:10:00 -06:00
local Products = {
{ name = "weed_whitewidow_seed" , price = 15 , amount = 150 , minrep = 0 },
{ name = "weed_skunk_seed" , price = 15 , amount = 150 , minrep = 0 },
{ name = "weed_purplehaze_seed" , price = 15 , amount = 150 , minrep = 0 },
{ name = "weed_ogkush_seed" , price = 15 , amount = 150 , minrep = 0 },
{ name = "weed_amnesia_seed" , price = 15 , amount = 150 , minrep = 0 },
}
2026-01-16 02:57:26 -07:00
local Dealers = {}
2025-08-09 03:10:00 -06:00
2026-01-16 02:57:26 -07:00
Bridge.Callback . Register ( 'md-drugs:server:dealerList' , function ( source , location )
local coords = json.decode ( Dealers [ location ]. coords )
coords = vector3 ( coords.x , coords.y , coords.z )
2026-01-19 00:46:49 -07:00
if not checkDistance ( source , coords , 4.0 , 'md-drugs:server:dealerList' ) then
2026-01-16 02:57:26 -07:00
return
2023-12-07 15:45:48 -08:00
end
2026-01-16 02:57:26 -07:00
return Products
2023-12-07 15:45:48 -08:00
end )
2024-11-12 01:04:42 -08:00
2024-11-23 15:33:17 -08:00
local DeliveryItems = {
{ item = "weed_brick" , minrep = 0 , payout = { min = 10 , max = 50 }},
{ item = "coke_brick" , minrep = 0 , payout = { min = 10 , max = 50 }},
}
2026-01-16 02:57:26 -07:00
Bridge.Callback . Register ( 'md-drugs:server:GetDeliveryItem' , function ( source , data )
2023-12-07 15:45:48 -08:00
local src = source
2024-11-23 15:33:17 -08:00
local itemnum = math.random ( 1 , # DeliveryItems )
local item = DeliveryItems [ itemnum ]. item
2024-09-24 15:07:41 -07:00
local amount = math.random ( 1 , 4 )
2026-01-16 02:57:26 -07:00
local check = MySQL.query . await ( 'SELECT * FROM deliveriesdealer WHERE cid = ?' , { Bridge.Framework . GetPlayerIdentifier ( src )})
2024-11-23 15:33:17 -08:00
local locnum = math.random ( 1 , # dloc )
2024-09-24 15:07:41 -07:00
local coord = json.encode ({
2024-11-23 15:33:17 -08:00
x = dloc [ locnum ]. coords.x ,
y = dloc [ locnum ]. coords.y ,
z = dloc [ locnum ]. coords.z ,
w = dloc [ locnum ]. coords.w
2024-09-24 15:07:41 -07:00
})
if not check [ 1 ] then
MySQL.insert ( 'INSERT INTO deliveriesdealer SET cid = ?, itemdata = ?, timestart = ?, maxtime = ?, location = ?' ,
2026-01-16 02:57:26 -07:00
{ Bridge.Framework . GetPlayerIdentifier ( src ), json.encode ({ item = item , amount = amount }), os.time (), os.time () + ( 15 * 60 ), coord })
Bridge.Inventory . AddItem ( src , item , amount )
2025-09-15 21:43:22 -07:00
local tab = {
bool = true ,
item = item ,
amount = amount ,
coords = coord
}
return tab
2024-09-24 15:07:41 -07:00
else
local time = os.time ()
local timeout = math.floor ( os.difftime ( time , check [ 1 ]. maxtime ) / 60 )
2025-08-09 03:10:00 -06:00
if timeout > 15 then
2026-01-16 02:57:26 -07:00
MySQL.query . await ( 'DELETE FROM deliveriesdealer WHERE cid = ?' , { Bridge.Framework . GetPlayerIdentifier ( src )})
Bridge.Notify . SendNotify ( src , Bridge.Language . Locale ( 'Deliveries.slowAf' ), 'error' )
2025-09-15 21:43:22 -07:00
return { bool = false }
2025-08-09 03:10:00 -06:00
end
2026-01-16 02:57:26 -07:00
Bridge.Notify . SendNotify ( src , Bridge.Language . Locale ( 'Deliveries.alreadyDelivering' ), 'error' )
2025-09-15 21:43:22 -07:00
local tab = {
bool = false ,
item = item ,
amount = amount ,
coords = coord
}
return tab
2024-09-24 15:07:41 -07:00
end
2023-12-07 15:45:48 -08:00
end )
2024-09-24 15:07:41 -07:00
RegisterNetEvent ( 'md-drugs:server:giveDeliveryItems' , function ( item , amount )
2023-12-07 15:45:48 -08:00
local src = source
2026-01-16 02:57:26 -07:00
local id = Bridge.Framework . GetPlayerIdentifier ( src )
local check = MySQL.query . await ( 'SELECT * FROM deliveriesdealer WHERE cid = ?' , { id })
2024-09-24 15:07:41 -07:00
if not check [ 1 ] then return end
local time = os.time ()
local timeout = math.floor ( os.difftime ( time , check [ 1 ]. maxtime ) / 60 )
local itemData = json.decode ( check [ 1 ]. itemdata )
2025-08-09 03:10:00 -06:00
if timeout >= 15 then
2026-01-16 02:57:26 -07:00
MySQL.query . await ( 'DELETE FROM deliveriesdealer WHERE cid = ?' , { id })
Bridge.Notify . SendNotify ( src , Bridge.Language . Locale ( 'Deliveries.slowAf' ), 'error' )
2025-08-09 03:10:00 -06:00
return
end
2026-01-16 02:57:26 -07:00
2024-09-24 15:07:41 -07:00
if item ~= itemData.item then return end
if amount ~= itemData.amount then return end
2026-01-16 02:57:26 -07:00
local coords = json.decode ( check [ 1 ]. location )
coords = vector3 ( coords.x , coords.y , coords.z )
2026-01-19 00:46:49 -07:00
if not checkDistance ( src , coords , 5.0 , 'md-drugs:server:giveDeliveryItems' ) then
2026-01-16 02:57:26 -07:00
return
end
if Bridge.Inventory . RemoveItem ( src , item , amount ) then
2024-11-23 15:33:17 -08:00
for k , v in pairs ( DeliveryItems ) do
2024-09-24 15:07:41 -07:00
if v.item == item then
local income = math.random ( v.payout . min , v.payout . max )
2026-01-16 02:57:26 -07:00
Bridge.Framework . AddAccountBalance ( src , 'cash' , income )
AddRep ( src , 'dealerrep' )
2023-12-07 15:45:48 -08:00
end
end
2026-01-16 02:57:26 -07:00
MySQL.query . await ( 'DELETE FROM deliveriesdealer WHERE cid = ?' , { id })
2023-12-07 15:45:48 -08:00
end
end )
2026-01-16 02:57:26 -07:00
-- TODO: COmmands
2025-08-09 03:10:00 -06:00
ps.registerCommand ( "newdealer" , {
2026-01-16 02:57:26 -07:00
help = Bridge.Language . Locale ( 'Deliveries.newDealerHelp.help' ),
2025-08-09 03:10:00 -06:00
description = {
2026-01-16 02:57:26 -07:00
{ name = "name" , help = Bridge.Language . Locale ( 'Deliveries.newDealerHelp.name' ), type = "string" },
{ name = "min" , help = Bridge.Language . Locale ( 'Deliveries.newDealerHelp.timeMin' ), type = "number" },
{ name = "max" , help = Bridge.Language . Locale ( 'Deliveries.newDealerHelp.timeMax' ), type = "number" }
2024-11-12 17:08:02 -08:00
},
2025-08-09 03:10:00 -06:00
admin = true ,
2024-11-12 17:08:02 -08:00
}, function ( source , args )
2023-12-07 15:45:48 -08:00
local ped = GetPlayerPed ( source )
local coords = GetEntityCoords ( ped )
2025-08-09 03:10:00 -06:00
local Player = ps.getPlayer ( source )
2023-12-07 15:45:48 -08:00
if not Player then return end
2024-11-12 17:08:02 -08:00
2025-09-15 21:31:49 -07:00
local dealerName = args [ 1 ]
2023-12-07 15:45:48 -08:00
local pos = json.encode ({ x = coords.x , y = coords.y , z = coords.z })
2025-08-09 03:10:00 -06:00
2024-11-12 17:08:02 -08:00
local result = MySQL.scalar . await ( 'SELECT name FROM dealers WHERE name = ?' , { dealerName })
if result then
2026-01-16 02:57:26 -07:00
return Bridge.Notify . SendNotify ( source , Bridge.Language . Locale ( 'Deliveries.DealerExists' ), "error" )
2024-11-12 17:08:02 -08:00
end
MySQL.insert ( 'INSERT INTO dealers (name, coords, time, createdby) VALUES (?, ?, ?, ?)' , {
2026-01-16 02:57:26 -07:00
dealerName , pos , 'nil' , Bridge.Framework . GetPlayerIdentifier ( source )
})
Wait ( 1000 )
Locations.Dealers = MySQL.query . await ( 'SELECT * FROM dealers' )
GlobalState.MDDrugsLocations = Locations
TriggerClientEvent ( 'md-drugs:client:RefreshDealers' , - 1 )
2024-11-12 17:08:02 -08:00
end )
2025-08-09 03:10:00 -06:00
ps.registerCommand ( "deletedealer" , {
2026-01-16 02:57:26 -07:00
help = Bridge.Language . Locale ( 'Deliveries.deleteDealerHelp.help' ),
2025-08-09 03:10:00 -06:00
description = {
2026-01-16 02:57:26 -07:00
{ name = "name" , help = Bridge.Language . Locale ( 'Deliveries.deleteDealerHelp.name' ), type = "string" }
2024-11-12 17:08:02 -08:00
},
2025-08-09 03:10:00 -06:00
admin = true
2024-11-12 17:08:02 -08:00
}, function ( source , args )
local dealerName = args.name
local result = MySQL.scalar . await ( 'SELECT * FROM dealers WHERE name = ?' , { dealerName })
2023-12-07 15:45:48 -08:00
2025-09-15 21:31:49 -07:00
if result and result [ 1 ] then
2024-11-12 17:08:02 -08:00
MySQL.query ( 'DELETE FROM dealers WHERE name = ?' , { dealerName })
2026-01-16 02:57:26 -07:00
Wait ( 1000 )
Locations.Dealers = MySQL.query . await ( 'SELECT * FROM dealers' )
GlobalState.MDDrugsLocations = Locations
TriggerClientEvent ( 'md-drugs:client:RefreshDealers' , - 1 )
Bridge.Notify . SendNotify ( source , Bridge.Language . Locale ( 'Deliveries.deleteDealerSuccess' ), "success" )
2023-12-07 15:45:48 -08:00
else
2026-01-16 02:57:26 -07:00
Bridge.Notify . SendNotify ( source , Bridge.Language . Locale ( 'Deliveries.deleteDealerFail' ), "error" )
2025-08-09 03:10:00 -06:00
end
end )
2026-01-19 00:38:01 -07:00
2026-01-16 02:57:26 -07:00
RegisterNetEvent ( 'md-drugs:server:buyItemDealer' , function ( num , loc )
2025-08-09 03:10:00 -06:00
local src = source
local itemData = Products [ num ]
if not itemData then return end
2026-01-16 02:57:26 -07:00
local coords = json.decode ( Dealers [ loc ]. coords )
coords = vector3 ( coords.x , coords.y , coords.z )
2026-01-19 00:46:49 -07:00
if not checkDistance ( src , coords , 5.0 , 'md-drugs:server:buyItemDealer' ) then
2026-01-16 02:57:26 -07:00
return
end
if not Bridge.Framework . RemoveAccountBalance ( src , 'cash' , itemData.price ) or not Bridge.Framework . RemoveAccountBalance ( src , 'bank' , itemData.price ) then
Bridge.Notify . SendNotify ( src , Bridge.Language . Locale ( 'Catches.notEnoughMoney' ), 'error' )
2025-08-09 03:10:00 -06:00
return
2023-12-07 15:45:48 -08:00
end
2026-01-16 02:57:26 -07:00
Bridge.Inventory . AddItem ( src , itemData.name , 1 )
2026-01-19 00:38:01 -07:00
Bridge.Notify . SendNotify ( src , string.format ( Bridge.Language . Locale ( 'Deliveries.buyItemSuccess' ), 1 , Bridge.Inventory . GetItemInfo ( itemData.name ). label , itemData.price ), 'success' )
2026-01-16 02:57:26 -07:00
end )
Dealers = MySQL.query . await ( 'SELECT * FROM dealers' )
if Dealers and not Dealers [ 1 ] then
MySQL.insert ( 'INSERT INTO dealers SET name = ?, coords = ?, time = ?, createdby = ?' , { 'MD' , json.encode ({ x = 899.98 , y = - 2603.24 , z = 6.11 , h = 176.12 }), 'any' , 'code Newb' })
end
Locations.Dealers = Dealers
GlobalState.MDDrugsLocations = Locations