NullReferenceException Catch

This commit is contained in:
Lukas Moungos
2019-12-01 16:29:07 +01:00
parent a810a5abf8
commit f67fd6ac63
2 changed files with 32 additions and 17 deletions

View File

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

View File

@@ -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<Client> clientsInGangwar = new List<Client>();
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();
}