Skip to content

Commit

Permalink
angle info fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TimGoll committed Oct 8, 2023
1 parent 54e6eda commit 9cea89e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 53 deletions.
92 changes: 58 additions & 34 deletions gamemodes/terrortown/gamemode/server/sv_corpse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -337,40 +337,43 @@ function CORPSE.ShowSearch(ply, rag, isCovert, isLongRange)
local dtime = rag.time or 0

-- prepare additional corpse information
local kill_distance = CORPSE_KILL_NONE
if (rag.scene.hit_trace) then
local raw_kill_distance = rag.scene.hit_trace.StartPos:Distance(rag.scene.hit_trace.HitPos)
if (raw_kill_distance < 200) then
kill_distance = CORPSE_KILL_POINT_BLANK
elseif (raw_kill_distance >= 700) then
kill_distance = CORPSE_KILL_FAR
elseif (raw_kill_distance >= 200) then
kill_distance = CORPSE_KILL_CLOSE
local killDistance = CORPSE_KILL_NONE
if rag.scene.hit_trace then
local rawKillDistance = rag.scene.hit_trace.StartPos:Distance(rag.scene.hit_trace.HitPos)
if rawKillDistance < 200 then
killDistance = CORPSE_KILL_POINT_BLANK
elseif rawKillDistance >= 700 then
killDistance = CORPSE_KILL_FAR
elseif rawKillDistance >= 200 then
killDistance = CORPSE_KILL_CLOSE
end
end

local kill_hitgroup = HITGROUP_GENERIC
if (rag.scene.hit_group and rag.scene.hit_group > 0) then
kill_hitgroup = rag.scene.hit_group
local killHitGroup = HITGROUP_GENERIC
if rag.scene.hit_group and rag.scene.hit_group > 0 then
killHitGroup = rag.scene.hit_group
end

local kill_floor_surface = rag.scene.ground_type or 0
local kill_water_level = rag.scene.water_level or 0
local killFloorSurface = rag.scene.floorSurface or 0
local killWaterLevel = rag.scene.waterLevel or 0

local kill_angle = CORPSE_KILL_NONE
if (rag.scene.hit_trace) then
local raw_kill_angle = math.abs(math.AngleDifference((rag.scene.hit_trace.HitPos - rag.scene.victim.pos):Angle().yaw, rag.scene.victim.aim_yaw))
if (raw_kill_angle < 180) then
kill_angle = CORPSE_KILL_FRONT
local killAngle = CORPSE_KILL_NONE
if rag.scene.hit_trace then
local rawKillAngle = math.abs(math.AngleDifference(rag.scene.hit_trace.StartAng.yaw, rag.scene.victim.aim_yaw))

if rawKillAngle < 45 then
killAngle = CORPSE_KILL_BACK
elseif rawKillAngle < 135 then
killAngle = CORPSE_KILL_SIDE
else
kill_angle = CORPSE_KILL_BACK
killAngle = CORPSE_KILL_FRONT
end
end

local ply_model = rag.scene.ply_model or ""
local ply_model_color = rag.scene.ply_model_color or COLOR_WHITE
local ply_sid64 = rag.scene.ply_sid64 or ""
local last_damage = math.max(0, rag.scene.last_damage)
local plyModel = rag.scene.plyModel or ""
local plyModelColor = rag.scene.plyModelColor or COLOR_WHITE
local plySID64 = rag.scene.plySID64 or ""
local lastDamage = math.max(0, rag.scene.lastDamage)

local owner = player.GetBySteamID64(rag.sid64)
owner = IsValid(owner) and owner:EntIndex() or -1
Expand All @@ -383,7 +386,7 @@ function CORPSE.ShowSearch(ply, rag, isCovert, isLongRange)
end

-- only give credits if body is also confirmed
if (not isCovert) then
if not isCovert then
GiveFoundCredits(ply, rag, isLongRange)
end

Expand Down Expand Up @@ -465,16 +468,16 @@ function CORPSE.ShowSearch(ply, rag, isCovert, isLongRange)

net.WriteBit(isLongRange)

net.WriteUInt(kill_distance, 2)
net.WriteUInt(kill_hitgroup, 8)
net.WriteUInt(kill_floor_surface, 8)
net.WriteUInt(kill_water_level, 2)
net.WriteUInt(kill_angle, 2)
net.WriteString(ply_model)
net.WriteVector(ply_model_color)
net.WriteString(ply_sid64)
net.WriteUInt(killDistance, 2)
net.WriteUInt(killHitGroup, 8)
net.WriteUInt(killFloorSurface, 8)
net.WriteUInt(killWaterLevel, 2)
net.WriteUInt(killAngle, 2)
net.WriteString(plyModel)
net.WriteVector(plyModelColor)
net.WriteString(plySID64)
net.WriteUInt(credits, 8)
net.WriteUInt(last_damage, 16)
net.WriteUInt(lastDamage, 16)

-- 133 + string data + #kill_entids * 8 + team + 1
-- 200 + ?
Expand Down Expand Up @@ -576,12 +579,33 @@ local function GetSceneData(victim, attacker, dmginfo)
local att = attacker:LookupAttachment("anim_attachment_RH")
local angpos = attacker:GetAttachment(att)

PrintTable(angpos)

if not angpos then
scene.hit_trace.StartPos = attacker:GetShootPos()
scene.hit_trace.StartAng = attacker:EyeAngles()
else
scene.hit_trace.StartPos = angpos.Pos
scene.hit_trace.StartAng = angpos.Ang
end

PrintTable(scene.hit_trace)
end

scene.waterLevel = victim:WaterLevel();
scene.hitGroup = victim:LastHitGroup()
scene.floorSurface = 0
local groundTrace = util.TraceLine({
start = victim:GetPos(),
endpos = victim:GetPos() + Vector(0, 0, -100)
})
if groundTrace.Hit then
scene.floorSurface = groundTrace.MatType
end
scene.plyModel = victim:GetModel()
scene.plyModelColor = victim:GetPlayerColor()
scene.plySID64 = victim:SteamID64()
scene.lastDamage = dmginfo:GetDamage()

return scene
end
Expand Down
18 changes: 0 additions & 18 deletions gamemodes/terrortown/gamemode/server/sv_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -681,24 +681,6 @@ function GM:DoPlayerDeath(ply, attacker, dmginfo)

ply.server_ragdoll = rag

-- add additional ragdoll info that depends on the kill
ply.server_ragdoll.scene = ply.server_ragdoll.scene or {}

ply.server_ragdoll.scene.water_level = ply.server_ragdoll:WaterLevel();
ply.server_ragdoll.scene.hit_group = ply:LastHitGroup()
ply.server_ragdoll.scene.ground_type = 0
local groundTrace = util.TraceLine({
start = ply:GetPos(),
endpos = ply:GetPos() + Vector(0, 0, -100)
})
if (groundTrace.Hit) then
ply.server_ragdoll.scene.ground_type = groundTrace.MatType
end
ply.server_ragdoll.scene.ply_model = ply:GetModel()
ply.server_ragdoll.scene.ply_model_color = ply:GetPlayerColor()
ply.server_ragdoll.scene.ply_sid64 = ply:SteamID64()
ply.server_ragdoll.scene.last_damage = dmginfo:GetDamage()

CreateDeathEffect(ply, false)

util.StartBleeding(rag, dmginfo:GetDamage(), 15)
Expand Down
1 change: 1 addition & 0 deletions lua/terrortown/lang/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,7 @@ L.kill_distance_far = "The victim was shot from a long distance away."

L.kill_from_front = "The victim was shot from the front."
L.kill_from_back = "The victim was shot from behind."
L.kill_from_side = "The victim was shot from the side."

L.search_hitgroup_head = "The projectile was found in their head."
L.search_hitgroup_chest = "The projectile was found in their chest."
Expand Down
4 changes: 3 additions & 1 deletion lua/ttt2/libraries/bodysearch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CORPSE_KILL_FAR = 3

CORPSE_KILL_FRONT = 1
CORPSE_KILL_BACK = 2
CORPSE_KILL_SIDE = 3

bodysearch = bodysearch or {}

Expand Down Expand Up @@ -61,7 +62,8 @@ if CLIENT then

local orientationToText = {
[CORPSE_KILL_FRONT] = "kill_from_front",
[CORPSE_KILL_BACK] = "kill_from_back"
[CORPSE_KILL_BACK] = "kill_from_back",
[CORPSE_KILL_SIDE] = "kill_from_side"
}

local floorIDToText = {
Expand Down

0 comments on commit 9cea89e

Please sign in to comment.