Skip to content

Instantly share code, notes, and snippets.

@x0rnn
Created May 19, 2023 18:49
Show Gist options
  • Save x0rnn/ad6a101685353704d50e897ce0f558da to your computer and use it in GitHub Desktop.
Save x0rnn/ad6a101685353704d50e897ce0f558da to your computer and use it in GitHub Desktop.
-- center prints damage given to the enemy and the distance for testing purposes
light_weapons = {1,2,3,5,6,7,8,9,10,11,12,13,14,17,37,38,44,45,46,50,51,53,54,55,56,61,62,66}
explosives = {15,16,18,19,20,22,23,26,39,40,41,42,52,63,64}
HR_HEAD = 0
HR_ARMS = 1
HR_BODY = 2
HR_LEGS = 3
HR_NONE = -1
HR_TYPES = {HR_HEAD, HR_ARMS, HR_BODY, HR_LEGS}
hitRegionsData = {}
function et_InitGame(levelTime, randomSeed, restart)
et.RegisterModname("dmg_print.lua "..et.FindSelf())
end
function getAllHitRegions(clientNum)
local regions = {}
for index, hitType in ipairs(HR_TYPES) do
regions[hitType] = et.gentity_get(clientNum, "pers.playerStats.hitRegions", hitType)
end
return regions
end
function hitType(clientNum)
local playerHitRegions = getAllHitRegions(clientNum)
if hitRegionsData[clientNum] == nil then
hitRegionsData[clientNum] = playerHitRegions
return 2
end
for index, hitType in ipairs(HR_TYPES) do
if playerHitRegions[hitType] > hitRegionsData[clientNum][hitType] then
hitRegionsData[clientNum] = playerHitRegions
return hitType
end
end
hitRegionsData[clientNum] = playerHitRegions
return -1
end
function has_value (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
function dist(a, b)
ax, ay, az = a[1], a[2], a[3]
bx, by, bz = b[1], b[2], b[3]
dx = math.abs(bx - ax)
dy = math.abs(by - ay)
dz = math.abs(bz - az)
d = math.sqrt((dx ^ 2) + (dy ^ 2) + (dz ^ 2))
return math.floor(d)
end
function et_Damage(target, attacker, damage, damageFlags, meansOfDeath)
if target ~= attacker and attacker ~= 1022 and attacker ~= 1023 then
local v_team = et.gentity_get(target, "sess.sessionTeam")
local k_team = et.gentity_get(attacker, "sess.sessionTeam")
local posk = et.gentity_get(target, "ps.origin")
local posv = et.gentity_get(attacker, "ps.origin")
local shotdist = dist(posk, posv)
if v_team ~= k_team then
if has_value(light_weapons, meansOfDeath) or has_value(explosives, meansOfDeath) then
local hitType = hitType(attacker)
if hitType == HR_HEAD then
if not has_value(explosives, meansOfDeath) then
et.trap_SendServerCommand(attacker, "cp \"HS " .. damage .. " HP, distance: " .. shotdist .. " units\";")
end
else
et.trap_SendServerCommand(attacker, "cp \"" .. damage .. " HP, distance: " .. shotdist .. " units\";")
end
end
end
end
end
function et_ClientSpawn(clientNum, revived, teamChange, restoreHealth)
hitRegionsData[clientNum] = getAllHitRegions(clientNum)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment