diff --git a/resources/[system]/scoreboard/cl_scoreboard.lua b/resources/[system]/scoreboard/cl_scoreboard.lua
new file mode 100644
index 000000000..847de354e
--- /dev/null
+++ b/resources/[system]/scoreboard/cl_scoreboard.lua
@@ -0,0 +1,48 @@
+local plyTable = {}
+
+RegisterNetEvent('fivem:playerJoined', function(source, name)
+ plyTable[source] = name
+end)
+
+RegisterNetEvent('fivem:syncPlayerData', function(scoreTbl)
+ plyTable = scoreTbl
+end)
+
+RegisterNetEvent('fivem:playerLeft', function(source)
+ plyTable[source] = nil
+end)
+
+RegisterCommand('+scoreboard', function()
+ local localPly = PlayerPedId()
+ local players = {}
+ for serverId, name in pairs(plyTable) do
+ local ply = GetPlayerFromServerId(serverId)
+ local wantedLevel
+ local r, g, b = 255, 255, 255
+ -- if the player exists and isnt themselves.
+ if ply ~= localPly then
+ wantedLevel = GetPlayerWantedLevel(ply)
+ r, g, b = GetPlayerRgbColour(ply)
+ end
+ players[#players + 1] = '
' .. serverId .. ' | ' .. sanitize(name) .. ' | ' .. (wantedLevel and wantedLevel or tostring(0)) .. ' |
'
+ end
+ SendNUIMessage({ text = table.concat(players) })
+end)
+RegisterCommand('-scoreboard', function()
+ SendNUIMessage({
+ meta = 'close'
+ })
+end)
+RegisterKeyMapping('+scoreboard', 'Opens Scoreboard', 'keyboard', GetConvar('scoreboard_toggleScoreboard', 'UP'))
+
+function sanitize(txt)
+ local replacements = {
+ ['&' ] = '&',
+ ['<' ] = '<',
+ ['>' ] = '>',
+ ['\n'] = '
'
+ }
+ return txt
+ :gsub('[&<>\n]', replacements)
+ :gsub(' +', function(s) return ' '..(' '):rep(#s-1) end)
+end
diff --git a/resources/[system]/scoreboard/fxmanifest.lua b/resources/[system]/scoreboard/fxmanifest.lua
index f2657fa06..5b700cbf1 100644
--- a/resources/[system]/scoreboard/fxmanifest.lua
+++ b/resources/[system]/scoreboard/fxmanifest.lua
@@ -9,7 +9,8 @@ repository 'https://github.com/citizenfx/cfx-server-data'
-- temporary!
ui_page 'html/scoreboard.html'
-client_script 'scoreboard.lua'
+client_script 'cl_scoreboard.lua'
+server_script 'sv_scoreboard.lua'
files {
'html/scoreboard.html',
diff --git a/resources/[system]/scoreboard/scoreboard.lua b/resources/[system]/scoreboard/scoreboard.lua
deleted file mode 100644
index 4d0efdb30..000000000
--- a/resources/[system]/scoreboard/scoreboard.lua
+++ /dev/null
@@ -1,48 +0,0 @@
-local listOn = false
-
-Citizen.CreateThread(function()
- listOn = false
- while true do
- Wait(0)
-
- if IsControlPressed(0, 27)--[[ INPUT_PHONE ]] then
- if not listOn then
- local players = {}
- local ptable = GetActivePlayers()
- for _, i in ipairs(ptable) do
- local wantedLevel = GetPlayerWantedLevel(i)
- r, g, b = GetPlayerRgbColour(i)
- table.insert(players,
- '' .. GetPlayerServerId(i) .. ' | ' .. sanitize(GetPlayerName(i)) .. ' | ' .. (wantedLevel and wantedLevel or tostring(0)) .. ' |
'
- )
- end
-
- SendNUIMessage({ text = table.concat(players) })
-
- listOn = true
- while listOn do
- Wait(0)
- if(IsControlPressed(0, 27) == false) then
- listOn = false
- SendNUIMessage({
- meta = 'close'
- })
- break
- end
- end
- end
- end
- end
-end)
-
-function sanitize(txt)
- local replacements = {
- ['&' ] = '&',
- ['<' ] = '<',
- ['>' ] = '>',
- ['\n'] = '
'
- }
- return txt
- :gsub('[&<>\n]', replacements)
- :gsub(' +', function(s) return ' '..(' '):rep(#s-1) end)
-end
diff --git a/resources/[system]/scoreboard/sv_scoreboard.lua b/resources/[system]/scoreboard/sv_scoreboard.lua
new file mode 100644
index 000000000..2d9edb0aa
--- /dev/null
+++ b/resources/[system]/scoreboard/sv_scoreboard.lua
@@ -0,0 +1,17 @@
+-- prevent the possibility of someone spamming this event to try and net lag the server.
+local joinedTbl = {}
+RegisterNetEvent('playerJoined', function()
+ local name = GetPlayerName(source)
+ if not joinedTbl[source] then
+ joinedTbl[source] = name
+ TriggerClientEvent('fivem:playerJoined', -1, source, name)
+ TriggerClientEvent('fivem:syncPlayerData', source, joinedTbl)
+ else
+ print(('%s [%s] tried sending the \'playerJoined\' net event, but they\'ve already joined!'):format(name, source))
+ end
+end)
+
+AddEventHandler('playerDropped', function()
+ joinedTbl[source] = nil
+ TriggerClientEvent('fivem:playerLeft', -1, source)
+end)
\ No newline at end of file