Extend death-system

This commit is contained in:
VegaZ
2018-10-22 20:09:14 +02:00
parent 78f4919e12
commit e54337a573
5 changed files with 111 additions and 20 deletions

View File

@@ -7,6 +7,7 @@
var playerName; var playerName;
var playerId; var playerId;
var playerMoney; var playerMoney;
var dutyMedics = 0;
var isDeath = false; var isDeath = false;
var deathTime; var deathTime;
@@ -16,13 +17,19 @@ var fade;
mp.game.gameplay.setFadeOutAfterDeath(false); mp.game.gameplay.setFadeOutAfterDeath(false);
mp.events.add("startDeathTimer", () => { mp.events.add("startDeathTimer", (isAdmin) => {
if (isDeath === false) { if (isDeath === false) {
isDeath = true; isDeath = true;
mp.gui.chat.activate(false); if (isAdmin) {
mp.gui.chat.activate(true);
}
else {
mp.gui.chat.activate(false);
}
deathDate = new Date(); deathDate = new Date();
respawnTime = Math.floor(deathDate.getTime() / 1000 + 120); respawnTime = Math.floor(deathDate.getTime() / 1000 + 120);
fade = 255 - 120; fade = 255 - 120;
mp.game.graphics.requestStreamedTextureDict("Mptattoos", true);
} }
}); });
@@ -39,21 +46,51 @@ mp.events.add("respawnDeathPlayer", () => {
mp.events.callRemote('RespawnPlayerAtHospital'); mp.events.callRemote('RespawnPlayerAtHospital');
}); });
mp.events.add("updateDutyMedics", (count) => {
if (count == true)
{
dutyMedics++;
}
else
{
dutyMedics--;
}
});
mp.events.add("render", () => { mp.events.add("render", () => {
currentDate = new Date(); currentDate = new Date();
if (isDeath === true) { if (isDeath === true) {
var medicString;
if (dutyMedics > 0) {
medicString = "Derzeit sind ~g~" + dutyMedics + " Medics ~s~im Dienst ~c~und versuchen dich wiederzubeleben...";
} else {
medicString = "Derzeit sind ~r~keine Medics ~s~im Dienst."
}
deathSeconds = respawnTime - Math.floor(currentDate.getTime() / 1000); deathSeconds = respawnTime - Math.floor(currentDate.getTime() / 1000);
var alpha = fade + (Math.floor((currentDate.getTime() / 1000) - (deathDate.getTime() / 1000))); var alpha = fade + (Math.floor((currentDate.getTime() / 1000) - (deathDate.getTime() / 1000)));
if (deathSeconds >= 0) { if (deathSeconds >= 0) {
mp.game.graphics.drawText("~y~" + deathSeconds, [0.5, 0.5], mp.game.graphics.drawSprite("Mptattoos", "clearout", 0.625, 0.52, 0.1, 0.1, 0, 255, 255, 255, 236);
mp.game.graphics.drawText("Respawn in: ~y~" + deathSeconds, [0.5, 0.5],
{ {
font: 7, font: 7,
color: [255, 255, 255, 255], color: [255, 255, 255, 255],
scale: [0.8, 0.8], scale: [0.8, 0.8],
outline: true outline: true
}) })
mp.game.graphics.drawText(medicString, [0.5, 0.975],
{
font: 4,
color: [255, 255, 255, 255],
scale: [0.4, 0.4],
outline: true
})
mp.game.graphics.drawRect(0.5, 0.5, 1, 1, 0, 0, 0, alpha); mp.game.graphics.drawRect(0.5, 0.5, 1, 1, 0, 0, 0, alpha);
} else { } else {
mp.events.call("respawnDeathPlayer"); mp.events.call("respawnDeathPlayer");
} }

View File

@@ -206,7 +206,7 @@ namespace reallife_gamemode.Server.Commands
#endregion #endregion
#region Sanitäter Commands #region Sanitäter Commands
[Command("revive", "~m~Benutzung: ~s~/invite")] [Command("revive", "~m~Benutzung: ~s~/revive")]
public void CmdFactionMedicRevive(Client player) public void CmdFactionMedicRevive(Client player)
{ {
if (player.GetUser()?.FactionId == null || player.GetUser().FactionId != 2) if (player.GetUser()?.FactionId == null || player.GetUser().FactionId != 2)
@@ -225,5 +225,32 @@ namespace reallife_gamemode.Server.Commands
deadPlayer.Health = 50; deadPlayer.Health = 50;
} }
#endregion #endregion
#region Global Fraktions Commands
[Command("duty", "~m~Benutzung: ~s~/invite")]
public void CmdFactionDuty(Client player)
{
if (player.GetUser()?.FactionId == null)
{
ChatService.NotAuthorized(player);
return;
}
if(player.GetData("duty") != true)
{
player.SetData("duty", true);
player.SendNotification("Du bist nun ~g~im Dienst.");
if(player.GetUser().FactionId == 2)
{
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", true);
}
}
else
{
player.SetData("duty", false);
player.SendNotification("Du bist nun ~r~außer Dienst.");
NAPI.ClientEvent.TriggerClientEventForAll("updateDutyMedics", false);
}
}
#endregion
} }
} }

View File

@@ -48,20 +48,6 @@ namespace reallife_gamemode.Server.Events
return; 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.SetData("isLoggedIn", false);
player.Position = new Vector3(-1883.736, -781.4911, -10); player.Position = new Vector3(-1883.736, -781.4911, -10);
player.FreezePosition = true; player.FreezePosition = true;

View File

@@ -23,7 +23,27 @@ namespace reallife_gamemode.Server.Events
public void OnPlayerDeath(Client player, Client killer, uint reason) public void OnPlayerDeath(Client player, Client killer, uint reason)
{ {
player.SetData("isDead", true); player.SetData("isDead", true);
player.TriggerEvent("startDeathTimer");
if (player.GetUser().IsAdmin(AdminLevel.ADMIN) == true)
{
player.TriggerEvent("startDeathTimer", true);
}
else
{
player.TriggerEvent("startDeathTimer", false);
}
//var dutyMedics = 0;
//var allPlayers = NAPI.Pools.GetAllPlayers();
//foreach (Client medic in allPlayers)
//{
// if (medic.GetUser()?.FactionId == 2)
// {
// dutyMedics++;
// }
//}
//player.TriggerEvent("medicInfo", dutyMedics);
//TODO: Zum Full Release entfernen //TODO: Zum Full Release entfernen
NAPI.Chat.SendChatMessageToPlayer(player, "Du bist durch " + killer.Name + " gestorben: " + reason.ToString()); NAPI.Chat.SendChatMessageToPlayer(player, "Du bist durch " + killer.Name + " gestorben: " + reason.ToString());
@@ -64,7 +84,7 @@ namespace reallife_gamemode.Server.Events
} }
[RemoteEvent("RespawnPlayerAtHospital")] [RemoteEvent("RespawnPlayerAtHospital")]
public void RespawnPlayerAtHospital(Client player) public void RespawnPlayerAtHospital(Client player)
{ {
player.SetData("isDead", false); player.SetData("isDead", false);
player.RemoveAllWeapons(); player.RemoveAllWeapons();
NAPI.Player.SpawnPlayer(player, new Vector3(-495.45, -336.33, 34.5)); NAPI.Player.SpawnPlayer(player, new Vector3(-495.45, -336.33, 34.5));

View File

@@ -5,6 +5,7 @@ using System.Text;
using GTANetworkAPI; using GTANetworkAPI;
using reallife_gamemode.Model; using reallife_gamemode.Model;
using reallife_gamemode.Server.Entities; using reallife_gamemode.Server.Entities;
using reallife_gamemode.Server.Util;
/** /**
* @overview Life of German Reallife - Event Login (Login.cs) * @overview Life of German Reallife - Event Login (Login.cs)
@@ -46,6 +47,26 @@ namespace reallife_gamemode.Server.Events
player.SetData("isLoggedIn", true); player.SetData("isLoggedIn", true);
player.SetData("spec", true); player.SetData("spec", true);
player.SetData("duty", false);
if (user.Dead == true)
{
if (user.IsAdmin(AdminLevel.ADMIN) == true)
{
player.TriggerEvent("startDeathTimer", true);
}
else
{
player.TriggerEvent("startDeathTimer", false);
}
player.SetData("isDead", true);
}
else
{
player.SetData("isDead", false);
}
var userBankAccount = loginUser.UserBankAccounts.SingleOrDefault(u => u.UserId == user.Id); var userBankAccount = loginUser.UserBankAccounts.SingleOrDefault(u => u.UserId == user.Id);
userBankAccount.Balance = userBankAccount.Balance; userBankAccount.Balance = userBankAccount.Balance;
player.TriggerEvent("draw", player.Name, player.Handle.Value); player.TriggerEvent("draw", player.Name, player.Handle.Value);