diff --git a/Client/Gui/deathscreen.js b/Client/Gui/deathscreen.js new file mode 100644 index 00000000..99f30604 --- /dev/null +++ b/Client/Gui/deathscreen.js @@ -0,0 +1,61 @@ +/** + * @overview Life of German Reallife - Gui Infobox infobox.js + * @author VegaZ + * @copyright (c) 2008 - 2018 Life of German + */ + +var playerName; +var playerId; +var playerMoney; + +var isDeath = false; +var deathTime; +var respawnTime; +var deathSeconds; +var fade; + +mp.game.gameplay.setFadeOutAfterDeath(false); + +mp.events.add("startDeathTimer", () => { + if (isDeath === false) { + isDeath = true; + mp.gui.chat.activate(false); + deathDate = new Date(); + respawnTime = Math.floor(deathDate.getTime() / 1000 + 120); + fade = 255 - 120; + } +}); + +mp.events.add("onPlayerRevived", () => { + isDeath = false; + mp.gui.chat.activate(true); + mp.game.gameplay.setFadeOutAfterDeath(false); +}); + +mp.events.add("respawnDeathPlayer", () => { + isDeath = false; + mp.gui.chat.activate(true); + mp.game.gameplay.setFadeOutAfterDeath(false); + mp.events.callRemote('RespawnPlayerAtHospital'); +}); + +mp.events.add("render", () => { + currentDate = new Date(); + + if (isDeath === true) { + deathSeconds = respawnTime - Math.floor(currentDate.getTime() / 1000); + var alpha = fade + (Math.floor((currentDate.getTime() / 1000) - (deathDate.getTime() / 1000))); + if (deathSeconds >= 0) { + mp.game.graphics.drawText("~y~" + deathSeconds, [0.5, 0.5], + { + font: 7, + color: [255, 255, 255, 255], + scale: [0.8, 0.8], + outline: true + }) + mp.game.graphics.drawRect(0.5, 0.5, 1, 1, 0, 0, 0, alpha); + } else { + mp.events.call("respawnDeathPlayer"); + } + } +}); \ No newline at end of file diff --git a/Client/index.js b/Client/index.js index 75951af2..f5dd4598 100644 --- a/Client/index.js +++ b/Client/index.js @@ -8,7 +8,7 @@ require('./Login/main.js'); require('./Save/main.js'); require('./Save/save.js'); - +require('./Gui/deathscreen.js'); require('./Gui/infobox.js'); require('./Gui/playerlist.js'); require('./Login/main.js'); diff --git a/Main.cs b/Main.cs index 54defe8b..f8405200 100644 --- a/Main.cs +++ b/Main.cs @@ -24,6 +24,7 @@ namespace reallife_gamemode NAPI.Server.SetCommandErrorMessage("~r~[FEHLER]~s~ Dieser Command existiert nicht."); NAPI.Server.SetDefaultSpawnLocation(DEFAULT_SPAWN_POSITION, DEFAULT_SPAWN_HEADING); NAPI.Server.SetAutoSpawnOnConnect(false); + NAPI.Server.SetAutoRespawnAfterDeath(false); using (var context = new DatabaseContext()) { diff --git a/Server/Commands/Faction.cs b/Server/Commands/Faction.cs index f1b84674..06d407b8 100644 --- a/Server/Commands/Faction.cs +++ b/Server/Commands/Faction.cs @@ -20,11 +20,13 @@ namespace reallife_gamemode.Server.Commands { class Faction : Script { + #region Chat Commands + [Command("f", "~m~Benutzung: ~s~/f [Nachricht]", GreedyArg = true)] public void CmdFactionF(Client player, string message) { Entities.Faction f = player.GetUser()?.GetFaction(); - if(f == null || f.StateOwned) + if (f == null || f.StateOwned) { ChatService.NotAuthorized(player); return; @@ -59,16 +61,18 @@ namespace reallife_gamemode.Server.Commands } string broadcastMessage = "!{CC3333}** " + player.GetUser().GetFactionRank().RankName + " " + player.Name + ": " + message + ", over **"; - using(var context = new DatabaseContext()) + using (var context = new DatabaseContext()) { ChatService.BroadcastFaction(broadcastMessage, context.Factions.ToList().FindAll(c => c.StateOwned)); } } + #endregion + #region Leader Commands [Command("invite", "~m~Benutzung: ~s~/invite [Name]")] public void CmdFactionInvite(Client player, string name) { - if(player.GetUser()?.FactionId == null || player.GetUser().FactionLeader == false) + if (player.GetUser()?.FactionId == null || player.GetUser().FactionLeader == false) { ChatService.NotAuthorized(player); return; @@ -81,7 +85,7 @@ namespace reallife_gamemode.Server.Commands return; } - if(target.GetUser()?.FactionId != null) + if (target.GetUser()?.FactionId != null) { player.SendChatMessage("~r~[FEHLER]~s~ Dieser Spieler ist schon in einer Fraktion."); return; @@ -121,7 +125,7 @@ namespace reallife_gamemode.Server.Commands using (var dbContext = new DatabaseContext()) { FactionRank fr = dbContext.FactionRanks.FirstOrDefault(r => r.RankName == rank && r.FactionId == player.GetUser(dbContext).FactionId); - if(fr == null) + if (fr == null) { player.SendChatMessage("~r~[FEHLER]~s~ Dieser Rang existiert nicht."); return; @@ -158,13 +162,13 @@ namespace reallife_gamemode.Server.Commands return; } - if(player.Handle == target.Handle) + if (player.Handle == target.Handle) { player.SendChatMessage("~r~[FEHLER]~s~ Du kannst dich nicht selber uninviten."); return; } - if(target.GetUser()?.FactionLeader ?? false) + if (target.GetUser()?.FactionLeader ?? false) { player.SendChatMessage("~r~[FEHLER]~s~ Du kannst keinen Leader uninviten."); return; @@ -183,7 +187,7 @@ namespace reallife_gamemode.Server.Commands } } - [Command("lc", "~m~Benutzung: ~s~/lc [Nachricht]", GreedyArg = true)] + [Command("lc", "~m~Benutzung: ~s~/lc [Nachricht]", GreedyArg = true)] public void CmdFactionLc(Client player, string message) { if (player.GetUser()?.FactionId == null || player.GetUser().FactionLeader == false) @@ -199,5 +203,27 @@ namespace reallife_gamemode.Server.Commands if (p.GetUser()?.FactionLeader ?? false) p.SendChatMessage(broadcastMsg); }); } + #endregion + #region Sanitäter Commands + + [Command("revive", "~m~Benutzung: ~s~/invite")] + public void CmdFactionMedicRevive(Client player) + { + if (player.GetUser()?.FactionId == null || player.GetUser().FactionId != 2) + { + ChatService.NotAuthorized(player); + return; + } + + var nearPlayers = NAPI.Player.GetPlayersInRadiusOfPlayer(2, player); + var deadPlayer = nearPlayers.Where(i => i.GetData("isDead") == true).FirstOrDefault(); + + deadPlayer.TriggerEvent("onPlayerRevived"); + deadPlayer.SendNotification("Du wurdest von ~y~" + player.Name + "~s~ wiederbelebt."); + deadPlayer.SetData("isDead", false); + NAPI.Player.SpawnPlayer(deadPlayer, deadPlayer.Position); + deadPlayer.Health = 50; + } + #endregion } } diff --git a/Server/Entities/User.cs b/Server/Entities/User.cs index 474cdf1a..8628237f 100644 --- a/Server/Entities/User.cs +++ b/Server/Entities/User.cs @@ -36,6 +36,8 @@ namespace reallife_gamemode.Server.Entities public string Email { get; set; } public AdminLevel AdminLevel { get; set; } + public bool Dead { get; set; } + public float PositionX { get; set; } public float PositionY { get; set; } public float PositionZ { get; set; } diff --git a/Server/Events/Connect.cs b/Server/Events/Connect.cs index 53a19793..7a46fc9a 100644 --- a/Server/Events/Connect.cs +++ b/Server/Events/Connect.cs @@ -47,6 +47,21 @@ namespace reallife_gamemode.Server.Events return; } + + using (var loginUser = new DatabaseContext()) + { + var user = loginUser.Users.SingleOrDefault(b => b.Name == player.Name); + if(user.Dead == true) + { + player.TriggerEvent("startDeathTimer"); + player.SetData("isDead", true); + } + else + { + player.SetData("isDead", false); + } + } + player.SetData("isLoggedIn", false); player.Position = new Vector3(-1883.736, -781.4911, -10); player.FreezePosition = true; diff --git a/Server/Events/Death.cs b/Server/Events/Death.cs index 222b93f1..15139c9f 100644 --- a/Server/Events/Death.cs +++ b/Server/Events/Death.cs @@ -22,6 +22,9 @@ namespace reallife_gamemode.Server.Events [ServerEvent(Event.PlayerDeath)] public void OnPlayerDeath(Client player, Client killer, uint reason) { + player.SetData("isDead", true); + player.TriggerEvent("startDeathTimer"); + //TODO: Zum Full Release entfernen NAPI.Chat.SendChatMessageToPlayer(player, "Du bist durch " + killer.Name + " gestorben: " + reason.ToString()); @@ -59,5 +62,12 @@ namespace reallife_gamemode.Server.Events userDeath.SaveChanges(); } } + [RemoteEvent("RespawnPlayerAtHospital")] + public void RespawnPlayerAtHospital(Client player) + { + player.SetData("isDead", false); + player.RemoveAllWeapons(); + NAPI.Player.SpawnPlayer(player, new Vector3(-495.45, -336.33, 34.5)); + } } } diff --git a/Server/Events/Disconnect.cs b/Server/Events/Disconnect.cs index d923476f..1811d970 100644 --- a/Server/Events/Disconnect.cs +++ b/Server/Events/Disconnect.cs @@ -46,6 +46,7 @@ namespace reallife_gamemode.Server.Events user.PositionX = player.Position.X; user.PositionY = player.Position.Y; user.PositionZ = player.Position.Z; + user.Dead = player.GetData("isDead"); saveUser.SaveChanges(); } }