Escape Wanteds done Client Side.

This commit is contained in:
2021-04-27 23:07:44 +02:00
parent b48e76ba45
commit 38a47c32c2
4 changed files with 48 additions and 80 deletions

View File

@@ -1,6 +1,13 @@
export default function playerBlips() { import { afkStatus } from '../Player/antiafk';
import { getWantedCount } from './wanteds';
export default function playerBlips() {
var playerBlipMap: Map<PlayerMp, BlipMp>; var playerBlipMap: Map<PlayerMp, BlipMp>;
var ready = false; var ready = false;
var escapeTimer = null;
const PD_BLIP = 38;
const FIB_BLIP = 63;
setInterval(() => { setInterval(() => {
if (!ready) return; if (!ready) return;
@@ -9,7 +16,7 @@
mp.players.forEachInStreamRange( mp.players.forEachInStreamRange(
(player) => { (player) => {
if (mp.players.local == player) if (mp.players.local == player)
return; return;
if (!playerBlipMap.has(player)) { if (!playerBlipMap.has(player)) {
let pBlip = mp.blips.new(1, player.position, { let pBlip = mp.blips.new(1, player.position, {
@@ -43,8 +50,29 @@
pBlip.setColour(isNaN(color) ? 0 : color); pBlip.setColour(isNaN(color) ? 0 : color);
pBlip.setPosition(player.position.x, player.position.y, player.position.z); pBlip.setPosition(player.position.x, player.position.y, player.position.z);
}
if ((color == PD_BLIP || color == FIB_BLIP || afkStatus)) {
if (escapeTimer) {
mp.events.call("SERVER:SetWantedFlash", false);
clearInterval(escapeTimer);
escapeTimer = null;
}
return;
}
if (!escapeTimer && !afkStatus && getWantedCount() > 0) {
mp.events.call("SERVER:SetWantedFlash", true);
escapeTimer = setInterval(() => {
if (getWantedCount() == 0) {
clearInterval(escapeTimer);
escapeTimer = null;
return;
}
mp.events.callRemote("CLIENT:EscapeWanted");
}, 300000); //120000 -> 2 min , 300000 -> 5min
}
}
}); });
}, 50); }, 50);

View File

@@ -1,13 +1,12 @@
export default function antiAfk(globalData: IGlobalData) { export let afkStatus: boolean = false;
export default function antiAfk(globalData: IGlobalData) {
let lastPosition: Vector3Mp = mp.players.local.position; let lastPosition: Vector3Mp = mp.players.local.position;
let afkCounter: number = 0; let afkCounter: number = 0;
let afkStatus: boolean = false;
setInterval(checkAfkPosition, 1000 * 10); setInterval(checkAfkPosition, 1000 * 10);
function checkAfkPosition() { function checkAfkPosition() {
if (!globalData.LoggedIn) { if (!globalData.LoggedIn) {
return; return;
} }

View File

@@ -62,7 +62,6 @@ namespace ReallifeGamemode.Server.Util
}); });
} }
private static void Timer60000_Elapsed(object sender, ElapsedEventArgs e) private static void Timer60000_Elapsed(object sender, ElapsedEventArgs e)
{ {
NAPI.Task.Run(() => NAPI.Task.Run(() =>
@@ -79,7 +78,6 @@ namespace ReallifeGamemode.Server.Util
{ {
NAPI.Task.Run(() => NAPI.Task.Run(() =>
{ {
WantedEscapeTimer.Timer_Elapsed();
Jail.JailIn_Elapsed(); Jail.JailIn_Elapsed();
Gangwar.Gangwar.Value_TimerElapsed(); Gangwar.Gangwar.Value_TimerElapsed();
}); });

View File

@@ -13,82 +13,25 @@ using ReallifeGamemode.Server.Services;
namespace ReallifeGamemode.Server.Wanted namespace ReallifeGamemode.Server.Wanted
{ {
public class WantedEscapeTimer public class WantedEscapeTimer : Script
{ {
private const int WantedEscapeTime = 300000; [RemoteEvent("CLIENT:EscapeWanted")]
public void WantedEscape(Player player)
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()
{ {
using var dbContext = new DatabaseContext(); 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); ChatService.HQMessage(player.Name + " konnte solange abtauchen, sodass er nicht mehr gesucht wird.");
if (user != null && user.Wanteds > 0) user.SetBlipAndNametagColor();
{
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);
}
}
} }
dbContext.SaveChanges();
} }
} }
} }