Merge branch 'feature/deathEvent' into develop

This commit is contained in:
VegaZ
2018-10-21 21:31:51 +02:00
8 changed files with 125 additions and 9 deletions

61
Client/Gui/deathscreen.js Normal file
View File

@@ -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");
}
}
});

View File

@@ -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');

View File

@@ -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())
{

View File

@@ -20,6 +20,8 @@ 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)
{
@@ -64,6 +66,8 @@ namespace reallife_gamemode.Server.Commands
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)
@@ -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
}
}

View File

@@ -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; }

View File

@@ -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;

View File

@@ -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));
}
}
}

View File

@@ -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();
}
}