v1.1.0
This commit is contained in:
parent
6b8988ade4
commit
26cb787b57
125 changed files with 9157 additions and 1940 deletions
106
jRandomSkills - SRC Files/src/player/skills/ExplosiveShot.cs
Normal file
106
jRandomSkills - SRC Files/src/player/skills/ExplosiveShot.cs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Modules.Memory;
|
||||
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||
using CounterStrikeSharp.API.Modules.Utils;
|
||||
using jRandomSkills.src.player;
|
||||
using jRandomSkills.src.utils;
|
||||
using static jRandomSkills.jRandomSkills;
|
||||
|
||||
namespace jRandomSkills
|
||||
{
|
||||
public class ExplosiveShot : ISkill
|
||||
{
|
||||
private const Skills skillName = Skills.ExplosiveShot;
|
||||
private static float damage = Config.GetValue<float>(skillName, "damage");
|
||||
private static float damageRadius = Config.GetValue<float>(skillName, "damageRadius");
|
||||
|
||||
public static void LoadSkill()
|
||||
{
|
||||
SkillUtils.RegisterSkill(skillName, Config.GetValue<string>(skillName, "color"), false);
|
||||
|
||||
Instance.RegisterEventHandler<EventRoundFreezeEnd>((@event, info) =>
|
||||
{
|
||||
Instance.AddTimer(0.1f, () =>
|
||||
{
|
||||
foreach (var player in Utilities.GetPlayers())
|
||||
{
|
||||
if (!Instance.IsPlayerValid(player)) continue;
|
||||
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
if (playerInfo?.Skill != skillName) continue;
|
||||
EnableSkill(player);
|
||||
}
|
||||
});
|
||||
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
VirtualFunctions.CBaseEntity_TakeDamageOldFunc.Hook(OnTakeDamage, HookMode.Pre);
|
||||
}
|
||||
|
||||
public static void EnableSkill(CCSPlayerController player)
|
||||
{
|
||||
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == player.SteamID);
|
||||
float newChance = (float)Instance.Random.NextDouble() * (Config.GetValue<float>(skillName, "ChanceTo") - Config.GetValue<float>(skillName, "ChanceFrom")) + Config.GetValue<float>(skillName, "ChanceFrom");
|
||||
playerInfo.SkillChance = newChance;
|
||||
newChance = (float)Math.Round(newChance, 2) * 100;
|
||||
newChance = (float)Math.Round(newChance);
|
||||
SkillUtils.PrintToChat(player, $"{ChatColors.DarkRed}{Localization.GetTranslation("explosiveshot")}{ChatColors.Lime}: " + Localization.GetTranslation("explosiveshot_desc2", newChance), false);
|
||||
}
|
||||
|
||||
private static void SpawnExplosion(Vector vector)
|
||||
{
|
||||
var heProjectile = Utilities.CreateEntityByName<CHEGrenadeProjectile>("hegrenade_projectile");
|
||||
if (heProjectile == null || !heProjectile.IsValid) return;
|
||||
|
||||
Vector pos = vector;
|
||||
heProjectile.TicksAtZeroVelocity = 100;
|
||||
heProjectile.TeamNum = (byte)CsTeam.None;
|
||||
heProjectile.Damage = damage;
|
||||
heProjectile.DmgRadius = damageRadius;
|
||||
heProjectile.Teleport(pos, null, new Vector(0, 0, -10));
|
||||
heProjectile.DispatchSpawn();
|
||||
heProjectile.AcceptInput("InitializeSpawnFromWorld", null, null, "");
|
||||
heProjectile.DetonateTime = 0;
|
||||
}
|
||||
|
||||
private static HookResult OnTakeDamage(DynamicHook h)
|
||||
{
|
||||
CEntityInstance param = h.GetParam<CEntityInstance>(0);
|
||||
CTakeDamageInfo param2 = h.GetParam<CTakeDamageInfo>(1);
|
||||
|
||||
if (param == null || param.Entity == null || param2 == null || param2.Attacker == null || param2.Attacker.Value == null)
|
||||
return HookResult.Continue;
|
||||
|
||||
CCSPlayerPawn attackerPawn = new CCSPlayerPawn(param2.Attacker.Value.Handle);
|
||||
if (attackerPawn.DesignerName != "player")
|
||||
return HookResult.Continue;
|
||||
|
||||
if (attackerPawn == null || attackerPawn.Controller?.Value == null)
|
||||
return HookResult.Continue;
|
||||
|
||||
CCSPlayerController attacker = attackerPawn.Controller.Value.As<CCSPlayerController>();
|
||||
var playerInfo = Instance.skillPlayer.FirstOrDefault(p => p.SteamID == attacker.SteamID);
|
||||
if (playerInfo == null || playerInfo.Skill != skillName) return HookResult.Continue;
|
||||
|
||||
if (Instance.Random.NextDouble() <= playerInfo.SkillChance)
|
||||
SpawnExplosion(param2.DamagePosition);
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
public class SkillConfig : Config.DefaultSkillInfo
|
||||
{
|
||||
public float Damage { get; set; }
|
||||
public float DamageRadius { get; set; }
|
||||
public float ChanceFrom { get; set; }
|
||||
public float ChanceTo { get; set; }
|
||||
public SkillConfig(Skills skill = skillName, bool active = true, string color = "#9c0000", CsTeam onlyTeam = CsTeam.None, bool needsTeammates = false, float damage = 10f, float damageRadius = 190f, float chanceFrom = .15f, float chanceTo = .3f) : base(skill, active, color, onlyTeam, needsTeammates)
|
||||
{
|
||||
Damage = damage;
|
||||
DamageRadius = damageRadius;
|
||||
ChanceFrom = chanceFrom;
|
||||
ChanceTo = chanceTo;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue