/
npc.lua
83 lines (54 loc) · 2.13 KB
/
npc.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
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
-- Add Network Strings we use
util.AddNetworkString( "PlayerKilledNPC" )
util.AddNetworkString( "NPCKilledNPC" )
--[[---------------------------------------------------------
Name: gamemode:OnNPCKilled( entity, attacker, inflictor )
Desc: The NPC has died
-----------------------------------------------------------]]
function GM:OnNPCKilled( ent, attacker, inflictor )
-- Convert the inflictor to the weapon that they're holding if we can.
if ( inflictor && inflictor != NULL && attacker == inflictor && (inflictor:IsPlayer() || inflictor:IsNPC()) ) then
inflictor = inflictor:GetActiveWeapon()
if ( attacker == NULL ) then inflictor = attacker end
end
local InflictorClass = "World"
local AttackerClass = "World"
if ( IsValid( inflictor ) ) then InflictorClass = inflictor:GetClass() end
if ( IsValid( attacker ) ) then
AttackerClass = attacker:GetClass()
if ( attacker:IsVehicle() && IsValid( attacker:GetDriver() ) ) then
attacker = attacker:GetDriver()
end
if ( attacker:IsPlayer() ) then
net.Start( "PlayerKilledNPC" )
net.WriteString( ent:GetClass() )
net.WriteString( InflictorClass )
net.WriteEntity( attacker )
net.Broadcast()
return
end
end
net.Start( "NPCKilledNPC" )
net.WriteString( ent:GetClass() )
net.WriteString( InflictorClass )
net.WriteString( AttackerClass )
net.Broadcast()
end
--[[---------------------------------------------------------
Name: gamemode:ScaleNPCDamage( ply, hitgroup, dmginfo )
Desc: Scale the damage based on being shot in a hitbox
-----------------------------------------------------------]]
function GM:ScaleNPCDamage( npc, hitgroup, dmginfo )
-- More damage if we're shot in the head
if ( hitgroup == HITGROUP_HEAD ) then
dmginfo:ScaleDamage( 2 )
end
-- Less damage if we're shot in the arms or legs
if ( hitgroup == HITGROUP_LEFTARM ||
hitgroup == HITGROUP_RIGHTARM ||
hitgroup == HITGROUP_LEFTLEG ||
hitgroup == HITGROUP_RIGHTLEG ||
hitgroup == HITGROUP_GEAR ) then
dmginfo:ScaleDamage( 0.25 )
end
end