NullReferenceException Catch
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,8 +86,22 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
|
||||
private void update()
|
||||
{
|
||||
Client[] owners = this.playerInGangwar.Where(c => c.GetUser().Faction.Name == this.Owner ).ToArray();
|
||||
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;
|
||||
@@ -98,10 +112,10 @@ namespace ReallifeGamemode.Server.Gangwar
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user