Miese Corona Zeiten push für Lenhardt
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
/**
|
||||
* @overview Life of German Reallife - Player Extension (PlayerExtension.cs)
|
||||
@@ -17,53 +17,53 @@ using System.Linq;
|
||||
namespace ReallifeGamemode.Server.Extensions
|
||||
{
|
||||
public static class PlayerExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// Gibt das User-Objekt eines Player's zurück.
|
||||
/// Gibt nichts zurück, wenn der Player nicht eingeloggt ist
|
||||
/// </summary>
|
||||
/// <param name="client">Der Player, dessen User man bekommen möchte</param>
|
||||
/// <param name="context">Ein eventuell vorhandener Datenbank-Context, falls man Änderungen in der Datenbank vornehmen will</param>
|
||||
/// <returns></returns>
|
||||
public static User GetUser(this Player client, DatabaseContext context = null)
|
||||
{
|
||||
context = context ?? new DatabaseContext();
|
||||
if (!client.IsLoggedIn()) return null;
|
||||
return context
|
||||
.Users
|
||||
.Include(u => u.Faction)
|
||||
.Include(u => u.FactionRank)
|
||||
.Include(u => u.Group)
|
||||
.Include(u => u.House)
|
||||
.Include(u => u.BankAccount)
|
||||
.Where(u => u.Name == client.Name)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public static Character GetCharacter(this User user, DatabaseContext context = null)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
/// <summary>
|
||||
/// Gibt das User-Objekt eines Player's zurück.
|
||||
/// Gibt nichts zurück, wenn der Player nicht eingeloggt ist
|
||||
/// </summary>
|
||||
/// <param name="client">Der Player, dessen User man bekommen möchte</param>
|
||||
/// <param name="context">Ein eventuell vorhandener Datenbank-Context, falls man Änderungen in der Datenbank vornehmen will</param>
|
||||
/// <returns></returns>
|
||||
public static User GetUser(this Player client, DatabaseContext context = null)
|
||||
{
|
||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
||||
context = context ?? new DatabaseContext();
|
||||
if (!client.IsLoggedIn()) return null;
|
||||
return context
|
||||
.Users
|
||||
.Include(u => u.Faction)
|
||||
.Include(u => u.FactionRank)
|
||||
.Include(u => u.Group)
|
||||
.Include(u => u.House)
|
||||
.Include(u => u.BankAccount)
|
||||
.Where(u => u.Name == client.Name)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt zurück, ob ein Player eingeloggt ist
|
||||
/// </summary>
|
||||
/// <param name="player">Der Player, dessen Login-Status man bekommen möchte</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsLoggedIn(this Player player)
|
||||
{
|
||||
return player.HasData("isLoggedIn") ? player.GetData<bool>("isLoggedIn") : false;
|
||||
}
|
||||
public static Character GetCharacter(this User user, DatabaseContext context = null)
|
||||
{
|
||||
if (context == null)
|
||||
{
|
||||
using (context = new DatabaseContext())
|
||||
{
|
||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return context.Characters.FirstOrDefault(u => u.UserId == user.Id);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gibt zurück, ob ein Player eingeloggt ist
|
||||
/// </summary>
|
||||
/// <param name="player">Der Player, dessen Login-Status man bekommen möchte</param>
|
||||
/// <returns></returns>
|
||||
public static bool IsLoggedIn(this Player player)
|
||||
{
|
||||
return player.HasData("isLoggedIn") ? player.GetData<bool>("isLoggedIn") : false;
|
||||
}
|
||||
|
||||
public static bool IsDuty(this Player player)
|
||||
{
|
||||
@@ -81,125 +81,126 @@ namespace ReallifeGamemode.Server.Extensions
|
||||
return newpos;
|
||||
}
|
||||
|
||||
internal static T GetData<T>(this User user, string key, T nullValue)
|
||||
{
|
||||
key += "data_";
|
||||
if (!user.Player.HasData(key)) return nullValue;
|
||||
return JsonConvert.DeserializeObject<T>(user.Player.GetData<dynamic>(key));
|
||||
}
|
||||
|
||||
internal static T GetData<T>(this User user, string key) => user.GetData<T>(key, default);
|
||||
|
||||
internal static void SetData(this User user, string key, object value)
|
||||
{
|
||||
key += "data_";
|
||||
user.Player.SetData(key, JsonConvert.SerializeObject(value));
|
||||
}
|
||||
|
||||
internal static void GiveWanteds(this User user, Player cop, int amount, string reason)
|
||||
{
|
||||
if (user.Wanteds + amount > 50)
|
||||
{
|
||||
ChatService.ErrorMessage(cop, "Die Wanteds dürfen ein Limit von 50 nicht überschreiten");
|
||||
return;
|
||||
}
|
||||
int newWanteds = user.Wanteds + amount;
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User dbUser = dbContext.Users.Where(u => u.Id == user.Id).FirstOrDefault();
|
||||
dbUser.Wanteds = newWanteds;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
user.Player.SetSharedData("blipColor", 64);
|
||||
ChatService.SendMessage(user.Player, "!{#FF614A}Du hast ein Verbrechen begangen: " + reason + "" + (cop != null ? " | Gemeldet von: " + cop.Name + "." : ""));
|
||||
ChatService.SendMessage(user.Player, " !{#FFFF00}Fahnundgslevel:~s~ " + newWanteds);
|
||||
|
||||
foreach (var copPlayer in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
User copUser = copPlayer.GetUser();
|
||||
if (cop != null && (copUser.FactionId == 1 || copUser.FactionId == 3))
|
||||
internal static T GetData<T>(this User user, string key, T nullValue)
|
||||
{
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: Straftat gemeldet von " + cop.Name + " mit Fahndungslevel " + amount + ". Straftäter: " + user.Name + ".");
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: Grund: " + reason + ".");
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: Der Straftäter: " + user.Name + " wird nun mit Fahndungslevel " + newWanteds + " gesucht.");
|
||||
}
|
||||
else if ((copUser.FactionId == 1 || copUser.FactionId == 3) && cop == null)
|
||||
{
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: " + user.Name + " hat eine Straftat begangen. Grund: " + reason + ".");
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: Der Straftäter: " + user.Name + " wird nun mit Fahndungslevel " + newWanteds + " gesucht.");
|
||||
}
|
||||
}
|
||||
}
|
||||
public static FactionRank GetFactionRank(this User user)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
FactionRank toReturn = dbContext.FactionRanks.FirstOrDefault(fR => fR.Id == user.FactionRankId);
|
||||
if (toReturn == null)
|
||||
{
|
||||
toReturn = dbContext.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == user.FactionId);
|
||||
key += "data_";
|
||||
if (!user.Player.HasData(key)) return nullValue;
|
||||
return JsonConvert.DeserializeObject<T>(user.Player.GetData<dynamic>(key));
|
||||
}
|
||||
|
||||
if (toReturn == null)
|
||||
internal static T GetData<T>(this User user, string key) => user.GetData<T>(key, default);
|
||||
|
||||
internal static void SetData(this User user, string key, object value)
|
||||
{
|
||||
toReturn = new FactionRank
|
||||
{
|
||||
RankName = "Rang-Fehler"
|
||||
};
|
||||
key += "data_";
|
||||
user.Player.SetData(key, JsonConvert.SerializeObject(value));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
public static void BanPlayer(this User user, Player admin, string reason, int mins)
|
||||
{
|
||||
using (var banUserContext = new DatabaseContext())
|
||||
{
|
||||
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
Ban banUser;
|
||||
|
||||
if (mins == 0)
|
||||
internal static void GiveWanteds(this User user, Player cop, int amount, string reason)
|
||||
{
|
||||
ChatService.Broadcast("!{#FF4040}[BAN] " + user.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]");
|
||||
banUser = new Ban { UserId = user.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp };
|
||||
if (user.Wanteds + amount > 50)
|
||||
{
|
||||
ChatService.ErrorMessage(cop, "Die Wanteds dürfen ein Limit von 50 nicht überschreiten");
|
||||
return;
|
||||
}
|
||||
int newWanteds = user.Wanteds + amount;
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
User dbUser = dbContext.Users.Where(u => u.Id == user.Id).FirstOrDefault();
|
||||
dbUser.Wanteds = newWanteds;
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
user.Player.SetSharedData("blipColor", 64);
|
||||
ChatService.SendMessage(user.Player, "!{#FF614A}Du hast ein Verbrechen begangen: " + reason + "" + (cop != null ? " | Gemeldet von: " + cop.Name + "." : ""));
|
||||
ChatService.SendMessage(user.Player, " !{#FFFF00}Fahnundgslevel:~s~ " + newWanteds);
|
||||
|
||||
user.Player?.Kick();
|
||||
|
||||
mins--;
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatService.Broadcast("!{#FF4040}[BAN] " + user.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]");
|
||||
banUser = new Ban { UserId = user.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 };
|
||||
user.Player?.Kick();
|
||||
foreach (var copPlayer in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
User copUser = copPlayer.GetUser();
|
||||
if (cop != null && (copUser.FactionId == 1 || copUser.FactionId == 3))
|
||||
{
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: Straftat gemeldet von " + cop.Name + " mit Fahndungslevel " + amount + ". Straftäter: " + user.Name + ".");
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: Grund: " + reason + ".");
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: Der Straftäter: " + user.Name + " wird nun mit Fahndungslevel " + newWanteds + " gesucht.");
|
||||
}
|
||||
else if ((copUser.FactionId == 1 || copUser.FactionId == 3) && cop == null)
|
||||
{
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: " + user.Name + " hat eine Straftat begangen. Grund: " + reason + ".");
|
||||
ChatService.SendMessage(copPlayer, "!{#8181E9}HQ: Der Straftäter: " + user.Name + " wird nun mit Fahndungslevel " + newWanteds + " gesucht.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
banUserContext.Bans.Add(banUser);
|
||||
banUserContext.SaveChanges();
|
||||
public static FactionRank GetFactionRank(this User user)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
FactionRank toReturn = dbContext.FactionRanks.FirstOrDefault(fR => fR.Id == user.FactionRankId);
|
||||
if (toReturn == null)
|
||||
{
|
||||
toReturn = dbContext.FactionRanks.OrderBy(f => f.Order).FirstOrDefault(f => f.FactionId == user.FactionId);
|
||||
}
|
||||
|
||||
var targetUser = banUserContext.Users.Where(u => u.Name == user.Name).FirstOrDefault();
|
||||
targetUser.BanId = banUser.Id;
|
||||
banUserContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
if (toReturn == null)
|
||||
{
|
||||
toReturn = new FactionRank
|
||||
{
|
||||
RankName = "Rang-Fehler"
|
||||
};
|
||||
}
|
||||
|
||||
public static void UnbanPlayer(this User user)
|
||||
{
|
||||
using (var unbanUser = new DatabaseContext())
|
||||
{
|
||||
var targetUser = unbanUser.Users.Where(u => u.Id == user.Id).FirstOrDefault();
|
||||
targetUser.BanId = null;
|
||||
unbanUser.SaveChanges();
|
||||
}
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<UserItem> GetItems(this User user)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.UserItems.Where(u => u.UserId == user.Id).ToList();
|
||||
}
|
||||
public static void BanPlayer(this User user, Player admin, string reason, int mins)
|
||||
{
|
||||
using (var banUserContext = new DatabaseContext())
|
||||
{
|
||||
int unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
|
||||
Ban banUser;
|
||||
|
||||
if (mins == 0)
|
||||
{
|
||||
ChatService.Broadcast("!{#FF4040}[BAN] " + user.Name + " wurde von " + admin.Name + " permanent gebannt. [" + reason + "]");
|
||||
banUser = new Ban { UserId = user.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp };
|
||||
|
||||
user.Player?.Kick();
|
||||
|
||||
mins--;
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatService.Broadcast("!{#FF4040}[BAN] " + user.Name + " wurde von " + admin.Name + " für " + mins + " Minuten gebannt. [" + reason + "]");
|
||||
banUser = new Ban { UserId = user.Id, Reason = reason, BannedBy = admin.Name, Applied = unixTimestamp, UntilDateTime = unixTimestamp + mins * 60 };
|
||||
user.Player?.Kick();
|
||||
}
|
||||
|
||||
banUserContext.Bans.Add(banUser);
|
||||
banUserContext.SaveChanges();
|
||||
|
||||
var targetUser = banUserContext.Users.Where(u => u.Name == user.Name).FirstOrDefault();
|
||||
targetUser.BanId = banUser.Id;
|
||||
banUserContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnbanPlayer(this User user)
|
||||
{
|
||||
using (var unbanUser = new DatabaseContext())
|
||||
{
|
||||
var targetUser = unbanUser.Users.Where(u => u.Id == user.Id).FirstOrDefault();
|
||||
targetUser.BanId = null;
|
||||
unbanUser.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
public static List<UserItem> GetItems(this User user)
|
||||
{
|
||||
using (var dbContext = new DatabaseContext())
|
||||
{
|
||||
return dbContext.UserItems.Where(u => u.UserId == user.Id).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +1,60 @@
|
||||
using ReallifeGamemode.Server.Util;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using ReallifeGamemode.Database;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
using ReallifeGamemode.Server.Types;
|
||||
using static ReallifeGamemode.Server.Types.AdminLevel;
|
||||
|
||||
namespace ReallifeGamemode.Server.Extensions
|
||||
{
|
||||
public static class EnumExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Gibt den richtigen Namen eines Admin Levels zurück
|
||||
/// </summary>
|
||||
/// <param name="level">Das Admin Level, dessen Namen man bekommen möchte.</param>
|
||||
/// <returns></returns>
|
||||
public static string GetName(this AdminLevel level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case MAPPING:
|
||||
return "Mapper";
|
||||
case ENTWICKLUNG:
|
||||
return "Entwickler";
|
||||
case SUPPORTER:
|
||||
return "Supporter";
|
||||
case ADMIN:
|
||||
case ADMIN2:
|
||||
case ADMIN3:
|
||||
return "Admin";
|
||||
case HEADADMIN:
|
||||
return "Headadmin";
|
||||
case PROJEKTLEITUNG:
|
||||
return "Projektleiter";
|
||||
default:
|
||||
return "Spieler";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gibt den richtigen Namen eines Admin Levels zurück
|
||||
/// </summary>
|
||||
/// <param name="level">Das Admin Level, dessen Namen man bekommen möchte.</param>
|
||||
/// <returns></returns>
|
||||
public static string GetName(this AdminLevel level)
|
||||
{
|
||||
switch (level)
|
||||
{
|
||||
case MAPPING:
|
||||
return "Mapper";
|
||||
|
||||
public static string GetName(this GroupRank rank)
|
||||
{
|
||||
switch (rank)
|
||||
{
|
||||
case GroupRank.OWNER:
|
||||
return "Besitzer";
|
||||
case GroupRank.MANAGER:
|
||||
return "Manager";
|
||||
case GroupRank.MEMBER:
|
||||
return "Mitglied";
|
||||
default:
|
||||
return "Keiner";
|
||||
}
|
||||
case ENTWICKLUNG:
|
||||
return "Entwickler";
|
||||
|
||||
case SUPPORTER:
|
||||
return "Supporter";
|
||||
|
||||
case ADMIN:
|
||||
case ADMIN2:
|
||||
case ADMIN3:
|
||||
return "Admin";
|
||||
|
||||
case HEADADMIN:
|
||||
return "Headadmin";
|
||||
|
||||
case PROJEKTLEITUNG:
|
||||
return "Projektleiter";
|
||||
|
||||
default:
|
||||
return "Spieler";
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetName(this GroupRank rank)
|
||||
{
|
||||
switch (rank)
|
||||
{
|
||||
case GroupRank.OWNER:
|
||||
return "Besitzer";
|
||||
|
||||
case GroupRank.MANAGER:
|
||||
return "Manager";
|
||||
|
||||
case GroupRank.MEMBER:
|
||||
return "Mitglied";
|
||||
|
||||
default:
|
||||
return "Keiner";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using System.Linq;
|
||||
|
||||
namespace ReallifeGamemode.Server.Extensions
|
||||
{
|
||||
static class HouseExtensions
|
||||
internal static class HouseExtensions
|
||||
{
|
||||
public static House Refresh(this House house)
|
||||
{
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ReallifeGamemode.Server.Extensions
|
||||
namespace ReallifeGamemode.Server.Extensions
|
||||
{
|
||||
public static class IntegerExtension
|
||||
{
|
||||
public static string ToMoneyString(this int? money)
|
||||
{
|
||||
return ToMoneyString(money ?? 0);
|
||||
public static string ToMoneyString(this int? money)
|
||||
{
|
||||
return ToMoneyString(money ?? 0);
|
||||
}
|
||||
|
||||
public static string ToMoneyString(this int money)
|
||||
{
|
||||
return "$" + string.Format(Main.SERVER_CULTURE, "{0:C0}", money).Replace("€", "").Trim();
|
||||
}
|
||||
}
|
||||
public static string ToMoneyString(this int money)
|
||||
{
|
||||
return "$" + string.Format(Main.SERVER_CULTURE, "{0:C0}", money).Replace("€", "").Trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
using GTANetworkAPI;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
|
||||
namespace ReallifeGamemode.Server.Extensions
|
||||
{
|
||||
static class ListExtensions
|
||||
internal static class ListExtensions
|
||||
{
|
||||
public static bool Contains(this List<Player> list, Player client)
|
||||
{
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GTANetworkAPI;
|
||||
using GTANetworkAPI;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Server.Job;
|
||||
using ReallifeGamemode.Server.Managers;
|
||||
@@ -10,66 +7,66 @@ using ReallifeGamemode.Server.Util;
|
||||
namespace ReallifeGamemode.Server.Extensions
|
||||
{
|
||||
public static class ServerVehicleExtensions
|
||||
{
|
||||
public static JobBase GetJob(this JobVehicle vehicle)
|
||||
{
|
||||
return JobManager.GetJob(vehicle.JobId);
|
||||
public static JobBase GetJob(this JobVehicle vehicle)
|
||||
{
|
||||
return JobManager.GetJob(vehicle.JobId);
|
||||
}
|
||||
|
||||
public static Vehicle GetVehicle(this ServerVehicle veh) => VehicleManager.GetVehicleFromServerVehicle(veh);
|
||||
|
||||
public static Vehicle Spawn(this ServerVehicle veh, Vehicle currentVeh = null)
|
||||
{
|
||||
if (currentVeh != null) VehicleManager.DeleteVehicle(currentVeh);
|
||||
Vector3 position = veh.Position;
|
||||
uint model = (uint)veh.Model;
|
||||
float heading = veh.Heading;
|
||||
int c1 = veh.PrimaryColor;
|
||||
int c2 = veh.SecondaryColor;
|
||||
Vehicle newVeh = NAPI.Vehicle.CreateVehicle(model, position, heading, c1, c2, "", 255, false, false);
|
||||
veh.Livery = veh.Livery;
|
||||
VehicleStreaming.SetEngineState(newVeh, false);
|
||||
VehicleStreaming.SetLockStatus(newVeh, veh.Locked);
|
||||
VehicleManager.AddVehicle(veh, newVeh);
|
||||
newVeh.Rotation = new Vector3(0, 0, heading);
|
||||
|
||||
newVeh.SetSharedData("drivenDistance", veh.DistanceDriven);
|
||||
|
||||
string numberplate = $"{veh.Id}";
|
||||
|
||||
if (veh is FactionVehicle fV)
|
||||
{
|
||||
numberplate = $"F{string.Join(".", fV.GetOwners())} " + numberplate;
|
||||
}
|
||||
|
||||
if (veh is UserVehicle uV)
|
||||
{
|
||||
numberplate = $"U{uV.UserId} " + numberplate;
|
||||
}
|
||||
|
||||
if (veh is ShopVehicle sV)
|
||||
{
|
||||
numberplate = "Shop";
|
||||
VehicleStreaming.SetLockStatus(newVeh, false);
|
||||
TextLabel label = NAPI.TextLabel.CreateTextLabel("SHOPVEHICLE\n" + "~g~" + sV.Price.ToMoneyString(),
|
||||
veh.Position.Add(new Vector3(0, 0, 1.3)), 20.0f, 1f, 1, new Color(255, 255, 255));
|
||||
|
||||
newVeh.SetSharedData("shopVehicleTextLabel", label.Handle.Value);
|
||||
}
|
||||
|
||||
if (veh is GroupVehicle gV)
|
||||
{
|
||||
numberplate = $"G{gV.GroupId} " + numberplate;
|
||||
}
|
||||
|
||||
if (veh is JobVehicle jV)
|
||||
{
|
||||
numberplate = $"J{jV.JobId} " + numberplate;
|
||||
}
|
||||
NAPI.Vehicle.SetVehicleNumberPlate(newVeh, numberplate);
|
||||
veh.NumberPlate = numberplate;
|
||||
|
||||
return newVeh;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vehicle GetVehicle(this ServerVehicle veh) => VehicleManager.GetVehicleFromServerVehicle(veh);
|
||||
|
||||
public static Vehicle Spawn(this ServerVehicle veh, Vehicle currentVeh = null)
|
||||
{
|
||||
if (currentVeh != null) VehicleManager.DeleteVehicle(currentVeh);
|
||||
Vector3 position = veh.Position;
|
||||
uint model = (uint)veh.Model;
|
||||
float heading = veh.Heading;
|
||||
int c1 = veh.PrimaryColor;
|
||||
int c2 = veh.SecondaryColor;
|
||||
Vehicle newVeh = NAPI.Vehicle.CreateVehicle(model, position, heading, c1, c2, "", 255, false, false);
|
||||
veh.Livery = veh.Livery;
|
||||
VehicleStreaming.SetEngineState(newVeh, false);
|
||||
VehicleStreaming.SetLockStatus(newVeh, veh.Locked);
|
||||
VehicleManager.AddVehicle(veh, newVeh);
|
||||
newVeh.Rotation = new Vector3(0, 0, heading);
|
||||
|
||||
newVeh.SetSharedData("drivenDistance", veh.DistanceDriven);
|
||||
|
||||
string numberplate = $"{veh.Id}";
|
||||
|
||||
if (veh is FactionVehicle fV)
|
||||
{
|
||||
numberplate = $"F{string.Join(".", fV.GetOwners())} " + numberplate;
|
||||
}
|
||||
|
||||
if (veh is UserVehicle uV)
|
||||
{
|
||||
numberplate = $"U{uV.UserId} " + numberplate;
|
||||
}
|
||||
|
||||
if (veh is ShopVehicle sV)
|
||||
{
|
||||
numberplate = "Shop";
|
||||
VehicleStreaming.SetLockStatus(newVeh, false);
|
||||
TextLabel label = NAPI.TextLabel.CreateTextLabel("SHOPVEHICLE\n" + "~g~" + sV.Price.ToMoneyString(),
|
||||
veh.Position.Add(new Vector3(0, 0, 1.3)), 20.0f, 1f, 1, new Color(255, 255, 255));
|
||||
|
||||
newVeh.SetSharedData("shopVehicleTextLabel", label.Handle.Value);
|
||||
}
|
||||
|
||||
if (veh is GroupVehicle gV)
|
||||
{
|
||||
numberplate = $"G{gV.GroupId} " + numberplate;
|
||||
}
|
||||
|
||||
if (veh is JobVehicle jV)
|
||||
{
|
||||
numberplate = $"J{jV.JobId} " + numberplate;
|
||||
}
|
||||
NAPI.Vehicle.SetVehicleNumberPlate(newVeh, numberplate);
|
||||
veh.NumberPlate = numberplate;
|
||||
|
||||
return newVeh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
using GTANetworkAPI;
|
||||
using System.Linq;
|
||||
using GTANetworkAPI;
|
||||
using ReallifeGamemode.Database.Entities;
|
||||
using ReallifeGamemode.Database.Models;
|
||||
using ReallifeGamemode.Server.Managers;
|
||||
using System.Linq;
|
||||
|
||||
namespace ReallifeGamemode.Server.Extensions
|
||||
{
|
||||
public static class VehicleExtension
|
||||
{
|
||||
public static ServerVehicle GetServerVehicle(this Vehicle veh, DatabaseContext context = null)
|
||||
{
|
||||
return VehicleManager.GetServerVehicleFromVehicle(veh, context);
|
||||
}
|
||||
public static ServerVehicle GetServerVehicle(this Vehicle veh, DatabaseContext context = null)
|
||||
{
|
||||
return VehicleManager.GetServerVehicleFromVehicle(veh, context);
|
||||
}
|
||||
|
||||
public static Player GetDriver(this Vehicle veh)
|
||||
{
|
||||
return NAPI.Pools.GetAllPlayers().Where(p => p.Vehicle.Handle == veh.Handle && p.VehicleSeat == 0).FirstOrDefault();
|
||||
public static Player GetDriver(this Vehicle veh)
|
||||
{
|
||||
return NAPI.Pools.GetAllPlayers().Where(p => p.Vehicle.Handle == veh.Handle && p.VehicleSeat == 0).FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user