-
Notifications
You must be signed in to change notification settings - Fork 11
/
damage_types.lua
38 lines (30 loc) · 916 Bytes
/
damage_types.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- from incredible-gmod.ru with <3
-- https://github.com/Be1zebub/Small-GLua-Things/blob/master/damage_types.lua
local DamageName = {}
for key, val in pairs(_G) do
if isstring(key) and key:StartWith("DMG_") then
DamageName[val] = key:sub(5):lower():gsub("^%l", string.upper)
end
end
local CTakeDamageInfo = FindMetaTable("CTakeDamageInfo")
function CTakeDamageInfo:GetTypes(raw)
local types, type = {}, self:GetDamageType()
for enum, name in next, DamageName do
if bit.band(type, enum) ~= 0 then
types[#types + 1] = raw and enum or name
end
end
return types
end
hook.Add("EntityTakeDamage", "PrintDamageTypes", function(target, dmg)
if dmg:GetAttacker():IsPlayer() then
dmg:GetAttacker():ChatPrint("youve deal damage: "..
table.concat(dmg:GetTypes(), ", ")
)
end
if target:IsPlayer() then
target:ChatPrint("youve got damage: "..
table.concat(dmg:GetTypes(), ", ")
)
end
end)