Hey,
ich habe eine autoSave Funktion eingebaut, die Spieler werden gespeichert beim Vehicle Safe wird mir gesagt, dass ich eine Connection Open und Valid sein soll
SaveFunktion
Code
Task.Run(() =>
{
while (true)
{
Task.Delay(1000 * 60 * 1).Wait();
Task first_while = Task.Run(() =>
{
NAPI.World.SetTime(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
foreach (Player c in NAPI.Pools.GetAllPlayers())
{
IPlayer iplayer = c.GetData<IPlayer>("PlayerData");
iplayer.Save();
Vehicle.SaveAll();
}
});
first_while.Wait();
}
});
Alles anzeigen
Vehicle.SaveAll
Code
public static void SavePos(Vehicle v)
{
MySqlConnection conn = new MySqlConnection(Settings.Server_Settings.GetConnectionString());
conn.Open();
if (v.HasData("id"))
{
int vId = v.GetData<int>("id");
if (vId != -1)
{
if (v.GetData<DateTime>("lastUsed") > lastSave)
{
MySqlCommand cmd = new MySqlCommand("UPDATE vehicles SET " +
"p_x = @p_x, p_y = @p_y, p_z = @p_z, r = @r, " +
"engine = @engine, locked = @locked, hp = @hp, km=@km, fuel=@fuel, last_used = @last_used " +
"WHERE id = @id");
cmd.Parameters.AddWithValue("@p_x", v.Position.X);
cmd.Parameters.AddWithValue("@p_y", v.Position.Y);
cmd.Parameters.AddWithValue("@p_z", v.Position.Z);
cmd.Parameters.AddWithValue("@r", v.Rotation.Z);
cmd.Parameters.AddWithValue("@engine", v.GetData<bool>("engine"));
cmd.Parameters.AddWithValue("@locked", v.Locked);
cmd.Parameters.AddWithValue("@hp", v.GetData<float>("hp"));
cmd.Parameters.AddWithValue("@km", v.GetData<float>("km"));
cmd.Parameters.AddWithValue("@fuel", v.GetData<float>("fuel"));
cmd.Parameters.AddWithValue("@last_used", v.GetData<DateTime>("lastUsed"));
cmd.Parameters.AddWithValue("@id", vId);
cmd.ExecuteNonQuery();
NAPI.Util.ConsoleOutput("Fahrzeug[" + vId + "] gespeichert.");
}
}
}
conn.Close();
}
Alles anzeigen
Vielleicht kann mir einer von euch ja helfen
Lösung für das Problem
Code: Old
MySqlCommand cmd = new MySqlCommand("UPDATE vehicles SET " +
"p_x = @p_x, p_y = @p_y, p_z = @p_z, r = @r, " +
"engine = @engine, locked = @locked, hp = @hp, km=@km, fuel=@fuel, last_used = @last_used " +
"WHERE id = @id");
Zu:
Code
MySqlCommand cmd = new MySqlCommand("UPDATE vehicles SET " +
"p_x = @p_x, p_y = @p_y, p_z = @p_z, r = @r, " +
"engine = @engine, locked = @locked, hp = @hp, km=@km, fuel=@fuel, last_used = @last_used " +
"WHERE id = @id", conn);
Fehlerbehoben, close.