Escape Wanteds done Client Side.
This commit is contained in:
@@ -13,82 +13,25 @@ using ReallifeGamemode.Server.Services;
|
||||
|
||||
namespace ReallifeGamemode.Server.Wanted
|
||||
{
|
||||
public class WantedEscapeTimer
|
||||
public class WantedEscapeTimer : Script
|
||||
{
|
||||
private const int WantedEscapeTime = 300000;
|
||||
|
||||
public static Dictionary<int, int> waTimer { get; set; } = new Dictionary<int, int>(); //zeit in ms
|
||||
/*
|
||||
public static void WantedTimer()
|
||||
{
|
||||
//System.Timers.Timer timer = new System.Timers.Timer(2500);
|
||||
//timer.Start();
|
||||
//timer.Elapsed += Timer_Elapsed;
|
||||
}
|
||||
*/
|
||||
|
||||
public static void ResetWantedTimeToElapse(User user)
|
||||
{
|
||||
waTimer[user.Id] = WantedEscapeTime;
|
||||
}
|
||||
|
||||
public static void Timer_Elapsed()
|
||||
[RemoteEvent("CLIENT:EscapeWanted")]
|
||||
public void WantedEscape(Player player)
|
||||
{
|
||||
using var dbContext = new DatabaseContext();
|
||||
foreach (var player in NAPI.Pools.GetAllPlayers())
|
||||
User user = player.GetUser(dbContext);
|
||||
|
||||
if (user.Wanteds <= 0)
|
||||
return;
|
||||
|
||||
player.SendChatMessage("~y~Du hast erfolgreich einen Wanted abgetaucht.");
|
||||
user.Wanteds -= 1;
|
||||
if (user.Wanteds == 0)
|
||||
{
|
||||
User user = player.GetUser(dbContext);
|
||||
if (user != null && user.Wanteds > 0)
|
||||
{
|
||||
if (!waTimer.ContainsKey(user.Id))
|
||||
ResetWantedTimeToElapse(user);
|
||||
|
||||
bool isNearCop = false;
|
||||
foreach (var playerCop in NAPI.Pools.GetAllPlayers())
|
||||
{
|
||||
if (!playerCop.IsLoggedIn()) continue;
|
||||
|
||||
User cop = playerCop.GetUser();
|
||||
if (cop != null && (cop.FactionId == 1 || cop.FactionId == 3))
|
||||
{
|
||||
if (cop.GetData<bool>("duty") && playerCop.Position.DistanceTo2D(player.Position) <= 500)
|
||||
{
|
||||
//Schriftzug 'abgetaucht' zerstören :(
|
||||
isNearCop = true;
|
||||
break;
|
||||
}
|
||||
//Hier abgetaucht schriftzug einfügen :)
|
||||
}
|
||||
}
|
||||
|
||||
if (!waTimer.ContainsKey(user.Id))
|
||||
waTimer[user.Id] = 300000;
|
||||
|
||||
if (waTimer[user.Id] <= 0)
|
||||
{
|
||||
ResetWantedTimeToElapse(user);
|
||||
player.SendChatMessage("~y~Du hast erfolgreich einen Wanted abgetaucht.");
|
||||
user.Wanteds -= 1;
|
||||
if (user.Wanteds == 0)
|
||||
{
|
||||
ChatService.HQMessage(player.Name + " konnte solange abtauchen, sodass er nicht mehr gesucht wird.");
|
||||
user.SetBlipAndNametagColor();
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
waTimer[user.Id] = WantedEscapeTime;
|
||||
}
|
||||
else if (!isNearCop && !player.IsAfk())
|
||||
{
|
||||
player.TriggerEvent("SERVER:SetWantedFlash", true);
|
||||
waTimer[user.Id] -= 2500;
|
||||
}
|
||||
else if (isNearCop)
|
||||
{
|
||||
player.TriggerEvent("SERVER:SetWantedFlash", false);
|
||||
ResetWantedTimeToElapse(user);
|
||||
}
|
||||
}
|
||||
ChatService.HQMessage(player.Name + " konnte solange abtauchen, sodass er nicht mehr gesucht wird.");
|
||||
user.SetBlipAndNametagColor();
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user