-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.lua
More file actions
98 lines (88 loc) · 2.9 KB
/
client.lua
File metadata and controls
98 lines (88 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
local QBCore = exports['qb-core']:GetCoreObject()
-- Blip
CreateThread(function()
local blip = AddBlipForCoord(Config.ShopLocation)
SetBlipSprite(blip, Config.ShopBlip.sprite)
SetBlipDisplay(blip, 4)
SetBlipScale(blip, Config.ShopBlip.scale)
SetBlipColour(blip, Config.ShopBlip.color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(Config.ShopBlip.name)
EndTextCommandSetBlipName(blip)
end)
-- Marker and interaction
CreateThread(function()
while true do
Wait(0)
local player = PlayerPedId()
local coords = GetEntityCoords(player)
local dist = #(coords - Config.ShopLocation)
if dist < 10.0 then
DrawMarker(2, Config.ShopLocation.x, Config.ShopLocation.y, Config.ShopLocation.z, 0, 0, 0, 0, 0, 0, 0.4, 0.4, 0.4, 0, 255, 100, 200, false, true)
if dist < 1.5 then
DrawText3D(Config.ShopLocation, "[E] Open Marketplace")
if IsControlJustReleased(0, 38) then
TriggerServerEvent("rod_market:getItems") -- Fetch server item list
end
end
else
Wait(500)
end
end
end)
-- Draw Text
function DrawText3D(pos, text)
SetTextScale(0.35, 0.35)
SetTextFont(4)
SetTextProportional(1)
SetTextColour(255, 255, 255, 215)
SetTextEntry("STRING")
SetTextCentre(true)
AddTextComponentString(text)
DrawText(_x, _y)
end
-- Receive item list and open menu
RegisterNetEvent("rod_market:openMenu", function(items)
local menu = {}
for _, v in pairs(items) do
table.insert(menu, {
header = v.name .. " - $" .. v.price,
txt = "Seller: " .. v.seller,
params = {
event = "rod_market:buyItem",
args = {
id = v.id
}
}
})
end
table.insert(menu, {
header = "💸 Sell an Item",
params = {
event = "rod_market:sellItem"
}
})
exports['qb-menu']:openMenu(menu)
end)
-- Sell menu input
RegisterNetEvent("rod_market:sellItem", function()
local keyboard = exports['qb-input']:ShowInput({
header = "List Item For Sale",
submitText = "List Item",
inputs = {
{
text = "Item Name (from inventory)", name = "item", type = "text", isRequired = true
},
{
text = "Amount", name = "amount", type = "number", isRequired = true
},
{
text = "Price per Item", name = "price", type = "number", isRequired = true
}
}
})
if keyboard then
TriggerServerEvent("rod_market:listItem", keyboard.item, tonumber(keyboard.amount), tonumber(keyboard.price))
end
end)