Fixed server crash when unknown vehicle is spawned, Car gets teleported on /to and /gh

This commit is contained in:
Lennart Kampshoff
2018-10-03 12:50:23 +02:00
parent 5d2e37645c
commit 0bb235fbfd

View File

@@ -38,7 +38,7 @@ namespace reallife_gamemode.Server.Commands
}
[Command("veh", "~m~Benutzung: ~s~/veh [Fahrzeug] (Farbe 1) (Farbe 2)")]
public void CmdAdminVeh(Client player, VehicleHash hash, int color1 = 111, int color2 = 111)
public void CmdAdminVeh(Client player, string hash, int color1 = 111, int color2 = 111)
{
if (!player.GetUser()?.IsAdmin(AdminLevel.ADMIN) ?? true)
{
@@ -52,7 +52,24 @@ namespace reallife_gamemode.Server.Commands
return;
}
Vehicle v = NAPI.Vehicle.CreateVehicle(hash, player.Position, player.Rotation.Z, color1, color2);
hash = hash.ToUpper();
uint.TryParse(hash, out uint vehHash);
if (vehHash == 0)
{
if (Enum.IsDefined(typeof(VehicleHash), hash))
{
vehHash = (uint)Enum.Parse(typeof(VehicleHash), hash);
}
}
if(vehHash == 0)
{
player.SendChatMessage("~r~[FEHLER]~s~ Dieses Fahrzeug existiert nicht.");
return;
}
Vehicle v = NAPI.Vehicle.CreateVehicle(vehHash, player.Position, player.Rotation.Z, color1, color2);
player.SetIntoVehicle(v.Handle, -1);
}
@@ -113,7 +130,8 @@ namespace reallife_gamemode.Server.Commands
return;
}
player.Position = target.Position;
if (player.IsInVehicle && player.VehicleSeat == -1) player.Vehicle.Position = target.Position;
else player.Position = target.Position;
}
[Command("position")]
@@ -125,7 +143,7 @@ namespace reallife_gamemode.Server.Commands
return;
}
player.SendChatMessage("Position: X Y Z: " + player.Position + "");
player.SendChatMessage("Position: X Y Z: " + player.Position);
}
[Command("gotox", "~m~Benutzung: ~s~/gotox [X] [Y] [Z]")]
@@ -157,7 +175,8 @@ namespace reallife_gamemode.Server.Commands
return;
}
target.Position = player.Position;
if (target.IsInVehicle && target.VehicleSeat == -1) target.Vehicle.Position = player.Position;
else target.Position = player.Position;
target.SendChatMessage("Du wurdest von " + player.Name + " teleportiert.");
}