summaryrefslogtreecommitdiff
path: root/gamemode/cl_targetid.lua
blob: 2ea338c8daa02f08f0f3ff6fe33f430ff295d765 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
TargetedEntity = nil

local TargetedName = nil
local TargetedTime = 0
local TargetedDist = Vector(0,0,0)

ValidTargetEnts = { "prop_physics", "sent_oxygen", "sent_fuel_diesel", "sent_fuel_gas", "sent_propane_tank", "sent_propane_canister", "sent_barrel_radioactive", "sent_barrel_biohazard" }

function GM:GetEntityID( ent )

	if table.HasValue( ValidTargetEnts, ent:GetClass() ) then

		local tbl = item.GetByClass( ent:GetClass() )

		if tbl then

			TargetedName = tbl.Name
			TargetedEntity = ent
			TargetedDist = Vector( 0, 0, TargetedEntity:OBBCenter():Distance( TargetedEntity:OBBMaxs() ) )

		else

			tbl = item.GetByModel( ent:GetModel() )

			if tbl then

				TargetedName = tbl.Name
				TargetedEntity = ent
				TargetedDist = Vector( 0, 0, TargetedEntity:OBBCenter():Distance( TargetedEntity:OBBMaxs() ) )

			end

		end

	elseif ent:GetClass() == "sent_droppedgun" then

		local tbl = item.GetByModel( ent:GetModel() )

		if tbl then

			TargetedName = tbl.Name
			TargetedEntity = ent
			TargetedDist = Vector( 0, 0, 10 )

		end

	elseif ent:GetClass() == "sent_lootbag" then

		TargetedName = "Loot"
		TargetedEntity = ent
		TargetedDist = Vector( 0, 0, 10 )

	elseif ent:GetClass() == "sent_cash" then

		TargetedName = ent:GetNWInt( "Cash", 10 ) .. " " .. GAMEMODE.CurrencyName .. "s"
		TargetedEntity = ent
		TargetedDist = Vector( 0, 0, 5 )

	elseif ent:GetClass() == "sent_antidote" then

		TargetedName = "Antidote Crate"
		TargetedEntity = ent
		TargetedDist = Vector( 0, 0, 15 )

	elseif ent:GetClass() == "sent_supplycrate" then

		TargetedName = "Supply Crate"
		TargetedEntity = ent
		TargetedDist = Vector( 0, 0, 15 )

	elseif ent:GetClass() == "sent_bonuscrate" then

		TargetedName = "Weapon Cache"
		TargetedEntity = ent
		TargetedDist = Vector( 0, 0, 25 )

	elseif ent:GetClass() == "npc_scientist" then

		TargetedName = "Field Researcher"
		TargetedEntity = ent
		TargetedDist = Vector( 0, 0, 40 )

	elseif ent:IsPlayer() and ent:Team() == TEAM_ARMY then

		TargetedName = ent:Name()
		TargetedEntity = ent
		TargetedDist = Vector( 0, 0, 35 )

	end

	if IsValid( TargetedEntity ) then

		TargetedTime = CurTime() + 5

	end

end

function GM:HUDTraces()

	local tr = util.TraceLine( util.GetPlayerTrace( LocalPlayer() ) )

	GAMEMODE.LastTraceEnt = tr.Entity

	if IsValid( GAMEMODE.LastTraceEnt ) and GAMEMODE.LastTraceEnt:GetPos():Distance( LocalPlayer():GetPos() ) < 800 then

		GAMEMODE:GetEntityID( GAMEMODE.LastTraceEnt )

	end

end

function GM:HUDDrawTargetID()

	if not IsValid( LocalPlayer() ) then return end

	if not LocalPlayer():Alive() or LocalPlayer():Team() == TEAM_ZOMBIES then return end

	if IsValid( TargetedEntity ) and TargetedTime > CurTime() then

		local worldpos = TargetedEntity:LocalToWorld( TargetedEntity:OBBCenter() ) + TargetedDist
		local pos = ( worldpos ):ToScreen()

		//print( TargetedName .. " " .. tostring(TargetedDist) .. tostring(pos.visible) .. " - " .. pos.x .. " n " .. pos.y )

		if pos.visible then

			draw.SimpleText( TargetedName or "Error", "AmmoFontSmall", pos.x, pos.y, Color( 80, 150, 255 ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )

		end

	end

end