From 9f33cfbd89003da112862035edf1cab90a2c9a4f Mon Sep 17 00:00:00 2001 From: VegaZ Date: Sat, 29 Sep 2018 00:07:36 +0200 Subject: [PATCH 1/5] Initial commit for player keys --- Client/Player/keys.js | 37 ++++++++++++++++++++++ Client/index.js | 1 + Server/Commands/Admin.cs | 2 +- Server/Events/Key.cs | 47 ++++++++++++++++++++++++++++ Server/Events/SaveData.cs | 4 +-- Server/Extensions/ClientExtension.cs | 6 ++-- Server/Services/ChatService.cs | 4 +-- 7 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 Client/Player/keys.js create mode 100644 Server/Events/Key.cs diff --git a/Client/Player/keys.js b/Client/Player/keys.js new file mode 100644 index 00000000..d39d67ff --- /dev/null +++ b/Client/Player/keys.js @@ -0,0 +1,37 @@ +/** + * @overview Life of German Reallife - Player Keys keys.js + * @author VegaZ + * @copyright (c) 2008 - 2018 Life of German + */ + +//https://docs.microsoft.com/de-de/windows/desktop/inputdev/virtual-key-codes + +var chat = false; + +//ENTER +mp.keys.bind(0x0D, false, function () { + if (chat === true) { + chat = false; + } +}); + +//N +mp.keys.bind(0x4E, false, function () { + if (!chat) { + mp.events.callRemote("keyPress:N"); + } +}); + +//T +mp.keys.bind(0x54, false, function () { + if (chat === false) { + chat = true; + } +}); + +//X +mp.keys.bind(0x58, false, function () { + if (!chat) { + mp.events.callRemote("keyPress:X"); + } +}); diff --git a/Client/index.js b/Client/index.js index a0b043e1..a494dc53 100644 --- a/Client/index.js +++ b/Client/index.js @@ -6,6 +6,7 @@ require('./Gui/infobox.js'); require('./Login/main.js'); +require('./Player/keys.js'); require('./Save/main.js'); require('./FactionManagement/main.js'); diff --git a/Server/Commands/Admin.cs b/Server/Commands/Admin.cs index e1d95689..a88c4c11 100644 --- a/Server/Commands/Admin.cs +++ b/Server/Commands/Admin.cs @@ -665,7 +665,7 @@ namespace reallife_gamemode.Server.Commands { Vehicle vehicle = player.Vehicle; SaveData.SaveVehicleData((VehicleHash)vehicle.Model, vehicle.Position, vehicle.Heading, vehicle.NumberPlate, - Convert.ToByte(vehicle.PrimaryColor), Convert.ToByte(vehicle.SecondaryColor), vehicle.Locked, vehicle.EngineStatus, Convert.ToByte(vehicle.Dimension)); + Convert.ToByte(vehicle.PrimaryColor), Convert.ToByte(vehicle.SecondaryColor), vehicle.Locked, Convert.ToByte(vehicle.Dimension)); } else player.SendChatMessage("~m~Du sitzt in keinem Fahrzeug!"); break; diff --git a/Server/Events/Key.cs b/Server/Events/Key.cs new file mode 100644 index 00000000..f38999c9 --- /dev/null +++ b/Server/Events/Key.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Text; +using GTANetworkAPI; +/** +* @overview Life of German Reallife - Event Key (Key.cs) +* @author VegaZ +* @copyright (c) 2008 - 2018 Life of German +*/ + +namespace reallife_gamemode.Server.Events +{ + public class Key : Script + { + [RemoteEvent("keyPress:N")] + public void KeyPressN(Client player) + { + if (NAPI.Player.IsPlayerInAnyVehicle(player)) + { + bool engineStatus = NAPI.Vehicle.GetVehicleEngineStatus(player.Vehicle); + if (engineStatus == false) + { + player.Vehicle.EngineStatus = true; + } + else + { + player.Vehicle.EngineStatus = false; + } + } + } + [RemoteEvent("keyPress:X")] + public void KeyPressX(Client player) + { + if (NAPI.Player.IsPlayerInAnyVehicle(player)) + { + if (player.Seatbelt == false) + { + player.Seatbelt = true; + } + else + { + player.Seatbelt = false; + } + } + } + } +} diff --git a/Server/Events/SaveData.cs b/Server/Events/SaveData.cs index 01d32054..76df8990 100644 --- a/Server/Events/SaveData.cs +++ b/Server/Events/SaveData.cs @@ -50,7 +50,7 @@ namespace reallife_gamemode.Server.Events } public static void SaveVehicleData(VehicleHash vehicleModel, Vector3 vehiclePosition, float vehicleHeading, - string vehicleNumberPlate, byte vehiclePrimaryColor, byte vehicleSecondaryColor, bool vehicleLocked, bool vehicleEngine, byte vehicleDimension) + string vehicleNumberPlate, byte vehiclePrimaryColor, byte vehicleSecondaryColor, bool vehicleLocked, byte vehicleDimension) { using (var saveData = new Model.DatabaseContext()) { @@ -65,7 +65,7 @@ namespace reallife_gamemode.Server.Events PrimaryColor = vehiclePrimaryColor, SecondaryColor = vehicleSecondaryColor, Locked = vehicleLocked, - Engine = vehicleEngine, + Engine = false, Dimension = vehicleDimension, Active = true }; diff --git a/Server/Extensions/ClientExtension.cs b/Server/Extensions/ClientExtension.cs index c2b2e405..ab2762db 100644 --- a/Server/Extensions/ClientExtension.cs +++ b/Server/Extensions/ClientExtension.cs @@ -19,11 +19,9 @@ namespace reallife_gamemode.Server.Extensions { public static User GetUser(this Client client, DatabaseContext context = null) { -<<<<<<< HEAD + using (DatabaseContext dbContext = new DatabaseContext()) -======= if(context == null) ->>>>>>> feature/faction-system { using (context = new DatabaseContext()) { @@ -92,7 +90,7 @@ namespace reallife_gamemode.Server.Extensions { using (var unbanUser = new DatabaseContext()) { - var targetUser = unbanUser.Bans.FirstOrDefault(u => u.Id == target.GetUser().BanId); + var targetUser = unbanUser.Bans.FirstOrDefault(u => u.Id == target.GetUser(unbanUser).BanId); unbanUser.Bans.Remove(targetUser); unbanUser.SaveChanges(); } diff --git a/Server/Services/ChatService.cs b/Server/Services/ChatService.cs index bbd22361..4eaad24c 100644 --- a/Server/Services/ChatService.cs +++ b/Server/Services/ChatService.cs @@ -27,7 +27,6 @@ namespace reallife_gamemode.Server.Services player.SendChatMessage("~r~[FEHLER]~s~ Der Spieler wurde nicht gefunden."); } -<<<<<<< HEAD public static void PlayerNotLoggedIn(Client player) { player.SendChatMessage("~r~[FEHLER]~s~ Du bist nicht eingeloggt."); @@ -35,7 +34,7 @@ namespace reallife_gamemode.Server.Services public static void ErrorMsg(Client player) { player.SendChatMessage("~r~[FEHLER]~s~ Die Aktion wurde nicht ausgeführt."); -======= + } public static void BroadcastFaction(string message, List factions) { using (var dbCon = new DatabaseContext()) @@ -57,7 +56,6 @@ namespace reallife_gamemode.Server.Services public static void BroadcastFaction(string message, Faction faction) { BroadcastFaction(message, new List { faction }); ->>>>>>> feature/faction-system } } } From d9d9b06914a3e7399523892896cef50caf11919a Mon Sep 17 00:00:00 2001 From: VegaZ Date: Wed, 3 Oct 2018 19:02:48 +0200 Subject: [PATCH 2/5] Add Playerlist (tablist) --- Client/Gui/playerlist.html | 31 +++++++++++++++++++++++++++++++ Client/Gui/playerlist.js | 24 ++++++++++++++++++++++++ Client/Gui/style.css | 38 ++++++++++++++++++++++++++++++++++++++ Client/Player/keys.js | 8 ++++++++ Client/index.js | 1 + Server/Events/Key.cs | 18 ++++++++++++++++++ Server/Util/ListPlayer.cs | 20 ++++++++++++++++++++ 7 files changed, 140 insertions(+) create mode 100644 Client/Gui/playerlist.html create mode 100644 Client/Gui/playerlist.js create mode 100644 Client/Gui/style.css create mode 100644 Server/Util/ListPlayer.cs diff --git a/Client/Gui/playerlist.html b/Client/Gui/playerlist.html new file mode 100644 index 00000000..bb55c176 --- /dev/null +++ b/Client/Gui/playerlist.html @@ -0,0 +1,31 @@ + + + + + + + + + + +
+ + + + + + + + + + + +
ID
Name
Ping
+
+ + + \ No newline at end of file diff --git a/Client/Gui/playerlist.js b/Client/Gui/playerlist.js new file mode 100644 index 00000000..e7610890 --- /dev/null +++ b/Client/Gui/playerlist.js @@ -0,0 +1,24 @@ +/** + * @overview Life of German Reallife - Gui Playerlist playerlist.js + * @author VegaZ + * @copyright (c) 2008 - 2018 Life of German + */ + +var playerlistBrowser +var pList; + +mp.events.add("showPlayerlist", () => { + if (!playerlistBrowser) { + playerlistBrowser = mp.browsers.new('package://Gui/playerlist.html'); + mp.gui.chat.activate(false); + mp.gui.cursor.show(true, true); + } +}); + +mp.events.add("fetchPlayerList", (players) => { + + for (var player in players) + { + mp.gui.chat.push(player["Id"] + ", " + player["Name"] + ", " + player["Ping"]) + } +}); \ No newline at end of file diff --git a/Client/Gui/style.css b/Client/Gui/style.css new file mode 100644 index 00000000..d28c2277 --- /dev/null +++ b/Client/Gui/style.css @@ -0,0 +1,38 @@ +/** + * @overview Life of German Reallife - Save CSS style.css + * @author Orangebox, hydrant, VegaZ + * @copyright (c) 2008 - 2018 Life of German + */ + +.playerlist { + background-color: rgba(61, 68, 87, 0.50); + position: absolute; + top: 50%; + left: 50%; + margin-right: -50%; + transform: translate(-50%, -50%); + min-width: 60%; + text-align: center; +} + +body { + font-family: "Roboto", sans-serif; + -webkit-font-smoothing: antialiased; + overflow: hidden; +} +td { + align-content: stretch; + padding-left: 10px; + padding-right: 10px; + box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2), 0 0 0 0 rgba(0, 0, 0, 0.24); + border-top: 2px double gray; + border-bottom: 2px double gray; + border-width: 0.5px; + width: auto; +} + +table { + margin: auto; + align-self:center; + width: 100%; +} \ No newline at end of file diff --git a/Client/Player/keys.js b/Client/Player/keys.js index d39d67ff..cc1a69be 100644 --- a/Client/Player/keys.js +++ b/Client/Player/keys.js @@ -15,6 +15,14 @@ mp.keys.bind(0x0D, false, function () { } }); +//I +mp.keys.bind(0x49, false, function () { + if (!chat) { + mp.events.callRemote("keyPress:I"); + mp.events.call("showPlayerlist"); + } +}); + //N mp.keys.bind(0x4E, false, function () { if (!chat) { diff --git a/Client/index.js b/Client/index.js index a494dc53..e32216ec 100644 --- a/Client/index.js +++ b/Client/index.js @@ -5,6 +5,7 @@ */ require('./Gui/infobox.js'); +require('./Gui/playerlist.js'); require('./Login/main.js'); require('./Player/keys.js'); require('./Save/main.js'); diff --git a/Server/Events/Key.cs b/Server/Events/Key.cs index f38999c9..9f150ff8 100644 --- a/Server/Events/Key.cs +++ b/Server/Events/Key.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using GTANetworkAPI; +using reallife_gamemode.Server.Util; /** * @overview Life of German Reallife - Event Key (Key.cs) * @author VegaZ @@ -12,6 +13,23 @@ namespace reallife_gamemode.Server.Events { public class Key : Script { + [RemoteEvent("keyPress:I")] + public void KeyPressI(Client player) + { + List players = NAPI.Pools.GetAllPlayers(); + List ListPlayers = new List(); + + foreach(Client listPlayer in players) + { + var lPlayer = new ListPlayer(); + lPlayer.Id = listPlayer.Handle.Value; + lPlayer.Name = listPlayer.Name; + lPlayer.Ping = listPlayer.Ping; + + ListPlayers.Add(lPlayer); + } + player.TriggerEvent("fetchPlayerList", ListPlayers); + } [RemoteEvent("keyPress:N")] public void KeyPressN(Client player) { diff --git a/Server/Util/ListPlayer.cs b/Server/Util/ListPlayer.cs new file mode 100644 index 00000000..8de40e6c --- /dev/null +++ b/Server/Util/ListPlayer.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; +using GTANetworkAPI; + +/** + * @overview Life of German Reallife - Util ListPlayer ListPlayer.cs + * @author VegaZ + * @copyright (c) 2008 - 2018 Life of German + */ + +namespace reallife_gamemode.Server.Util +{ + public class ListPlayer : Script + { + public int Id; + public string Name; + public int Ping; + } +} From e900499893ba1c7a99823e270a6b5191491a8f56 Mon Sep 17 00:00:00 2001 From: Lennart Kampshoff Date: Wed, 3 Oct 2018 19:14:58 +0200 Subject: [PATCH 3/5] Fixed server -> client transport --- Client/Gui/playerlist.js | 11 +++++------ Server/Events/Key.cs | 3 ++- Server/Util/ListPlayer.cs | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Client/Gui/playerlist.js b/Client/Gui/playerlist.js index e7610890..1c689ddf 100644 --- a/Client/Gui/playerlist.js +++ b/Client/Gui/playerlist.js @@ -15,10 +15,9 @@ mp.events.add("showPlayerlist", () => { } }); -mp.events.add("fetchPlayerList", (players) => { - - for (var player in players) - { - mp.gui.chat.push(player["Id"] + ", " + player["Name"] + ", " + player["Ping"]) - } +mp.events.add("fetchPlayerList", (playersJson) => { + var players = JSON.parse(playersJson); + players.forEach((player) => { + mp.gui.chat.push(player.Id + ", " + player.Name + ", " + player.Ping); + }); }); \ No newline at end of file diff --git a/Server/Events/Key.cs b/Server/Events/Key.cs index 9f150ff8..cbe9e732 100644 --- a/Server/Events/Key.cs +++ b/Server/Events/Key.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using GTANetworkAPI; +using Newtonsoft.Json; using reallife_gamemode.Server.Util; /** * @overview Life of German Reallife - Event Key (Key.cs) @@ -28,7 +29,7 @@ namespace reallife_gamemode.Server.Events ListPlayers.Add(lPlayer); } - player.TriggerEvent("fetchPlayerList", ListPlayers); + player.TriggerEvent("fetchPlayerList", JsonConvert.SerializeObject(ListPlayers)); } [RemoteEvent("keyPress:N")] public void KeyPressN(Client player) diff --git a/Server/Util/ListPlayer.cs b/Server/Util/ListPlayer.cs index 8de40e6c..40ea85c4 100644 --- a/Server/Util/ListPlayer.cs +++ b/Server/Util/ListPlayer.cs @@ -11,10 +11,10 @@ using GTANetworkAPI; namespace reallife_gamemode.Server.Util { - public class ListPlayer : Script + public class ListPlayer { - public int Id; - public string Name; - public int Ping; + public int Id { get; set; } + public string Name { get; set; } + public int Ping { get; set; } } } From 60688d217815570814c1af4249a2839c3efd37a4 Mon Sep 17 00:00:00 2001 From: VegaZ Date: Wed, 3 Oct 2018 20:36:18 +0200 Subject: [PATCH 4/5] Add Tablefill --- Client/Gui/playerlist.html | 17 +++++++++++++---- Client/Gui/playerlist.js | 17 ++++++++++++++--- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Client/Gui/playerlist.html b/Client/Gui/playerlist.html index bb55c176..27f3ec10 100644 --- a/Client/Gui/playerlist.html +++ b/Client/Gui/playerlist.html @@ -8,11 +8,12 @@ - +
+
@@ -21,11 +22,19 @@ - - - +
Ping
+ \ No newline at end of file diff --git a/Client/Gui/playerlist.js b/Client/Gui/playerlist.js index 1c689ddf..21b1e65d 100644 --- a/Client/Gui/playerlist.js +++ b/Client/Gui/playerlist.js @@ -16,8 +16,19 @@ mp.events.add("showPlayerlist", () => { }); mp.events.add("fetchPlayerList", (playersJson) => { - var players = JSON.parse(playersJson); - players.forEach((player) => { + + pList = JSON.parse(playersJson); + + pList.forEach((player) => { mp.gui.chat.push(player.Id + ", " + player.Name + ", " + player.Ping); }); -}); \ No newline at end of file +}); + +//function getTable() { +// var table = ""; +// pList.forEach((player) => { +// var tableRow = "" + player.Id + "" + player.Name + "" + player.Ping + ""; +// table = table + tableRow; +// }) +// return document.write(table); +//} \ No newline at end of file From 8a46eded943e4985037d159d5ba047518c04d55e Mon Sep 17 00:00:00 2001 From: VegaZ Date: Fri, 5 Oct 2018 20:06:30 +0200 Subject: [PATCH 5/5] Rewrite of playerlist (not working) --- Client/Gui/playerlist.js | 1 + Client/Gui/script.js | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 Client/Gui/script.js diff --git a/Client/Gui/playerlist.js b/Client/Gui/playerlist.js index 21b1e65d..bc24759c 100644 --- a/Client/Gui/playerlist.js +++ b/Client/Gui/playerlist.js @@ -24,6 +24,7 @@ mp.events.add("fetchPlayerList", (playersJson) => { }); }); + //function getTable() { // var table = ""; // pList.forEach((player) => { diff --git a/Client/Gui/script.js b/Client/Gui/script.js new file mode 100644 index 00000000..6e54688e --- /dev/null +++ b/Client/Gui/script.js @@ -0,0 +1,8 @@ +$(document).ready(function () { + + mp.trig + + for (var player in pList) { + $("#playerData").append("" + player.Id + "" + player.Name + "" + player.Ping + ""); + } +}); \ No newline at end of file