main
This commit is contained in:
parent
868372e6b7
commit
72e2910a68
40 changed files with 1191 additions and 244 deletions
|
|
@ -1,11 +1,12 @@
|
|||
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 System.Drawing;
|
||||
using static src.jRandomSkills;
|
||||
|
||||
namespace src.player.skills
|
||||
{
|
||||
|
|
@ -13,18 +14,23 @@ namespace src.player.skills
|
|||
{
|
||||
private const Skills skillName = Skills.Ninja;
|
||||
private static readonly ConcurrentDictionary<nint, float> invisibilityChanged = [];
|
||||
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";
|
||||
private static readonly object setLock = new();
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
SkillUtils.RegisterSkill(skillName, SkillsInfo.GetValue<string>(skillName, "color"));
|
||||
Instance.AddToManifest(bloodParticle);
|
||||
}
|
||||
|
||||
public static void NewRound()
|
||||
{
|
||||
lock (setLock)
|
||||
{
|
||||
invisibilityChanged.Clear();
|
||||
invisiblePlayers.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static void WeaponEquip(EventItemEquip @event)
|
||||
|
|
@ -52,14 +58,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,8 +85,7 @@ namespace src.player.skills
|
|||
if (playerInfo?.Skill == skillName)
|
||||
UpdateNinja(player);
|
||||
if (!player.PawnIsAlive)
|
||||
if (invisibleEntities.ContainsKey(player.SteamID))
|
||||
invisibleEntities.TryRemove(player.SteamID, out _);
|
||||
invisiblePlayers.TryRemove(player, out _);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -84,8 +97,7 @@ namespace src.player.skills
|
|||
public static void DisableSkill(CCSPlayerController player)
|
||||
{
|
||||
SetPlayerVisibility(player, 0);
|
||||
SetWeaponVisibility(player, 0);
|
||||
invisibleEntities.TryRemove(player.SteamID, out _);
|
||||
invisiblePlayers.TryRemove(player, out _);
|
||||
}
|
||||
|
||||
private static void UpdateNinja(CCSPlayerController? player)
|
||||
|
|
@ -110,13 +122,19 @@ namespace src.player.skills
|
|||
if (!buttons.HasFlag(PlayerButtons.Moveleft) && !buttons.HasFlag(PlayerButtons.Moveright) && !buttons.HasFlag(PlayerButtons.Forward) && !buttons.HasFlag(PlayerButtons.Back) && flags.HasFlag(PlayerFlags.FL_ONGROUND))
|
||||
percentInvisibility += SkillsInfo.GetValue<float>(skillName, "idlePercentInvisibility");
|
||||
|
||||
SetWeaponVisibility(player, percentInvisibility);
|
||||
if (invisibilityChanged.TryGetValue(player.Handle, out float oldInvisibility))
|
||||
if (percentInvisibility == oldInvisibility)
|
||||
return;
|
||||
|
||||
invisibilityChanged.TryAdd(player.Handle, percentInvisibility);
|
||||
SetPlayerVisibility(player, percentInvisibility);
|
||||
|
||||
if (percentInvisibility > .9)
|
||||
invisiblePlayers.TryAdd(player, 0);
|
||||
else
|
||||
{
|
||||
SetPlayerVisibility(player, percentInvisibility);
|
||||
invisiblePlayers.TryRemove(player, out _);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetPlayerVisibility(CCSPlayerController player, float percentInvisibility)
|
||||
|
|
@ -130,30 +148,46 @@ namespace src.player.skills
|
|||
}
|
||||
}
|
||||
|
||||
private static void SetWeaponVisibility(CCSPlayerController player, float percentInvisibility)
|
||||
public static void PlayerHurt(EventPlayerHurt @event)
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) return;
|
||||
var playerPawn = player.PlayerPawn.Value!;
|
||||
if (playerPawn.WeaponServices == null) return;
|
||||
var player = @event.Userid;
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (!invisiblePlayers.ContainsKey(player)) return;
|
||||
|
||||
var color = Color.FromArgb(Math.Max(255 - (int)(255 * percentInvisibility * 2), 0), 255, 255, 255);
|
||||
var playerPawn = player.PlayerPawn.Value;
|
||||
if (playerPawn == null || !playerPawn.IsValid || playerPawn.AbsOrigin == null) return;
|
||||
|
||||
invisibleEntities.TryRemove(player.SteamID, out _);
|
||||
if (color.A != 0) return;
|
||||
CParticleSystem particle = Utilities.CreateEntityByName<CParticleSystem>("info_particle_system")!;
|
||||
if (particle == null) return;
|
||||
|
||||
foreach (var weapon in playerPawn.WeaponServices.MyWeapons)
|
||||
{
|
||||
if (weapon != null && weapon.IsValid && weapon.Value != null && weapon.Value.IsValid)
|
||||
{
|
||||
if (invisibleEntities.TryGetValue(player.SteamID, out var items))
|
||||
{
|
||||
if (!items.Contains(weapon.Index))
|
||||
items.Add(weapon.Index);
|
||||
}
|
||||
else
|
||||
invisibleEntities.TryAdd(player.SteamID, [weapon.Index]);
|
||||
}
|
||||
}
|
||||
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 uint? HideBomb(CCSPlayerController player)
|
||||
{
|
||||
var bombEntities = Utilities.FindAllEntitiesByDesignerName<CC4>("weapon_c4").ToList();
|
||||
if (bombEntities.Count == 0) return null;
|
||||
|
||||
var bomb = bombEntities.FirstOrDefault();
|
||||
if (bomb == null) return null;
|
||||
|
||||
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 = "#dedede", CsTeam onlyTeam = CsTeam.None, bool disableOnFreezeTime = false, bool needsTeammates = false, string requiredPermission = "", float idlePercentInvisibility = .3f, float duckPercentInvisibility = .3f, float knifePercentInvisibility = .3f) : SkillsInfo.DefaultSkillInfo(skill, active, color, onlyTeam, disableOnFreezeTime, needsTeammates, requiredPermission)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue