generated from K4ryuu/Project_Template
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"runtimeTarget": { | ||
"name": ".NETCoreApp,Version=v7.0", | ||
"signature": "" | ||
}, | ||
"compilationOptions": {}, | ||
"targets": { | ||
".NETCoreApp,Version=v7.0": { | ||
"K4ryuuDamageInfo/1.0.0": { | ||
"dependencies": { | ||
"CounterStrikeSharp.API": "1.0.0.0" | ||
}, | ||
"runtime": { | ||
"K4ryuuDamageInfo.dll": {} | ||
} | ||
}, | ||
"CounterStrikeSharp.API/1.0.0.0": { | ||
"runtime": { | ||
"CounterStrikeSharp.API.dll": { | ||
"assemblyVersion": "1.0.0.0", | ||
"fileVersion": "1.0.0.0" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"libraries": { | ||
"K4ryuuDamageInfo/1.0.0": { | ||
"type": "project", | ||
"serviceable": false, | ||
"sha512": "" | ||
}, | ||
"CounterStrikeSharp.API/1.0.0.0": { | ||
"type": "reference", | ||
"serviceable": false, | ||
"sha512": "" | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
|
||
namespace K4ryuuDamageInfo | ||
{ | ||
public class DamageInfoPlugin : BasePlugin | ||
{ | ||
public override string ModuleName => "Damage Info"; | ||
public override string ModuleVersion => "0.0.1"; | ||
|
||
private Dictionary<CCSPlayerController, DamageData> playerDamageData = new Dictionary<CCSPlayerController, DamageData>(); | ||
|
||
public override void Load(bool hotReload) | ||
{ | ||
RegisterEventHandler<EventPlayerHurt>((@event, info) => | ||
{ | ||
CCSPlayerController attackerController = @event.Attacker; | ||
int targetId = @event.Userid.UserId ?? -1; | ||
|
||
if (attackerController.IsValid && !attackerController.IsBot) | ||
{ | ||
if (!playerDamageData.ContainsKey(attackerController)) | ||
{ | ||
playerDamageData[attackerController] = new DamageData(); | ||
} | ||
|
||
playerDamageData[attackerController].UpdateDamage(attackerController, targetId, @event.DmgHealth, @event.DmgArmor, @event.Hitgroup); | ||
} | ||
|
||
return HookResult.Continue; | ||
}); | ||
} | ||
} | ||
|
||
public class DamageData | ||
{ | ||
private Dictionary<int, DamageInfo> damageInfo = new Dictionary<int, DamageInfo>(); | ||
private Dictionary<int, DateTime> lastUpdateTime = new Dictionary<int, DateTime>(); | ||
|
||
public void UpdateDamage(CCSPlayerController attackerController, int targetId, int damageHP, int damageArmor, int Hitgroup) | ||
{ | ||
if (!damageInfo.ContainsKey(targetId)) | ||
{ | ||
damageInfo[targetId] = new DamageInfo(); | ||
lastUpdateTime[targetId] = DateTime.Now; | ||
} | ||
|
||
ClearOutdatedDamageInfo(targetId); | ||
|
||
damageInfo[targetId].DamageHP += damageHP; | ||
damageInfo[targetId].DamageArmor += damageArmor; | ||
|
||
if (damageHP > 350) | ||
{ | ||
attackerController.PrintToCenter($"Damage Given:\nHP {damageInfo[targetId].DamageHP} | HitGroup: {HitGroupToString(Hitgroup)}"); | ||
} | ||
else | ||
attackerController.PrintToCenter($"Damage Given:\nHP {damageInfo[targetId].DamageHP} | Armor {damageInfo[targetId].DamageArmor} | HitGroup: {HitGroupToString(Hitgroup)}"); | ||
|
||
lastUpdateTime[targetId] = DateTime.Now; | ||
} | ||
|
||
private void ClearOutdatedDamageInfo(int targetId) | ||
{ | ||
if (lastUpdateTime.ContainsKey(targetId)) | ||
{ | ||
TimeSpan elapsed = DateTime.Now - lastUpdateTime[targetId]; | ||
if (elapsed.TotalSeconds > 5) | ||
{ | ||
damageInfo.Remove(targetId); | ||
lastUpdateTime.Remove(targetId); | ||
} | ||
} | ||
} | ||
|
||
public string HitGroupToString(int hitGroup) | ||
{ | ||
switch (hitGroup) | ||
{ | ||
case 0: | ||
return "Body"; | ||
case 1: | ||
return "Head"; | ||
case 2: | ||
return "Chest"; | ||
case 3: | ||
return "Stomach"; | ||
case 4: | ||
return "Left Arm"; | ||
case 5: | ||
return "Right Arm"; | ||
case 6: | ||
return "Left Leg"; | ||
case 7: | ||
return "Right Leg"; | ||
case 10: | ||
return "Gear"; | ||
default: | ||
return "Unknown"; | ||
} | ||
} | ||
} | ||
|
||
public class DamageInfo | ||
{ | ||
public int DamageHP { get; set; } | ||
public int DamageArmor { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="CounterStrikeSharp.API" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.5.002.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "K4ryuuDamageInfo", "K4ryuuDamageInfo.csproj", "{3C041C13-9D82-4182-B13E-C72A23029731}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{3C041C13-9D82-4182-B13E-C72A23029731}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3C041C13-9D82-4182-B13E-C72A23029731}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3C041C13-9D82-4182-B13E-C72A23029731}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3C041C13-9D82-4182-B13E-C72A23029731}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {477EB2E4-F28D-4ABA-A360-C4F8CC1F3594} | ||
EndGlobalSection | ||
EndGlobal |