-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.lua
174 lines (148 loc) · 6.12 KB
/
client.lua
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
local QRCore = exports['qr-core']:GetCoreObject()
local blipsLoaded = {}
local blipHandles = {}
-- Load and display blips from server
Citizen.CreateThread(function()
while true do
Citizen.Wait(30000)
QRCore.Functions.TriggerCallback('getBlips', function(blips)
for _, blip in pairs(blipsLoaded) do
RemoveBlip(blip)
end
blipHandles = {}
local hour = GetClockHours()
for _, info in pairs(blips) do
local currentColor = (hour >= info.openTime and hour < info.closeTime) and info.openColor or info.closeColor
local blipId = Citizen.InvokeNative(0x554D9D53F696D002, 1664425300, info.position.x, info.position.y, info.position.z)
SetBlipSprite(blipId, info.sprite, 1)
Citizen.InvokeNative(0x662D364ABF16DE2F, blipId, GetHashKey(currentColor))
local varString = CreateVarString(10, 'LITERAL_STRING', info.name)
Citizen.InvokeNative(0x9CB1A1623062F402, blipId, varString)
table.insert(blipsLoaded, blipId)
blipHandles[info.name] = blipId
end
end)
end
end)
-- Menu to Add and Remove Blips
local blipMenu = {
id = 'blip_manager',
title = 'Blips Management',
options = {
{
title = 'Add Blips',
onSelect = function()
local input = lib.inputDialog('Blips Management', {
{type = 'input', label = 'Blip Name', required = true},
{type = 'number', label = 'Sprite ID',required = true},
{type = 'input', label = 'Position (format: x,y,z)', pattern = "^-?\\d+\\.?\\d*,\\s?-?\\d+\\.?\\d*,\\s?-?\\d+\\.?\\d*$", required = true},
{type = 'number', label = 'Open Time (0-24)', min = 0, max = 24},
{type = 'number', label = 'Close Time (0-24)', min = 0, max = 24},
{type = 'input', label = 'Color when open', default = 'BLIP_MODIFIER_MP_COLOR_1'},
{type = 'input', label = 'Color when closed', default = 'BLIP_MODIFIER_MP_COLOR_2'}
})
if input then
local coords = stringsplit(input[3], ",")
local blipData = {
name = input[1],
sprite = tonumber(input[2]),
position = vector3(tonumber(coords[1]), tonumber(coords[2]), tonumber(coords[3])),
openTime = tonumber(input[4]),
closeTime = tonumber(input[5]),
openColor = input[6],
closeColor = input[7]
}
QRCore.Functions.TriggerCallback('addBlip', function(success)
if success then
addBlipToMap(blipData)
print("Blip added successfully!")
else
print("Failed to add blip!")
end
end, blipData)
end
end
},
{
title = 'Remove Blip',
onSelect = function()
QRCore.Functions.TriggerCallback('getBlips', function(blips)
local blipOptions = {}
for _, blip in pairs(blips) do
table.insert(blipOptions, {
title = blip.name,
onSelect = function()
QRCore.Functions.TriggerCallback('removeBlip', function(success)
if success then
removeBlipByName(blip.name)
print("Blip removed successfully!")
else
print("Failed to remove blip!")
end
end, blip.name)
end
})
end
lib.registerContext({
id = 'remove_blip_menu',
title = 'Select Blip to Remove',
options = blipOptions
})
lib.showContext('remove_blip_menu')
end)
end
}
}
}
lib.registerContext(blipMenu)
-- Command to open the blip management menu
RegisterCommand("blipmenu", function()
lib.showContext('blip_manager')
end, false)
-- Add a single blip to the map
function addBlipToMap(blipData)
local hour = GetClockHours()
local currentColor = (hour >= blipData.openTime and hour < blipData.closeTime) and blipData.openColor or blipData.closeColor
local blipId = Citizen.InvokeNative(0x554D9D53F696D002, 1664425300, blipData.position.x, blipData.position.y, blipData.position.z)
SetBlipSprite(blipId, blipData.sprite, 1)
Citizen.InvokeNative(0x662D364ABF16DE2F, blipId, GetHashKey(currentColor))
local varString = CreateVarString(10, 'LITERAL_STRING', blipData.name)
Citizen.InvokeNative(0x9CB1A1623062F402, blipId, varString)
table.insert(blipsLoaded, blipId)
blipHandles[blipData.name] = blipId
end
-- Remove a single blip from the map by its name
function removeBlipByName(blipName)
local blipId = blipHandles[blipName]
if blipId then
RemoveBlip(blipId)
blipHandles[blipName] = nil
for i=#blipsLoaded, 1, -1 do
if blipsLoaded[i] == blipId then
table.remove(blipsLoaded, i)
break
end
end
end
end
-- Helper function to split strings
function stringsplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t = {}
for str in string.gmatch(inputstr, "([^" .. sep .. "]+)") do
table.insert(t, str)
end
return t
end
-- Exports
exports('addBlip', function(blipData)
addBlipToMap(blipData)
end)
exports('removeBlip', function(blipName)
removeBlipByName(blipName)
end)
exports('getAllBlips', function()
return blipsLoaded
end)