-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
132 lines (113 loc) · 3.93 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
local QBCore = exports['qb-core']:GetCoreObject()
local hasOpenPlayerList = false
local showPlayerNames = false
local playerNamesCache = {}
-- Function to show the player list
function ShowPlayerList()
QBCore.Functions.TriggerCallback('bms:playerlist:getPlayerData', function(rdata)
if rdata.success then
local playerData = rdata.playerList
local staff = rdata.isStaff
local servertime = rdata.date
local sortedList = {}
if staff then
local iter = 0
local tkeys = {}
-- Populate the table that holds the keys
for k in pairs(playerData) do
iter = iter + 1
tkeys[iter] = k
end
-- Sort the keys
table.sort(tkeys)
iter = 0
-- Use the keys to retrieve the values in the sorted order
for _, k in ipairs(tkeys) do
iter = iter + 1
sortedList[iter] = playerData[k]
end
end
-- Cache player names
playerNamesCache = {}
for _, player in ipairs(playerData) do
playerNamesCache[player.id] = player.charname
end
if hasOpenPlayerList then
TriggerEvent('chat:addMessage', {
color = {243, 62, 62},
multiline = true,
args = {"REPORT IDS", "Displaying ids at time " .. servertime}
})
showPlayerNames = true
if staff then
SendNUIMessage({setPlayerData = true, plist = sortedList, st = staff})
end
end
end
end)
end
-- Function to hide the player list
function HidePlayerList()
SendNUIMessage({closeList = true})
showPlayerNames = false
end
-- Register command to show player list
RegisterCommand("+playerList", function()
if not hasOpenPlayerList then
hasOpenPlayerList = true
ShowPlayerList()
-- Send a message to the server to log the event
local playerData = QBCore.Functions.GetPlayerData()
local playerName = GetPlayerName(PlayerId())
local playerServerId = GetPlayerServerId(PlayerId())
local charName = playerData.charinfo.firstname .. ' ' .. playerData.charinfo.lastname
TriggerServerEvent('requestDateTime', playerName, playerServerId, charName)
end
end, false)
-- Register command to hide player list
RegisterCommand("-playerList", function()
hasOpenPlayerList = false
HidePlayerList()
end, false)
-- Key mapping for showing the player list
RegisterKeyMapping("+playerList", "(player) Show Player IDs", "keyboard", Config.KeyMapping.ShowPlayerList)
-- Function to draw 3D text with background
function DrawText3D(coords, text)
local onScreen, _x, _y = World3dToScreen2d(coords.x, coords.y, coords.z)
local px, py, pz = table.unpack(GetGameplayCamCoords())
SetTextScale(Config.TextScale, Config.TextScale)
SetTextFont(Config.TextFont)
SetTextProportional(Config.TextProportional)
SetTextEntry("STRING")
SetTextCentre(1)
AddTextComponentString(text)
-- Calculate width for the rectangle
local textWidth = (string.len(text)) / 370
-- Draw background rectangle first
DrawRect(_x, _y + 0.0125, 0.015 + textWidth, 0.03, table.unpack(Config.BackgroundColor))
-- Draw the text over the rectangle
SetTextColour(table.unpack(Config.TextColor))
DrawText(_x, _y)
end
-- Thread to display player IDs
CreateThread(function()
while true do
Wait(0)
if showPlayerNames then
local players = GetActivePlayers()
for i = 1, #players do
local player = players[i]
local ped = GetPlayerPed(player)
local playerCoords = GetEntityCoords(ped)
local playerServerId = GetPlayerServerId(player)
if player == PlayerId() then
DrawText3D(playerCoords + vector3(0, 0, 1.0), "[" .. playerServerId .. "] (You)")
else
DrawText3D(playerCoords + vector3(0, 0, 1.0), "[" .. playerServerId .. "]")
end
end
else
Wait(1000)
end
end
end)