fix fehler bei server close
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using GTANetworkAPI;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Extensions;
|
||||
using System.Linq;
|
||||
@@ -16,31 +17,27 @@ namespace ReallifeGamemode.Server.Events
|
||||
[ServerEvent(Event.ResourceStop)]
|
||||
public void OnResourceStop()
|
||||
{
|
||||
foreach (var player in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
player.GetUser(dbContext).PositionX = player.Position.X;
|
||||
player.GetUser(dbContext).PositionY = player.Position.Y;
|
||||
player.GetUser(dbContext).PositionZ = player.Position.Z;
|
||||
foreach (var player in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
player.TriggerEvent("CLIENT:StopSound");
|
||||
|
||||
User user = player.GetUser(dbContext);
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
user.PositionX = player.Position.X;
|
||||
user.PositionY = player.Position.Y;
|
||||
user.PositionZ = player.Position.Z;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
var users = NAPI.Pools.GetAllPlayers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Player user in users)
|
||||
{
|
||||
user.TriggerEvent("CLIENT:StopSound");
|
||||
using (var saveUsers = new DatabaseContext())
|
||||
{
|
||||
var saveUser = saveUsers.Users.SingleOrDefault(u => u.Name == user.Name);
|
||||
|
||||
saveUser.PositionX = user.Position.X;
|
||||
saveUser.PositionY = user.Position.Y;
|
||||
saveUser.PositionZ = user.Position.Z;
|
||||
saveUsers.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user