From f6872c0cbcd001718c8ec76be5311242f29a15ea Mon Sep 17 00:00:00 2001 From: kookroach Date: Wed, 7 Apr 2021 22:20:38 +0200 Subject: [PATCH 01/10] open #16 --- ReallifeGamemode.Client/util/animationSync.ts | 11 ++++++----- ReallifeGamemode.Server/Util/AnimationSync.cs | 3 --- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/ReallifeGamemode.Client/util/animationSync.ts b/ReallifeGamemode.Client/util/animationSync.ts index 22b39721..169a070b 100644 --- a/ReallifeGamemode.Client/util/animationSync.ts +++ b/ReallifeGamemode.Client/util/animationSync.ts @@ -106,16 +106,17 @@ export default function animationSync() { loadAnimDict(animDict, function () { mp.players.exists(entity) && 0 !== entity.handle && entity.taskPlayAnim(animDict, animName, 1, 0, duration, parseInt(flag), 0, !1, !1, !1) }); - if (!endless) { - animationBreakTimer = setInterval(() => breakAnimation(name), 120000); - } if (mp.players.local == entity) { + if (!endless) { + animationBreakTimer = setInterval(() => breakAnimation(name), 120000); + } + if (!loop) { let a = setInterval(function () { - mp.events.callRemote("CLIENT:ClearAnimationData", true); - clearInterval(a); + mp.game.wait(500); + mp.events.callRemote("CLIENT:ClearAnimationData", true); }, duration); } } diff --git a/ReallifeGamemode.Server/Util/AnimationSync.cs b/ReallifeGamemode.Server/Util/AnimationSync.cs index 6d10d672..827c83aa 100644 --- a/ReallifeGamemode.Server/Util/AnimationSync.cs +++ b/ReallifeGamemode.Server/Util/AnimationSync.cs @@ -64,8 +64,6 @@ namespace ReallifeGamemode.Server.Util /// Name of requested animation public static bool HasAnimation(this Player player, dynamic animationName) { - string data = player.GetData("Animation"); - bool x = player.GetData("Animation") == animationName; return player.HasData("Animation") && (player.GetData("Animation") == animationName); } @@ -74,7 +72,6 @@ namespace ReallifeGamemode.Server.Util if (!player.HasData("Animation")) return; - player.ClearAttachments(); player.ResetData("Animation"); player.ResetSharedData("AnimationData"); } From a63185768c9e1e141563df78d366f08b4bc6f919 Mon Sep 17 00:00:00 2001 From: kookroach Date: Wed, 7 Apr 2021 22:29:47 +0200 Subject: [PATCH 02/10] Fix #16 --- ReallifeGamemode.Server/Util/AnimationSync.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ReallifeGamemode.Server/Util/AnimationSync.cs b/ReallifeGamemode.Server/Util/AnimationSync.cs index 827c83aa..274871b9 100644 --- a/ReallifeGamemode.Server/Util/AnimationSync.cs +++ b/ReallifeGamemode.Server/Util/AnimationSync.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using GTANetworkAPI; using Newtonsoft.Json; +using ReallifeGamemode.Server.Managers; namespace ReallifeGamemode.Server.Util { @@ -95,7 +96,14 @@ namespace ReallifeGamemode.Server.Util { player.ClearAnimation(); if (checkTransition) + { AnimPairTransition(player); + } + else + { + player.ClearAttachments(); + PositionManager.cuffPoints.Remove(player); + } } [ServerEvent(Event.PlayerWeaponSwitch)] From a070f7b74af3c429f4464d3ddd2007792339e4e0 Mon Sep 17 00:00:00 2001 From: Fabian Wessels Date: Wed, 7 Apr 2021 22:30:15 +0200 Subject: [PATCH 03/10] =?UTF-8?q?wichtige=20infos=20zugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReallifeGamemode.Server/Events/Key.cs | 2 +- ReallifeGamemode.Server/Events/Register.cs | 2 +- ReallifeGamemode.Server/Managers/InteractionManager.cs | 2 +- ReallifeGamemode.Server/Managers/InventoryManager.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ReallifeGamemode.Server/Events/Key.cs b/ReallifeGamemode.Server/Events/Key.cs index 8cba9c05..134f7a62 100644 --- a/ReallifeGamemode.Server/Events/Key.cs +++ b/ReallifeGamemode.Server/Events/Key.cs @@ -21,7 +21,7 @@ using ReallifeGamemode.Server.WeaponDeal; /** * @overview Life of German Reallife - Event Key (Key.cs) -* @author VegaZ +* @author VegaZ, balbo * @copyright (c) 2008 - 2018 Life of German */ diff --git a/ReallifeGamemode.Server/Events/Register.cs b/ReallifeGamemode.Server/Events/Register.cs index 28ecacc0..b7640f91 100644 --- a/ReallifeGamemode.Server/Events/Register.cs +++ b/ReallifeGamemode.Server/Events/Register.cs @@ -6,7 +6,7 @@ using ReallifeGamemode.Database.Models; /** * @overview Life of German Reallife - Event Register (Register.cs) -* @author VegaZ +* @author VegaZ, balbo * @copyright (c) 2008 - 2018 Life of German */ diff --git a/ReallifeGamemode.Server/Managers/InteractionManager.cs b/ReallifeGamemode.Server/Managers/InteractionManager.cs index b6542171..b1c04dfc 100644 --- a/ReallifeGamemode.Server/Managers/InteractionManager.cs +++ b/ReallifeGamemode.Server/Managers/InteractionManager.cs @@ -19,7 +19,7 @@ using ReallifeGamemode.Server.Factions.Medic; /** * @overview Life of German Reallife - Managers Interaction (InteractionManager.cs) -* @author VegaZ +* @author VegaZ, balbo * @copyright (c) 2008 - 2018 Life of German */ diff --git a/ReallifeGamemode.Server/Managers/InventoryManager.cs b/ReallifeGamemode.Server/Managers/InventoryManager.cs index c8a88470..36525511 100644 --- a/ReallifeGamemode.Server/Managers/InventoryManager.cs +++ b/ReallifeGamemode.Server/Managers/InventoryManager.cs @@ -18,7 +18,7 @@ using ReallifeGamemode.Server.Types; /** * @overview Life of German Reallife - Managers InventoryManager (InventoryManager.cs) -* @author hydrant, VegaZ +* @author hydrant, VegaZ, balbo * @copyright (c) 2008 - 2018 Life of German */ From 56ab0734ee71fb7d9b56e278caa0e0adf9b6a89f Mon Sep 17 00:00:00 2001 From: kookroach Date: Wed, 7 Apr 2021 22:42:57 +0200 Subject: [PATCH 04/10] fix postitioning of cuffs and delete cuffpoits on death --- .../util/attachmentMngr.ts | 2 +- ReallifeGamemode.Server/Events/Death.cs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ReallifeGamemode.Client/util/attachmentMngr.ts b/ReallifeGamemode.Client/util/attachmentMngr.ts index a19df0ba..bb62ee5d 100644 --- a/ReallifeGamemode.Client/util/attachmentMngr.ts +++ b/ReallifeGamemode.Client/util/attachmentMngr.ts @@ -8,7 +8,7 @@ export default function attachmentManager(game: IGame) { attachmentMngr.register("weapondeal", "ex_prop_crate_ammo_bc", "chassis_dummy", new mp.Vector3(0.08, -0.9, -0.2), new mp.Vector3(0, 0, 0)); attachmentMngr.register("weapondeal1", "ex_office_swag_guns02", "chassis_dummy", new mp.Vector3(0, 0.8, 0), new mp.Vector3(0, 0, 0)); attachmentMngr.register("weapondeal2", "w_sg_pumpshotgun", "chassis_dummy", new mp.Vector3(0.4, 1.6, 0.62), new mp.Vector3(90, 0, 180)); - attachmentMngr.register("handcuffs", "p_cs_cuffs_02_s", 28422, new mp.Vector3(0, 0, 0), new mp.Vector3(0, 90, 0)); + attachmentMngr.register("handcuffs", "p_cs_cuffs_02_s", 28422, new mp.Vector3(-0.05, 0, 0), new mp.Vector3(90, 90, 0)); }); const attachmentMngr = diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs index b4edee69..fe1db994 100644 --- a/ReallifeGamemode.Server/Events/Death.cs +++ b/ReallifeGamemode.Server/Events/Death.cs @@ -25,27 +25,29 @@ namespace ReallifeGamemode.Server.Events public class Death : Script { [ServerEvent(Event.PlayerDeath)] - public void OnPlayerDeath(Player player, Player killer, uint reason ) + public void OnPlayerDeath(Player player, Player killer, uint reason) { if (!player.IsLoggedIn()) { player.Kick(); return; } - + + PositionManager.cuffPoints.Remove(player); + player.SetData("isDead", true); - using (var userDeath = new DatabaseContext()) - { + { User userisdead = player.GetUser(userDeath); userisdead.Dead = true; - userDeath.SaveChanges(); - } + userDeath.SaveChanges(); + } //TODO: Zum Full Release entfernen - if (player.HasData("togdeath")) { - ChatService.SendMessage(player, "Du bist durch " + (killer?.Name ?? "Niemanden") + " gestorben: " + reason.ToString()); + if (player.HasData("togdeath")) + { + ChatService.SendMessage(player, "Du bist durch " + (killer?.Name ?? "Niemanden") + " gestorben: " + reason.ToString()); } int? killerId; float killerPosX; @@ -108,8 +110,6 @@ namespace ReallifeGamemode.Server.Events Medic.delHealTask(player); ChatService.BroadcastFaction("~y~[MEDIC] ~w~" + player.Name + " ist soeben verstorben.", new List() { 2 }); } - - if (player.GetUser().IsAdmin(AdminLevel.ADMIN) == true) { From 3f2cdbeea86c92e0721c01cf59d22afeee2adbbd Mon Sep 17 00:00:00 2001 From: hydrant Date: Wed, 7 Apr 2021 23:32:52 +0200 Subject: [PATCH 05/10] maybe fix knast --- ReallifeGamemode.Server/Events/Death.cs | 73 ++++----- ReallifeGamemode.Server/Events/Login.cs | 3 +- ReallifeGamemode.Server/Events/Register.cs | 1 + .../Extensions/ClientExtension.cs | 76 +++++++-- ReallifeGamemode.Server/Finance/Economy.cs | 2 +- ReallifeGamemode.Server/Wanted/Jail.cs | 148 +++++------------- .../Wanted/WantedEscapeTimer.cs | 29 +--- 7 files changed, 148 insertions(+), 184 deletions(-) diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs index fe1db994..8cd14748 100644 --- a/ReallifeGamemode.Server/Events/Death.cs +++ b/ReallifeGamemode.Server/Events/Death.cs @@ -33,17 +33,12 @@ namespace ReallifeGamemode.Server.Events return; } + using var dbContext = new DatabaseContext(); + + User user = player.GetUser(dbContext); + PositionManager.cuffPoints.Remove(player); - player.SetData("isDead", true); - - using (var userDeath = new DatabaseContext()) - { - User userisdead = player.GetUser(userDeath); - userisdead.Dead = true; - userDeath.SaveChanges(); - } - //TODO: Zum Full Release entfernen if (player.HasData("togdeath")) { @@ -88,10 +83,25 @@ namespace ReallifeGamemode.Server.Events } } - User user = player.GetUser(); + bool copNearby = NAPI.Pools.GetAllPlayers().Any(u => u.IsDuty() && u.IsAlive() && u.Position.DistanceToSquared(player.Position) <= 200 * 200); + + if (copNearby) + { + user.SetJailTime(true); + Jail.Check_PutBehindBars(user); + ChatService.HQMessage(user.Name + " wurde ins Gefängnis eingeliefert."); + } + else + { + ChatService.HQMessage(user.Name + " wurde soeben ins Krankenhaus eingeliefert."); + } if (user.JailTime <= 0) { + player.SetData("isDead", true); + + user.Dead = true; + if (!player.HasData("reviveSperre")) { //MEDIC AUFTRAG @@ -123,32 +133,28 @@ namespace ReallifeGamemode.Server.Events //TODO PICTURE NOTIFICATION + SOUND für Medics player.ClearAttachments(); - - using (var userDeath = new DatabaseContext()) + List fItem = dbContext.UserItems.Where(u => u.UserId == user.Id).ToList(); + foreach (var item in fItem) { - List fItem = userDeath.UserItems.Where(u => u.UserId == user.Id).ToList(); - foreach (var item in fItem) + IItem iItem = InventoryManager.GetItemById(item.ItemId); + if (iItem is IWeaponDealItem obj) { - IItem iItem = InventoryManager.GetItemById(item.ItemId); - if (iItem is IWeaponDealItem obj) - { - int amount = item.Amount; + int amount = item.Amount; - Vector3 dropPosition = PlayerExtension.GetPositionFromPlayer(player, 0.6f, 0); - //new Vector3(player.Position.X, player.Position.Y, player.Position.Z - 0.8f); - Random r = new Random(); - GTANetworkAPI.Object grndObject; - Vector3 textPos = dropPosition; + Vector3 dropPosition = PlayerExtension.GetPositionFromPlayer(player, 0.6f, 0); + //new Vector3(player.Position.X, player.Position.Y, player.Position.Z - 0.8f); + Random r = new Random(); + GTANetworkAPI.Object grndObject; + Vector3 textPos = dropPosition; - dropPosition.Z -= 1.05f; - grndObject = NAPI.Object.CreateObject(3666746839, dropPosition, new Vector3(0, 0, r.Next(0, 360)), 255, 0); + dropPosition.Z -= 1.05f; + grndObject = NAPI.Object.CreateObject(3666746839, dropPosition, new Vector3(0, 0, r.Next(0, 360)), 255, 0); - GroundItem grndItem = new GroundItem { ItemId = iItem.Id, Amount = amount, Position = dropPosition }; - TextLabel grndTxtLbl = NAPI.TextLabel.CreateTextLabel(iItem.Name + " ~s~(~y~" + amount + "~s~)", textPos, 5, 0.5f, 4, new Color(255, 255, 255), false, 0); - GroundItem.AddGroundItem(grndItem, grndObject, grndTxtLbl); + GroundItem grndItem = new GroundItem { ItemId = iItem.Id, Amount = amount, Position = dropPosition }; + TextLabel grndTxtLbl = NAPI.TextLabel.CreateTextLabel(iItem.Name + " ~s~(~y~" + amount + "~s~)", textPos, 5, 0.5f, 4, new Color(255, 255, 255), false, 0); + GroundItem.AddGroundItem(grndItem, grndObject, grndTxtLbl); - userDeath.Remove(item); - } + dbContext.Remove(item); } var dead = new Database.Entities.Logs.Death @@ -165,8 +171,8 @@ namespace ReallifeGamemode.Server.Events VictimHeading = player.Heading, CauseOfDeath = reason.ToString() }; - userDeath.DeathLogs.Add(dead); - userDeath.SaveChanges(); + dbContext.DeathLogs.Add(dead); + dbContext.SaveChanges(); } } Job.JobBase job = Managers.JobManager.GetJob(player.GetUser().JobId ?? -1); @@ -219,9 +225,6 @@ namespace ReallifeGamemode.Server.Events //ChatService.SendMessage(player, "Debug10"); } } - - //JailTime.cs - Jail.Check_PutBehindBars(player); } [RemoteEvent("RespawnPlayerAtHospital")] diff --git a/ReallifeGamemode.Server/Events/Login.cs b/ReallifeGamemode.Server/Events/Login.cs index ccdd6628..1da5ec9f 100644 --- a/ReallifeGamemode.Server/Events/Login.cs +++ b/ReallifeGamemode.Server/Events/Login.cs @@ -54,6 +54,7 @@ namespace ReallifeGamemode.Server.Events } else { + player.SetData("dbId", user.Id); player.Name = username; player.TriggerEvent("SERVER:Login_Success"); player.TriggerEvent("CLIENT:StopSound"); @@ -122,7 +123,7 @@ namespace ReallifeGamemode.Server.Events } else { - Jail.Check_PutBehindBars(player); + Jail.Check_PutBehindBars(user); } } diff --git a/ReallifeGamemode.Server/Events/Register.cs b/ReallifeGamemode.Server/Events/Register.cs index b7640f91..8536642b 100644 --- a/ReallifeGamemode.Server/Events/Register.cs +++ b/ReallifeGamemode.Server/Events/Register.cs @@ -51,6 +51,7 @@ namespace ReallifeGamemode.Server.Events dbContext.Users.Add(user); dbContext.SaveChanges(); + player.SetData("dbId", user.Id); player.TriggerEvent("SERVER:Login_Success"); player.TriggerEvent("CLIENT:StopSound"); player.SetData("isLoggedIn", true); diff --git a/ReallifeGamemode.Server/Extensions/ClientExtension.cs b/ReallifeGamemode.Server/Extensions/ClientExtension.cs index 42305180..a1d4d914 100644 --- a/ReallifeGamemode.Server/Extensions/ClientExtension.cs +++ b/ReallifeGamemode.Server/Extensions/ClientExtension.cs @@ -59,6 +59,34 @@ namespace ReallifeGamemode.Server.Extensions } } + public static void SetJailTime(this User user, bool killed) + { + if (user == null) + { + return; + } + + int time = 26 * user.Wanteds; + if (killed) + { + time *= 2; + } + + user.Wanteds = 0; + user.JailTime = time; + } + + public static void AnnouncePlayerJailedIn(this User user) + { + if (user == null) + { + return; + } + string message = user.Name + " wurde ins Gefängnis geliefert"; + + ChatService.HQMessage(message); + } + /// /// Gibt zurück, ob ein Player eingeloggt ist /// @@ -76,8 +104,35 @@ namespace ReallifeGamemode.Server.Extensions public static bool IsDuty(this Player player) { - var user = player.GetUser(); - return user.GetData("duty", false); + return player.GetServerData("duty", false); + } + + public static bool IsAlive(this Player player) + { + return !player.HasData("isDead") || (bool)player.GetData("isDead") == false; + } + + public static T GetServerData(this Player player, string key, T defaultValue = default) + { + if (player == null) + { + return default; + } + + key += "data_"; + if (!player.HasData(key)) return defaultValue; + return JsonConvert.DeserializeObject(player.GetData(key)); + } + + public static void SetServerData(this Player player, string key, object value) + { + if (player == null) + { + return; + } + + key += "data_"; + player.SetData(key, JsonConvert.SerializeObject(value)); } public static bool IsAdminDuty(this Player player) @@ -98,27 +153,14 @@ namespace ReallifeGamemode.Server.Extensions internal static T GetData(this User user, string key, T nullValue) { - if (user == null) - { - return default; - } - - key += "data_"; - if (!user.Player.HasData(key)) return nullValue; - return JsonConvert.DeserializeObject(user.Player.GetData(key)); + return user.Player.GetServerData(key, nullValue); } internal static T GetData(this User user, string key) => user.GetData(key, default); internal static void SetData(this User user, string key, object value) { - if (user == null) - { - return; - } - - key += "data_"; - user.Player.SetData(key, JsonConvert.SerializeObject(value)); + user.Player.SetServerData(key, value); } internal static void GiveWanteds(this User user, Player cop, int amount, string reason) diff --git a/ReallifeGamemode.Server/Finance/Economy.cs b/ReallifeGamemode.Server/Finance/Economy.cs index 4c551892..1ff424a2 100644 --- a/ReallifeGamemode.Server/Finance/Economy.cs +++ b/ReallifeGamemode.Server/Finance/Economy.cs @@ -171,7 +171,7 @@ namespace ReallifeGamemode.Server.Finance if (putInJail != 0 && minusJail) { - Jail.Check_PutBehindBars(client, false); + Jail.Check_PutBehindBars(u); } } diff --git a/ReallifeGamemode.Server/Wanted/Jail.cs b/ReallifeGamemode.Server/Wanted/Jail.cs index c9cfe660..12d21685 100644 --- a/ReallifeGamemode.Server/Wanted/Jail.cs +++ b/ReallifeGamemode.Server/Wanted/Jail.cs @@ -10,6 +10,7 @@ using ReallifeGamemode.Server.Services; using ReallifeGamemode.Services; using System.Diagnostics; using Newtonsoft.Json; +using ReallifeGamemode.Server.Managers; namespace ReallifeGamemode.Server.Wanted { @@ -18,105 +19,37 @@ namespace ReallifeGamemode.Server.Wanted private static Dictionary Jailtime { get; set; } = new Dictionary(); //time in seconds - public static void Check_PutBehindBars(Player client, bool announceHq = true) + public static void Check_PutBehindBars(User user) { - User user = client.GetUser(); + Player player = user.Player; + PositionManager.cuffPoints.Remove(player); if (user.JailTime > 0) { - client.RemoveAllWeapons(); - client.Health = 100; - client.Armor = 0; + player.RemoveAllWeapons(); + player.Health = 100; + player.Armor = 0; Random rnd = new Random(); int rndInt = rnd.Next(1, 3); if (rndInt == 1) - NAPI.Player.SpawnPlayer(client, new Vector3(458.9842, -997.2126, 24.91485)); //send client to jail + NAPI.Player.SpawnPlayer(player, new Vector3(458.9842, -997.2126, 24.91485)); //send client to jail if (rndInt == 2) - NAPI.Player.SpawnPlayer(client, new Vector3(459.696, -994.3766, 24.91486)); //send client to jail + NAPI.Player.SpawnPlayer(player, new Vector3(459.696, -994.3766, 24.91486)); //send client to jail if (rndInt == 3) - NAPI.Player.SpawnPlayer(client, new Vector3(458.3372, -1001.258, 24.91485)); //send client to jail + NAPI.Player.SpawnPlayer(player, new Vector3(458.3372, -1001.258, 24.91485)); //send client to jail Jailtime[user.Id] = user.JailTime; // 54 sec for each wanted star -> in total 45min for 50 Wanteds - int timeMinutes = 0; + int timeMinutes; - if (((int)(user.JailTime / 60)) <= 1 && user.JailTime != 0) + if ((user.JailTime / 60) <= 1 && user.JailTime != 0) { timeMinutes = 1; } else { - timeMinutes = (int)(user.JailTime / 60); + timeMinutes = (user.JailTime / 60); } - client.TriggerEvent("jailTime", timeMinutes); + player.TriggerEvent("jailTime", timeMinutes); return; } - if (user.Wanteds <= 0) - return; - using (var dbContext = new DatabaseContext()) - { - foreach (var copPlayer in NAPI.Pools.GetAllPlayers()) - { - if (!copPlayer.IsLoggedIn()) continue; - User cop = copPlayer.GetUser(); - if (cop?.FactionId == 1 || cop?.FactionId == 3) - { - int jailTime = user.Wanteds * 54; - if (cop.GetData("duty") && copPlayer.Position.DistanceTo2D(client.Position) <= 200 && (!copPlayer.HasData("isDead") || copPlayer.GetData("isDead") != true)) - { - if (!client.HasData("isDead") || client.GetData("isDead") == false) - { - jailTime /= 2; - } - - User clientUser = client.GetUser(dbContext); - - clientUser.JailTime = jailTime; - Jailtime[user.Id] = jailTime; // 54 sec for each wanted star -> in total 45min for 50 Wanteds - - clientUser.Wanteds = 0; - client.SetData("isDead", false); - client.RemoveAllWeapons(); - client.SetSharedData("blipColor", 0); - Random rnd = new Random(); - int rndInt = rnd.Next(1, 3); - if (rndInt == 1) - NAPI.Player.SpawnPlayer(client, new Vector3(458.9842, -997.2126, 24.91485)); //send client to jail - if (rndInt == 2) - NAPI.Player.SpawnPlayer(client, new Vector3(459.696, -994.3766, 24.91486)); //send client to jail - if (rndInt == 3) - NAPI.Player.SpawnPlayer(client, new Vector3(458.3372, -1001.258, 24.91485)); //send client to jail - - client.TriggerEvent("onPlayerRevived"); - MedicTask task = Medic.ReviveTasks.FirstOrDefault(t => t.Victim == client.Name); - Medic.RemoveTaskFromList(task); - client.Health = 100; - - int timeMinutes = 0; - - if (((int)(Jailtime[user.Id] / 60)) <= 1 && Jailtime[user.Id] != 0) - { - timeMinutes = 1; - } - else - { - timeMinutes = (int)(Jailtime[user.Id] / 60); - } - - client.TriggerEvent("jailTime", JsonConvert.SerializeObject(timeMinutes)); - - clientUser.SetBlipAndNametagColor(); - - if (announceHq) - { - ChatService.BroadcastFaction("!{#8181E9}HQ: " + user.Name + " wurde ins Gefängnis geliefert.", new List() { 1, 3 }); - } - } - else if (user.Wanteds > 0 && user.JailTime <= 0) - { - ChatService.BroadcastFaction("!{#8181E9}HQ: Der Verdächtigte " + user.Name + " wurde soeben ins Krankenhaus eingeliefert.", new System.Collections.Generic.List() { 1, 3 }); - } - } - } - dbContext.SaveChanges(); - } } /* @@ -136,23 +69,28 @@ namespace ReallifeGamemode.Server.Wanted public static void JailIn_Elapsed() { + using var dbContext = new DatabaseContext(); foreach (var player in NAPI.Pools.GetAllPlayers()) { - User user = player.GetUser(); - if (user != null && !Jailtime.ContainsKey(user.Id)) + if (player.Position.DistanceTo(new Vector3(458.9842, -997.2126, 24.91485)) > 7) { - foreach (var copPlayer in NAPI.Pools.GetAllPlayers()) + continue; + } + + User user = player.GetUser(); + + if (user != null && user.Wanteds > 0 && !Jailtime.ContainsKey(user.Id)) + { + foreach (var copPlayer in NAPI.Pools.GetAllPlayers().Where(u => u.IsLoggedIn() && u.IsDuty()) { - if (!copPlayer.IsLoggedIn()) return; - User cop = copPlayer.GetUser(); - if (cop.GetData("duty") && copPlayer.Position.DistanceTo2D(player.Position) <= 500 && (!copPlayer.HasData("isDead") || copPlayer.GetData("isDead") != true)) + if (!copPlayer.HasData("isDead") || copPlayer.GetData("isDead") != true) { - if (player.Position.DistanceTo2D(new Vector3(458.9842, -997.2126, 24.91485)) <= 7) + if (player.Position.DistanceTo(copPlayer.Position) < 5) { - if (player.Position.DistanceTo2D(copPlayer.Position) < 5) - { - Check_PutBehindBars(player); - } + user.SetJailTime(false); + user.AnnouncePlayerJailedIn(); + dbContext.SaveChanges(); + Check_PutBehindBars(user); } } } @@ -183,9 +121,10 @@ namespace ReallifeGamemode.Server.Wanted public static void JailOut_Elapsed() { + using var dbContext = new DatabaseContext(); foreach (var player in NAPI.Pools.GetAllPlayers()) { - User user = player.GetUser(); + User user = player.GetUser(dbContext); if (user != null && Jailtime.ContainsKey(user.Id)) { if (user.JailTime <= 0) @@ -197,11 +136,7 @@ namespace ReallifeGamemode.Server.Wanted } if (user.JailTime > 0) { - using (var dbContext = new DatabaseContext()) - { - player.GetUser(dbContext).JailTime -= 60; - dbContext.SaveChanges(); - } + user.JailTime -= 60; int timeMinutes = 0; @@ -219,15 +154,16 @@ namespace ReallifeGamemode.Server.Wanted } } } + dbContext.SaveChanges(); } - + [RemoteEvent("setPrisonerFree")] public void Release_Jail(Player cop, string client) { Player player = PlayerService.GetPlayerByNameOrId(client); if (player == null) return; - + User user = player.GetUser(); if (Jailtime.ContainsKey(user.Id)) { @@ -248,15 +184,15 @@ namespace ReallifeGamemode.Server.Wanted public static void Release_Jail_Admin(Player admin, Player target) { - User user = target.GetUser(); + using var dbContext = new DatabaseContext(); + User user = target.GetUser(dbContext); if (Jailtime.ContainsKey(user.Id)) { Jailtime.Remove(user.Id); - using (var dbContext = new DatabaseContext()) - { - target.GetUser(dbContext).JailTime = 0; - dbContext.SaveChanges(); - } + + user.JailTime = 0; + dbContext.SaveChanges(); + target.Health = 100; target.Position = new Vector3(427.879, -984.65, 30.71); diff --git a/ReallifeGamemode.Server/Wanted/WantedEscapeTimer.cs b/ReallifeGamemode.Server/Wanted/WantedEscapeTimer.cs index 5fc94dee..a9640a8b 100644 --- a/ReallifeGamemode.Server/Wanted/WantedEscapeTimer.cs +++ b/ReallifeGamemode.Server/Wanted/WantedEscapeTimer.cs @@ -35,9 +35,10 @@ namespace ReallifeGamemode.Server.Wanted public static void Timer_Elapsed() { + using var dbContext = new DatabaseContext(); foreach (var player in NAPI.Pools.GetAllPlayers()) { - User user = player.GetUser(); + User user = player.GetUser(dbContext); if (user != null && user.Wanteds > 0) { if (!waTimer.ContainsKey(user.Id)) @@ -68,30 +69,10 @@ namespace ReallifeGamemode.Server.Wanted { ResetWantedTimeToElapse(player); player.SendChatMessage("~y~Du hast erfolgtreich einen Wanted abgetaucht."); - using (var dbContext = new DatabaseContext()) + user.Wanteds -= 1; + if (user.Wanteds == 0) { - player.GetUser(dbContext).Wanteds -= 1; - if (player.GetUser(dbContext).Wanteds == 0) - { - switch (player.GetUser(dbContext).FactionId) - { - case null: - player.SetSharedData("blipColor", 0); - break; - - case 8: - player.SetSharedData("blipColor", 83); - break; - - case 7: - player.SetSharedData("blipColor", 52); - break; - - case 4: - player.SetSharedData("blipColor", 5); - break; - } - } + user.SetBlipAndNametagColor(); dbContext.SaveChanges(); } } From 0722816765bdbab5f2df0255b2b1ef3336599c48 Mon Sep 17 00:00:00 2001 From: hydrant Date: Wed, 7 Apr 2021 23:42:02 +0200 Subject: [PATCH 06/10] fix hq --- ReallifeGamemode.Server/Extensions/ClientExtension.cs | 2 +- ReallifeGamemode.Server/Wanted/Jail.cs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ReallifeGamemode.Server/Extensions/ClientExtension.cs b/ReallifeGamemode.Server/Extensions/ClientExtension.cs index a1d4d914..e20a998e 100644 --- a/ReallifeGamemode.Server/Extensions/ClientExtension.cs +++ b/ReallifeGamemode.Server/Extensions/ClientExtension.cs @@ -109,7 +109,7 @@ namespace ReallifeGamemode.Server.Extensions public static bool IsAlive(this Player player) { - return !player.HasData("isDead") || (bool)player.GetData("isDead") == false; + return !player.HasData("isDead") || player.GetData("isDead") == false; } public static T GetServerData(this Player player, string key, T defaultValue = default) diff --git a/ReallifeGamemode.Server/Wanted/Jail.cs b/ReallifeGamemode.Server/Wanted/Jail.cs index 12d21685..4a92c263 100644 --- a/ReallifeGamemode.Server/Wanted/Jail.cs +++ b/ReallifeGamemode.Server/Wanted/Jail.cs @@ -81,9 +81,10 @@ namespace ReallifeGamemode.Server.Wanted if (user != null && user.Wanteds > 0 && !Jailtime.ContainsKey(user.Id)) { - foreach (var copPlayer in NAPI.Pools.GetAllPlayers().Where(u => u.IsLoggedIn() && u.IsDuty()) + foreach (var copPlayer in NAPI.Pools.GetAllPlayers().Where(u => u.IsLoggedIn() && u.IsDuty() && u.IsAlive())) { - if (!copPlayer.HasData("isDead") || copPlayer.GetData("isDead") != true) + User copUser = copPlayer.GetUser(dbContext); + if (copUser.FactionId == 1 || copUser.FactionId == 3) { if (player.Position.DistanceTo(copPlayer.Position) < 5) { @@ -91,6 +92,7 @@ namespace ReallifeGamemode.Server.Wanted user.AnnouncePlayerJailedIn(); dbContext.SaveChanges(); Check_PutBehindBars(user); + break; } } } From b3475efbe8379e45b42db930db878a4783bdfc7b Mon Sep 17 00:00:00 2001 From: hydrant Date: Wed, 7 Apr 2021 23:50:56 +0200 Subject: [PATCH 07/10] fix jailtime --- ReallifeGamemode.Server/Wanted/Jail.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ReallifeGamemode.Server/Wanted/Jail.cs b/ReallifeGamemode.Server/Wanted/Jail.cs index 4a92c263..fe51b4b1 100644 --- a/ReallifeGamemode.Server/Wanted/Jail.cs +++ b/ReallifeGamemode.Server/Wanted/Jail.cs @@ -45,10 +45,9 @@ namespace ReallifeGamemode.Server.Wanted } else { - timeMinutes = (user.JailTime / 60); + timeMinutes = user.JailTime / 60; } player.TriggerEvent("jailTime", timeMinutes); - return; } } @@ -77,7 +76,7 @@ namespace ReallifeGamemode.Server.Wanted continue; } - User user = player.GetUser(); + User user = player.GetUser(dbContext); if (user != null && user.Wanteds > 0 && !Jailtime.ContainsKey(user.Id)) { From e3cc8cf191f230d183ffae799130579b815649d9 Mon Sep 17 00:00:00 2001 From: hydrant Date: Thu, 8 Apr 2021 00:00:54 +0200 Subject: [PATCH 08/10] fix death dbchanges --- ReallifeGamemode.Server/Events/Death.cs | 39 ++++++++++++------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs index 8cd14748..fcbe84e5 100644 --- a/ReallifeGamemode.Server/Events/Death.cs +++ b/ReallifeGamemode.Server/Events/Death.cs @@ -58,28 +58,27 @@ namespace ReallifeGamemode.Server.Events killerPosZ = -1; killerHeading = -1; } - else + else if (killer.IsLoggedIn()) { - var killerUser = killer.GetUser(); - if (killerUser == null) + var killerUser = killer.GetUser(dbContext); + if (killerUser != null) { - return; - } - killerId = killerUser.Id; - killerPosX = killer.Position.X; - killerPosY = killer.Position.Y; - killerPosZ = killer.Position.Z; - killerHeading = killer.Heading; - if (player.HasData("inGangWar") && killer.HasData("inGangWar")) - { - Gangwar.Gangwar.GangwarKill(killer, player); - } + killerId = killerUser.Id; + killerPosX = killer.Position.X; + killerPosY = killer.Position.Y; + killerPosZ = killer.Position.Z; + killerHeading = killer.Heading; + if (player.HasData("inGangWar") && killer.HasData("inGangWar")) + { + Gangwar.Gangwar.GangwarKill(killer, player); + } - if (player != killer) - { - Autowanted.Check_AutoWanted(killer, player); - string message = "~y~[HINWEIS]: " + killer.Name + " hat " + player.Name + " getötet (" + Managers.WeaponManager.GetCauseOfDeathByHash(reason) + ")"; - ChatService.BroadcastAdmin(message, AdminLevel.ADMIN); + if (player != killer) + { + Autowanted.Check_AutoWanted(killer, player); + string message = "~y~[HINWEIS]: " + killer.Name + " hat " + player.Name + " getötet (" + Managers.WeaponManager.GetCauseOfDeathByHash(reason) + ")"; + ChatService.BroadcastAdmin(message, AdminLevel.ADMIN); + } } } @@ -172,7 +171,6 @@ namespace ReallifeGamemode.Server.Events CauseOfDeath = reason.ToString() }; dbContext.DeathLogs.Add(dead); - dbContext.SaveChanges(); } } Job.JobBase job = Managers.JobManager.GetJob(player.GetUser().JobId ?? -1); @@ -225,6 +223,7 @@ namespace ReallifeGamemode.Server.Events //ChatService.SendMessage(player, "Debug10"); } } + dbContext.SaveChanges(); } [RemoteEvent("RespawnPlayerAtHospital")] From 85ab6c09c22266cc0bb4e803958e2b72a53f0521 Mon Sep 17 00:00:00 2001 From: hydrant Date: Thu, 8 Apr 2021 00:03:05 +0200 Subject: [PATCH 09/10] fix death --- ReallifeGamemode.Server/Events/Death.cs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs index fcbe84e5..f6f0e0c6 100644 --- a/ReallifeGamemode.Server/Events/Death.cs +++ b/ReallifeGamemode.Server/Events/Death.cs @@ -44,21 +44,13 @@ namespace ReallifeGamemode.Server.Events { ChatService.SendMessage(player, "Du bist durch " + (killer?.Name ?? "Niemanden") + " gestorben: " + reason.ToString()); } - int? killerId; - float killerPosX; - float killerPosY; - float killerPosZ; - float killerHeading; + int? killerId = null; + float killerPosX = -1; + float killerPosY = -1; + float killerPosZ = -1; + float killerHeading = -1; - if (killer == null || killer.IsNull) - { - killerId = null; - killerPosX = -1; - killerPosY = -1; - killerPosZ = -1; - killerHeading = -1; - } - else if (killer.IsLoggedIn()) + if (killer.IsLoggedIn()) { var killerUser = killer.GetUser(dbContext); if (killerUser != null) From a34e478b3a8a484164cc7440078c99bd566ee376 Mon Sep 17 00:00:00 2001 From: hydrant Date: Thu, 8 Apr 2021 00:07:10 +0200 Subject: [PATCH 10/10] blip nametag farbe --- ReallifeGamemode.Server/Wanted/Jail.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ReallifeGamemode.Server/Wanted/Jail.cs b/ReallifeGamemode.Server/Wanted/Jail.cs index fe51b4b1..d8273fed 100644 --- a/ReallifeGamemode.Server/Wanted/Jail.cs +++ b/ReallifeGamemode.Server/Wanted/Jail.cs @@ -21,6 +21,7 @@ namespace ReallifeGamemode.Server.Wanted public static void Check_PutBehindBars(User user) { + user.SetBlipAndNametagColor(); Player player = user.Player; PositionManager.cuffPoints.Remove(player); if (user.JailTime > 0) @@ -88,6 +89,7 @@ namespace ReallifeGamemode.Server.Wanted if (player.Position.DistanceTo(copPlayer.Position) < 5) { user.SetJailTime(false); + user.SetBlipAndNametagColor(); user.AnnouncePlayerJailedIn(); dbContext.SaveChanges(); Check_PutBehindBars(user);