diff --git a/ReallifeGamemode.Server/Events/Death.cs b/ReallifeGamemode.Server/Events/Death.cs index faa38807..cc0c9810 100644 --- a/ReallifeGamemode.Server/Events/Death.cs +++ b/ReallifeGamemode.Server/Events/Death.cs @@ -63,7 +63,7 @@ namespace ReallifeGamemode.Server.Events } User user = player.GetUser(); - if(user.JailTime <= 0 && !player.HasData("inGangWar")) + if(user.JailTime <= 0) { //MEDIC AUFTRAG MedicTask reviveTask = new MedicTask() diff --git a/ReallifeGamemode.Server/Gangwar/Turf.cs b/ReallifeGamemode.Server/Gangwar/Turf.cs index 43b8638f..f6c259ae 100644 --- a/ReallifeGamemode.Server/Gangwar/Turf.cs +++ b/ReallifeGamemode.Server/Gangwar/Turf.cs @@ -38,7 +38,7 @@ namespace ReallifeGamemode.Server.Gangwar this.Att_Score = 5; this.Def_Score = 5; this.status = "normal"; - this.playerInside = null; + this.playerInside = new Client[0]; this.timer = null; } @@ -86,22 +86,36 @@ namespace ReallifeGamemode.Server.Gangwar private void update() { - Client[] owners = this.playerInGangwar.Where(c => c.GetUser().Faction.Name == this.Owner ).ToArray(); - Client[] attackers = this.playerInGangwar.Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray(); - /* - if (owners.Length > attackers.Length) - this.Att_Score -= owners.Length - attackers.Length; - if(owners.Length < attackers.Length) - this.Def_Score -= attackers.Length - owners.Length; - */ - foreach (Client gangwarPlayer in this.playerInGangwar) + try + { + Client[] owners = this.playerInGangwar.Where(c => c.GetUser().Faction.Name == this.Owner).ToArray(); + Client[] attackers = this.playerInGangwar.Where(c => c.GetUser().Faction.Name == this.Attacker).ToArray(); + }catch(NullReferenceException ex) + { + int i = 0; + foreach(var c in playerInGangwar) + { + if (!NAPI.Entity.DoesEntityExist(c.Handle)) + { + this.playerInside = this.playerInside.Where(gp => gp != c).ToArray(); + } + i++; + } + } + /* + if (owners.Length > attackers.Length) + this.Att_Score -= owners.Length - attackers.Length; + if(owners.Length < attackers.Length) + this.Def_Score -= attackers.Length - owners.Length; + */ + foreach (Client gangwarPlayer in this.playerInGangwar) { gangwarPlayer.TriggerEvent("CLIENT:ScoreUpdate", JsonConvert.SerializeObject(this.Att_Score), JsonConvert.SerializeObject(this.Def_Score), JsonConvert.SerializeObject(this.TurfID)); } - if(this.Def_Score <= 0) + if (this.Def_Score <= 0) { this.takeOver(this.Attacker); - }else if(this.Att_Score <= 0) + } else if (this.Att_Score <= 0) { this.takeOver(this.Owner); } @@ -190,11 +204,12 @@ namespace ReallifeGamemode.Server.Gangwar using (var context = new DatabaseContext()) { List clientsInGangwar = new List(); - User[] usersInGangwar = context.Users.Where(c => c.Faction.Name == getOwner() || c.Faction.Name == getAttacker()).ToArray(); - foreach(var u in usersInGangwar) + + Client[] usersInGangwar = NAPI.Pools.GetAllPlayers().Where(c => c.GetUser().Faction.Name == getOwner() || c.GetUser().Faction.Name == getAttacker()).ToArray(); + foreach (var u in usersInGangwar) { - u.Client.SetData("inGangWar", getId()); - clientsInGangwar.Add(u.Client); + u.SetData("inGangWar", getId()); + clientsInGangwar.Add(u); } playerInGangwar = clientsInGangwar.ToArray(); }