-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #725 from bitpredator/dev
feat: esx_scoreboard
- Loading branch information
Showing
6 changed files
with
742 additions
and
0 deletions.
There are no files selected for viewing
235 changes: 235 additions & 0 deletions
235
server-data/resources/[esx_addons]/esx_scoreboard/client/main.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,235 @@ | ||
--- CrazyFox Discord Channel: https://discord.gg/4E8sth5 | ||
local Keys = { | ||
["ESC"] = 322, | ||
["F1"] = 288, | ||
["F2"] = 289, | ||
["F3"] = 170, | ||
["F5"] = 166, | ||
["F6"] = 167, | ||
["F7"] = 168, | ||
["F8"] = 169, | ||
["F9"] = 56, | ||
["F10"] = 57, | ||
["~"] = 243, | ||
["1"] = 157, | ||
["2"] = 158, | ||
["3"] = 160, | ||
["4"] = 164, | ||
["5"] = 165, | ||
["6"] = 159, | ||
["7"] = 161, | ||
["8"] = 162, | ||
["9"] = 163, | ||
["-"] = 84, | ||
["="] = 83, | ||
["BACKSPACE"] = 177, | ||
["TAB"] = 37, | ||
["Q"] = 44, | ||
["W"] = 32, | ||
["E"] = 38, | ||
["R"] = 45, | ||
["T"] = 245, | ||
["Y"] = 246, | ||
["U"] = 303, | ||
["P"] = 199, | ||
["["] = 39, | ||
["]"] = 40, | ||
["ENTER"] = 18, | ||
["CAPS"] = 137, | ||
["A"] = 34, | ||
["S"] = 8, | ||
["D"] = 9, | ||
["F"] = 23, | ||
["G"] = 47, | ||
["H"] = 74, | ||
["K"] = 311, | ||
["L"] = 182, | ||
["LEFTSHIFT"] = 21, | ||
["Z"] = 20, | ||
["X"] = 73, | ||
["C"] = 26, | ||
["V"] = 0, | ||
["B"] = 29, | ||
["N"] = 249, | ||
["M"] = 244, | ||
[","] = 82, | ||
["."] = 81, | ||
["LEFTCTRL"] = 36, | ||
["LEFTALT"] = 19, | ||
["SPACE"] = 22, | ||
["RIGHTCTRL"] = 70, | ||
["HOME"] = 213, | ||
["PAGEUP"] = 10, | ||
["PAGEDOWN"] = 11, | ||
["DELETE"] = 178, | ||
["LEFT"] = 174, | ||
["RIGHT"] = 175, | ||
["TOP"] = 27, | ||
["DOWN"] = 173, | ||
["NENTER"] = 201, | ||
["N4"] = 108, | ||
["N5"] = 60, | ||
["N6"] = 107, | ||
["N+"] = 96, | ||
["N-"] = 97, | ||
["N7"] = 117, | ||
["N8"] = 61, | ||
["N9"] = 118, | ||
} | ||
|
||
local idVisable = true | ||
|
||
Citizen.CreateThread(function() | ||
ESX = exports["es_extended"]:getSharedObject() | ||
|
||
Citizen.Wait(2000) | ||
ESX.TriggerServerCallback("esx_scoreboard:getConnectedPlayers", function(connectedPlayers) | ||
UpdatePlayerTable(connectedPlayers) | ||
end) | ||
end) | ||
|
||
Citizen.CreateThread(function() | ||
Citizen.Wait(500) | ||
SendNUIMessage({ | ||
action = "updateServerInfo", | ||
|
||
maxPlayers = GetConvarInt("sv_maxclients", 48), | ||
}) | ||
end) | ||
|
||
RegisterNetEvent("esx_scoreboard:updateConnectedPlayers") | ||
AddEventHandler("esx_scoreboard:updateConnectedPlayers", function(connectedPlayers) | ||
UpdatePlayerTable(connectedPlayers) | ||
end) | ||
|
||
RegisterNetEvent("esx_scoreboard:updatePing") | ||
AddEventHandler("esx_scoreboard:updatePing", function(connectedPlayers) | ||
SendNUIMessage({ | ||
action = "updatePing", | ||
players = connectedPlayers, | ||
}) | ||
end) | ||
|
||
RegisterNetEvent("esx_scoreboard:toggleID") | ||
AddEventHandler("esx_scoreboard:toggleID", function(state) | ||
if state then | ||
idVisable = state | ||
else | ||
idVisable = not idVisable | ||
end | ||
|
||
SendNUIMessage({ | ||
action = "toggleID", | ||
state = idVisable, | ||
}) | ||
end) | ||
|
||
function UpdatePlayerTable(connectedPlayers) | ||
local formattedPlayerList, num = {}, 1 | ||
local players = 0 | ||
|
||
for _, v in pairs(connectedPlayers) do | ||
if num == 1 then | ||
table.insert(formattedPlayerList, ("<tr><td>%s</td><td>%s</td><td>%s</td>"):format(v.name, v.id, v.ping)) | ||
num = 2 | ||
elseif num == 2 then | ||
table.insert(formattedPlayerList, ("<td>%s</td><td>%s</td><td>%s</td>"):format(v.name, v.id, v.ping)) | ||
num = 3 | ||
elseif num == 3 then | ||
table.insert(formattedPlayerList, ("<td>%s</td><td>%s</td><td>%s</td></tr>"):format(v.name, v.id, v.ping)) | ||
num = 1 | ||
end | ||
|
||
players = players + 1 | ||
end | ||
|
||
if (num == 1) or (num == 2) then | ||
table.insert(formattedPlayerList, "</tr>") | ||
end | ||
|
||
SendNUIMessage({ | ||
action = "updatePlayerList", | ||
players = table.concat(formattedPlayerList), | ||
}) | ||
end | ||
|
||
Citizen.CreateThread(function() | ||
while true do | ||
Citizen.Wait(0) | ||
|
||
if IsControlJustReleased(0, Keys["F10"]) and IsInputDisabled(0) then | ||
ToggleScoreBoard() | ||
Citizen.Wait(200) | ||
|
||
-- D-pad up on controllers works, too! | ||
elseif IsControlJustReleased(0, 172) and not IsInputDisabled(0) then | ||
ToggleScoreBoard() | ||
Citizen.Wait(200) | ||
end | ||
end | ||
end) | ||
|
||
-- Close scoreboard when game is paused | ||
local IsPaused | ||
Citizen.CreateThread(function() | ||
while true do | ||
Citizen.Wait(300) | ||
|
||
if IsPauseMenuActive() and not IsPaused then | ||
IsPaused = true | ||
SendNUIMessage({ | ||
action = "close", | ||
}) | ||
elseif not IsPauseMenuActive() and IsPaused then | ||
IsPaused = false | ||
end | ||
end | ||
end) | ||
|
||
local scorebo = false | ||
function ToggleScoreBoard() | ||
scorebo = not scorebo | ||
if scorebo then | ||
SetTimecycleModifier("default") | ||
else | ||
SetTimecycleModifier("default") | ||
end | ||
SendNUIMessage({ | ||
action = "toggle", | ||
}) | ||
end | ||
|
||
local disabled = false | ||
Citizen.CreateThread(function() | ||
while true do | ||
Citizen.Wait(0) | ||
|
||
if scorebo then | ||
--if not disabled then | ||
--DisableControlAction(0,169,true) | ||
DisableControlAction(24, 99, true) | ||
DisableControlAction(24, 16, true) | ||
DisableControlAction(24, 17, true) | ||
DisableControlAction(29, 242, true) | ||
disabled = true | ||
--end | ||
if IsControlJustReleased(29, 241) then | ||
SendNUIMessage({ | ||
action = "scrollUP", | ||
}) | ||
elseif IsDisabledControlJustReleased(29, 242) then | ||
SendNUIMessage({ | ||
action = "scrollDOWN", | ||
}) | ||
end | ||
elseif not scorebo then | ||
if disabled then | ||
EnableControlAction(24, 99, true) | ||
EnableControlAction(24, 16, true) | ||
EnableControlAction(24, 17, true) | ||
EnableControlAction(29, 242, true) | ||
disabled = false | ||
end | ||
end | ||
end | ||
end) |
18 changes: 18 additions & 0 deletions
18
server-data/resources/[esx_addons]/esx_scoreboard/fxmanifest.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
fx_version("cerulean") | ||
games({ "gta5" }) | ||
|
||
ui_page("html/scoreboard.html") | ||
|
||
files({ | ||
"html/*", | ||
}) | ||
|
||
shared_script("@es_extended/imports.lua") | ||
|
||
client_scripts({ | ||
"client/main.lua", | ||
}) | ||
|
||
server_scripts({ | ||
"server/main.lua", | ||
}) |
105 changes: 105 additions & 0 deletions
105
server-data/resources/[esx_addons]/esx_scoreboard/html/listener.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
var visable = false; | ||
$(function () { | ||
window.addEventListener('message', function (event) { | ||
switch (event.data.action) { | ||
case 'toggle': | ||
if (visable) { | ||
$('#wrap').fadeOut(); | ||
} else { | ||
$('#wrap').fadeIn(); | ||
} | ||
if (visable) { | ||
$('#wrap2').fadeOut(); | ||
} else { | ||
$('#wrap2').fadeIn(); | ||
} | ||
visable = !visable; | ||
break; | ||
case 'close': | ||
$('#wrap').fadeOut(); | ||
visable = false; | ||
break; | ||
case 'toggleID': | ||
if (event.data.state) { | ||
$('td:nth-child(2),th:nth-child(2)').show(); | ||
$('td:nth-child(5),th:nth-child(5)').show(); | ||
$('td:nth-child(8),th:nth-child(8)').show(); | ||
} else { | ||
$('td:nth-child(2),th:nth-child(2)').hide(); | ||
$('td:nth-child(5),th:nth-child(5)').hide(); | ||
$('td:nth-child(8),th:nth-child(8)').hide(); | ||
} | ||
break; | ||
case 'scrollUP': | ||
$("#style-1").scrollTop($("#style-1").scrollTop() - 100); | ||
break; | ||
case 'scrollDOWN': | ||
$("#style-1").scrollTop($("#style-1").scrollTop() + 100); | ||
break; | ||
case 'updatePlayerList': | ||
$('#playerlist tr:gt(0)').remove(); | ||
$('#playerlist').append(event.data.players); | ||
applyPingColor(); | ||
//sortPlayerList(); | ||
break; | ||
case 'updatePing': | ||
updatePing(event.data.players); | ||
applyPingColor(); | ||
break; | ||
case 'updateServerInfo': | ||
if (event.data.maxPlayers) { | ||
$('#max_players').html(event.data.maxPlayers); | ||
} | ||
break; | ||
default: | ||
console.log('esx_scoreboard: unknown action!'); | ||
break; | ||
} | ||
}, false); | ||
}); | ||
|
||
function applyPingColor() { | ||
$('#playerlist tr').each(function () { | ||
$(this).find('td:nth-child(3),td:nth-child(6),td:nth-child(9)').each(function () { | ||
var ping = $(this).html(); | ||
var color = 'green'; | ||
if (ping > 150 && ping < 190) { | ||
color = 'orange'; | ||
} else if (ping >= 200) { | ||
color = 'red'; | ||
} | ||
$(this).css('color', color); | ||
$(this).html(ping + " <span style='color:white;'>ms</span>"); | ||
}); | ||
}); | ||
} | ||
function updatePing(players) { | ||
jQuery.each(players, function (index, element) { | ||
if (element != null) { | ||
$('#playerlist tr:not(.heading)').each(function () { | ||
$(this).find('td:nth-child(2):contains(' + element.id + ')').each(function () { | ||
$(this).parent().find('td').eq(2).html(element.ping); | ||
}); | ||
$(this).find('td:nth-child(5):contains(' + element.id + ')').each(function () { | ||
$(this).parent().find('td').eq(5).html(element.ping); | ||
}); | ||
$(this).find('td:nth-child(8):contains(' + element.id + ')').each(function () { | ||
$(this).parent().find('td').eq(8).html(element.ping); | ||
}); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
function sortPlayerList() { | ||
var table = $('#playerlist'), | ||
rows = $('tr:not(.heading)', table); | ||
rows.sort(function (a, b) { | ||
var keyA = $('td', a).eq(1).html(); | ||
var keyB = $('td', b).eq(1).html(); | ||
return (keyA - keyB); | ||
}); | ||
rows.each(function (index, row) { | ||
table.append(row); | ||
}); | ||
} |
Oops, something went wrong.