main
This commit is contained in:
parent
868372e6b7
commit
72e2910a68
40 changed files with 1191 additions and 244 deletions
|
|
@ -1,22 +1,29 @@
|
|||
using System.Drawing;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
using CounterStrikeSharp.API.Modules.Memory;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using static src.jRandomSkills;
|
||||
using System.Collections.Concurrent;
|
||||
using src.utils;
|
||||
using System.Collections.Concurrent;
|
||||
using static src.jRandomSkills;
|
||||
|
||||
namespace src.player.skills
|
||||
{
|
||||
public class C4Camouflage : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.C4Camouflage;
|
||||
private static readonly ConcurrentDictionary<ulong, ConcurrentBag<uint>> invisibleEntities = [];
|
||||
private static readonly ConcurrentDictionary<CCSPlayerController, byte> invisiblePlayers = [];
|
||||
private const string bloodParticle = "particles/blood_impact/blood_impact_high.vpcf";
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
||||
Instance.AddToManifest(bloodParticle);
|
||||
}
|
||||
|
||||
public static void NewRound()
|
||||
{
|
||||
invisiblePlayers.Clear();
|
||||
}
|
||||
|
||||
public static void WeaponPickup(EventItemPickup @event)
|
||||
|
|
@ -30,7 +37,7 @@ namespace src.player.skills
|
|||
|
||||
public static void WeaponEquip(EventItemEquip @event)
|
||||
{
|
||||
var player = @event.Userid;
|
||||
var player = @event.Userid!;
|
||||
var weapon = @event.Item;
|
||||
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
|
|
@ -38,25 +45,16 @@ namespace src.player.skills
|
|||
if (playerInfo?.Skill != skillName) return;
|
||||
|
||||
if (weapon == "c4")
|
||||
{
|
||||
SetPlayerVisibility(player!, false);
|
||||
SetWeaponVisibility(player!, false);
|
||||
}
|
||||
invisiblePlayers.TryAdd(player, 0);
|
||||
else
|
||||
{
|
||||
SetPlayerVisibility(player!, true);
|
||||
SetWeaponVisibility(player!, true);
|
||||
}
|
||||
invisiblePlayers.TryRemove(player, out _);
|
||||
}
|
||||
|
||||
public static void OnTick()
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
if (!player.PawnIsAlive)
|
||||
if (invisibleEntities.ContainsKey(player.SteamID))
|
||||
invisibleEntities.TryRemove(player.SteamID, out _);
|
||||
}
|
||||
invisiblePlayers.TryRemove(player, out _);
|
||||
}
|
||||
|
||||
public static void CheckTransmit([CastFrom(typeof(nint))] CCheckTransmitInfoList infoList)
|
||||
|
|
@ -64,14 +62,22 @@ namespace src.player.skills
|
|||
foreach (var (info, player) in infoList)
|
||||
{
|
||||
if (player == null) continue;
|
||||
foreach ((var playerId, var itemList) in invisibleEntities)
|
||||
if (player.SteamID != playerId)
|
||||
foreach (var entityIndex in itemList)
|
||||
{
|
||||
var entity = Utilities.GetEntityFromIndex<CBaseEntity>((int)entityIndex);
|
||||
if (entity == null || !entity.IsValid) continue;
|
||||
info.TransmitEntities.Remove(entity.Index);
|
||||
}
|
||||
foreach (var _player in invisiblePlayers.Keys)
|
||||
if (player.SteamID != _player.SteamID)
|
||||
{
|
||||
var playerPawn = _player.PlayerPawn.Value;
|
||||
if (playerPawn == null || !playerPawn.IsValid) continue;
|
||||
|
||||
var entity = Utilities.GetEntityFromIndex<CBaseEntity>((int)playerPawn.Index);
|
||||
if (entity == null || !entity.IsValid) continue;
|
||||
info.TransmitEntities.Remove(entity.Index);
|
||||
|
||||
var bombIndex = HideBomb(_player);
|
||||
if (bombIndex == null) continue;
|
||||
var bombEntity = Utilities.GetEntityFromIndex<CBaseEntity>((int)bombIndex);
|
||||
if (bombEntity == null || !bombEntity.IsValid) continue;
|
||||
info.TransmitEntities.Remove(bombEntity.Index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,54 +94,54 @@ namespace src.player.skills
|
|||
var activeWeapon = playerPawn.WeaponServices.ActiveWeapon.Value;
|
||||
if (activeWeapon.DesignerName != "weapon_c4") return;
|
||||
|
||||
SetPlayerVisibility(player, false);
|
||||
SetWeaponVisibility(player, false);
|
||||
invisiblePlayers.TryAdd(player, 0);
|
||||
}
|
||||
|
||||
public static void DisableSkill(CCSPlayerController player)
|
||||
{
|
||||
SetPlayerVisibility(player, true);
|
||||
SetWeaponVisibility(player, true);
|
||||
invisibleEntities.TryRemove(player.SteamID, out _);
|
||||
invisiblePlayers.TryRemove(player, out _);
|
||||
}
|
||||
|
||||
private static void SetPlayerVisibility(CCSPlayerController player, bool enabled)
|
||||
public static void PlayerHurt(EventPlayerHurt @event)
|
||||
{
|
||||
var player = @event.Userid;
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (!invisiblePlayers.ContainsKey(player)) return;
|
||||
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
if (playerPawn != null && playerPawn.IsValid)
|
||||
{
|
||||
var color = Color.FromArgb(enabled ? 255 : 0, 255, 255, 255);
|
||||
playerPawn.Render = color;
|
||||
Utilities.SetStateChanged(playerPawn, "CBaseModelEntity", "m_clrRender");
|
||||
}
|
||||
if (playerPawn == null || !playerPawn.IsValid || playerPawn.AbsOrigin == null) return;
|
||||
|
||||
CParticleSystem particle = Utilities.CreateEntityByName<CParticleSystem>("info_particle_system")!;
|
||||
if (particle == null) return;
|
||||
|
||||
particle.EffectName = bloodParticle;
|
||||
particle.StartActive = true;
|
||||
|
||||
Vector pos = new(playerPawn.AbsOrigin.X, playerPawn.AbsOrigin.Y, playerPawn.AbsOrigin.Z + 50);
|
||||
particle.Teleport(pos);
|
||||
particle.DispatchSpawn();
|
||||
|
||||
particle.AcceptInput("Start");
|
||||
}
|
||||
|
||||
private static void SetWeaponVisibility(CCSPlayerController player, bool visible)
|
||||
private static uint? HideBomb(CCSPlayerController player)
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
var playerPawn = player.PlayerPawn.Value!;
|
||||
if (playerPawn.WeaponServices == null) return;
|
||||
var bombEntities = Utilities.FindAllEntitiesByDesignerName<CC4>("weapon_c4").ToList();
|
||||
if (bombEntities.Count == 0) return null;
|
||||
|
||||
invisibleEntities.TryRemove(player.SteamID, out _);
|
||||
foreach (var weapon in playerPawn.WeaponServices.MyWeapons)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
{
|
||||
if (!visible)
|
||||
{
|
||||
if (invisibleEntities.TryGetValue(player.SteamID, out var items))
|
||||
{
|
||||
if (!items.Contains(weapon.Index))
|
||||
items.Add(weapon.Index);
|
||||
}
|
||||
else
|
||||
invisibleEntities.TryAdd(player.SteamID, [weapon.Index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
var bomb = bombEntities.FirstOrDefault();
|
||||
if (bomb == null) return null;
|
||||
|
||||
if (visible)
|
||||
invisibleEntities.TryRemove(player.SteamID, out _);
|
||||
// if (bomb.OwnerEntity.Index != player.Index) return null;
|
||||
|
||||
bomb.EntitySpottedState.Spotted = false;
|
||||
Utilities.SetStateChanged(bomb, "CCSPlayerPawn", "m_entitySpottedState", Schema.GetSchemaOffset("EntitySpottedState_t", "m_bSpotted"));
|
||||
|
||||
for (int i = 0; i < bomb.EntitySpottedState.SpottedByMask.Length; i++)
|
||||
bomb.EntitySpottedState.SpottedByMask[i] = 0;
|
||||
Utilities.SetStateChanged(bomb, "CCSPlayerPawn", "m_entitySpottedState", Schema.GetSchemaOffset("EntitySpottedState_t", "m_bSpottedByMask"));
|
||||
|
||||
return bomb.Index;
|
||||
}
|
||||
|
||||
public class SkillConfig(Skills skill = skillName, bool active = true, string color = "#00911f", CsTeam onlyTeam = CsTeam.Terrorist, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "") : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue