From 994672d99c1ae494c1a5c6428a4b0f936e974ebd Mon Sep 17 00:00:00 2001 From: hydrant Date: Mon, 19 Apr 2021 01:54:14 +0200 Subject: [PATCH] NEUE ONLINELISTE DANKE EMRE.NL --- ReallifeGamemode.Client/Gui/playerlist.ts | 35 ++++++++++++++----- .../assets/html/onlinelist/index.html | 19 +++++----- .../assets/js/onlinelist/script.js | 24 +++++++------ ReallifeGamemode.Server/Events/Key.cs | 20 +++++++---- 4 files changed, 63 insertions(+), 35 deletions(-) diff --git a/ReallifeGamemode.Client/Gui/playerlist.ts b/ReallifeGamemode.Client/Gui/playerlist.ts index 3a136335..03ad7497 100644 --- a/ReallifeGamemode.Client/Gui/playerlist.ts +++ b/ReallifeGamemode.Client/Gui/playerlist.ts @@ -8,30 +8,47 @@ export default function playerList(globalData: IGlobalData): void { var playerlistBrowser: BrowserMp = null; var pList; + var factionPlayersMap: Map = new Map(); + const factionIds = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; mp.events.add("showPlayerlist", (playersJson) => { - + if (playerlistBrowser !== null) { playerlistBrowser.destroy(); playerlistBrowser = null; globalData.InMenu = false; mp.gui.cursor.show(false, false); - mp.gui.chat.activate(true); + mp.gui.chat.activate(true); } else if (!globalData.InMenu) { globalData.InMenu = true; - playerlistBrowser = mp.browsers.new('package://assets/html/Playerlist/Tabliste.html'); + playerlistBrowser = mp.browsers.new('package://assets/html/onlinelist/index.html'); mp.gui.chat.activate(false); mp.gui.cursor.show(true, true); pList = JSON.parse(playersJson); - pList.forEach((player) => { - playerlistBrowser.execute(`ad_row('${JSON.stringify(player.Id)}','${JSON.stringify(player.Name)}',${JSON.stringify(player.FactionName)},'${JSON.stringify(player.Ping)}');`); - }); - } + + + } }); - mp.events.add("CEF:fetchPlayerList", () => { - + mp.events.add("CEF:PlayerList_Loaded", () => { + factionIds.forEach(f => { + factionPlayersMap.set(f, 0); + }); + + pList.forEach((player) => { + var facId = player.FactionId; + + playerlistBrowser.execute(`addPlayerEntry('${player.Id}','${player.Name}', '${facId}', '${player.FactionName}','${player.Ping}');`); + + factionPlayersMap.set(facId, factionPlayersMap.get(facId) + 1); + }); + + factionPlayersMap.forEach((value, key) => { + playerlistBrowser.execute(`setPlayerCount(${key}, ${value});`) + }); + + playerlistBrowser.execute(`setPlayerCount(-1, ${pList.length});`); }); } diff --git a/ReallifeGamemode.Client/assets/html/onlinelist/index.html b/ReallifeGamemode.Client/assets/html/onlinelist/index.html index 023cb2bc..a052ea50 100644 --- a/ReallifeGamemode.Client/assets/html/onlinelist/index.html +++ b/ReallifeGamemode.Client/assets/html/onlinelist/index.html @@ -11,7 +11,7 @@

Spielerliste

-

Spieler:

+

Spieler: 0

@@ -29,23 +29,24 @@
    -
  1. LSPD: 5
  2. -
  3. FIB: 5
  4. -
  5. LSED: 5
  6. +
  7. LSPD: 0
  8. +
  9. FIB: 0
  10. +
  11. LSED: 0
    -
  1. GSF: 5
  2. -
  3. FYB: 5
  4. -
  5. LSV: 5
  6. +
  7. GSF: 0
  8. +
  9. FYB: 0
  10. +
  11. LSV: 0
    -
  1. NR: 5
  2. -
  3. Zivilisten: 5
  4. +
  5. NR: 0
  6. +
  7. Zivilisten: 0
+ \ No newline at end of file diff --git a/ReallifeGamemode.Client/assets/js/onlinelist/script.js b/ReallifeGamemode.Client/assets/js/onlinelist/script.js index db952af2..a1e8eae5 100644 --- a/ReallifeGamemode.Client/assets/js/onlinelist/script.js +++ b/ReallifeGamemode.Client/assets/js/onlinelist/script.js @@ -1,19 +1,23 @@ window.onbeforeunload = () => { window.scrollTo(0, 0); } +$(document).ready(function () { + mp.trigger('CEF:PlayerList_Loaded'); +}); + setPlayerCount = (factionId, value) => { - if (factionId == -1) { - document.getElementById('player-count').innerHTML = value; - } else if (factionId >= 0 && factionId <= 9) { - document.getElementById(factionId).innerHTML = value; - } + if (factionId == -1) { + document.getElementById('player-count').innerHTML = value; + } else if (factionId >= 0 && factionId <= 9) { + document.getElementById(factionId).innerHTML = value; + } } -addPlayerEntry = (userId, userName, factionId, factionName, userPing) => { - document.getElementById('players').innerHTML += `${userId} ${userName} ${factionName} ${userPing}`; +function addPlayerEntry(userId, userName, factionId, factionName, userPing) { + document.getElementById('players').innerHTML += `${userId} ${userName} ${factionName} ${userPing}`; } addPlayerEntries = (json) => { - JSON.parse(json).forEach(e => { - - }); + JSON.parse(json).forEach(e => { + + }); } diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index d0372911..ef44c839 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -453,7 +453,7 @@ namespace ReallifeGamemode.Server.Events int amount = 0; var tempFactionWeapon = weapons.Where(f => f.WeaponModel == weapon).FirstOrDefault(); - if(tempFactionWeapon != null) + if (tempFactionWeapon != null) { amount = tempFactionWeapon.Ammount; } @@ -513,7 +513,7 @@ namespace ReallifeGamemode.Server.Events player.SendNotification("~r~Im Dienst kannst du keine Kleidung kaufen", false); return; } - if(JobBase.GetPlayerInJob().Contains(player)) + if (JobBase.GetPlayerInJob().Contains(player)) { player.SendNotification("~r~Im aktiven Job kannst du keine Kleidung kaufen", false); return; @@ -686,12 +686,18 @@ namespace ReallifeGamemode.Server.Events List players = NAPI.Pools.GetAllPlayers().Where(p => p.IsLoggedIn() == true).OrderBy(o => o.Handle.Value).ToList(); - var listPlayers = players.Select(p => new + var listPlayers = players.Select(p => { - Id = p.Handle.Value, - p.Name, - p.Ping, - FactionName = p.GetUser()?.Faction?.Name ?? "Zivilist", + User u = p.GetUser(); + + return new + { + Id = p.Handle.Value, + p.Name, + p.Ping, + FactionName = u?.Faction?.Name ?? "Zivilist", + FactionId = u?.FactionId ?? 0 + }; }); player.TriggerEvent("showPlayerlist", JsonConvert.SerializeObject(listPlayers)); }