-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshared.lua
More file actions
140 lines (124 loc) · 3.53 KB
/
shared.lua
File metadata and controls
140 lines (124 loc) · 3.53 KB
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
136
137
138
139
140
local config = ttt_perky_config
ENT.Type = "anim"
ENT.Model = Model( "models/props/cs_office/radio.mdl" )
ENT.LifeTime = config.radiojammer_duration
ENT.destructTime = 0
ENT.SoundInterval = config.radiojammer_sound_interval
ENT.NextSound = 0
ENT.DetectiveNearRadius = 400
ENT.Health = config.radiojammer_health
local jamSound = Sound( "npc/scanner/cbot_servochatter.wav" )
-- load sounds
local randomSounds = {}
for i = 1, 15 do
randomSounds[i] = Sound( "ambient/levels/prison/radio_random"..i..".wav" )
end
if SERVER then
AddCSLuaFile("shared.lua")
end
if CLIENT then
-- this entity can be DNA-sampled so we need some display info
ENT.Icon = "VGUI/ttt/icon_radiojammer"
ENT.PrintName = "Radio Jammer"
end
function ENT:Initialize()
self.Entity:SetModel( self.Model )
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
self.Entity:SetSolid(SOLID_VPHYSICS)
self.Entity:SetCollisionGroup(COLLISION_GROUP_NONE)
self.Entity:SetHealth( self.health )
if SERVER then
self.Entity:SetMaxHealth( self.health )
self.Entity:SetUseType(SIMPLE_USE)
self.destructTime = CurTime() + self.LifeTime
elseif CLIENT then
if LocalPlayer() == self:GetOwner() then
LocalPlayer().radiojammer = self.Entity
end
end
self.NextSound = CurTime() + self.SoundInterval
self.jamming = false
self.fingerprints = {}
end
function ENT:IsDetectiveNear()
local center = self:GetPos()
local r = self.DetectiveNearRadius ^ 2
local d = 0.0
local diff = nil
for _, ent in pairs(player.GetAll()) do
if IsValid(ent) and ent:IsActiveDetective() then
-- dot of the difference with itself is distance squared
diff = center - ent:GetPos()
d = diff:DotProduct(diff)
if d < r then
return true
end
end
end
return false
end
function ENT:Think()
if SERVER then
if CurTime() > self.destructTime then
self:DoExplode()
self:Remove()
end
if CurTime() > self.NextSound then
self.NextSound = CurTime() + self.SoundInterval
local amp = 100
if self:IsDetectiveNear() then
amp = 140
end
local n = math.random(1,15)
WorldSound( randomSounds[n], self:GetPos(), amp, 100 )
--WorldSound( jamSound, self:GetPos(), amp, 100 )
end
end
end
local zapsound = Sound("npc/assassin/ball_zap1.wav")
function ENT:OnTakeDamage(dmginfo)
self:TakePhysicsDamage(dmginfo)
self:SetHealth(self:Health() - dmginfo:GetDamage())
if self:Health() < 0 then
self:DoExplode()
self:Remove()
end
end
function ENT:DoExplode()
local effect = EffectData()
effect:SetOrigin( self:GetPos() )
util.Effect("cball_explode", effect)
WorldSound( zapsound, self:GetPos() )
end
function ENT:OnRemove()
if CLIENT then
if LocalPlayer() == self:GetOwner() then
LocalPlayer().radiojammer = nil
end
end
end
if SERVER then
function ENT.PlayerSay( ply, text, team )
if #ents.FindByClass( 'ttt_radiojammer' ) > 0 then
if not ply:HasEquipmentItem( EQUIP_RADIOFREQUENCY ) then
return "[JAMMED]"
end
end
end
hook.Add( 'PlayerSay', 'ttt_radiojammer_playersay', ENT.PlayerSay )
function ENT.PlayerCanHearVoice( listner, talker )
if #ents.FindByClass( 'ttt_radiojammer' ) > 0 then
if talker:IsSpec() then
return nil
elseif talker:IsActiveTraitor() then
return nil
elseif talker:HasEquipmentItem( EQUIP_RADIOFREQUENCY ) then
return nil
else
return false, false
end
end
end
hook.Add( 'PlayerCanHearPlayersVoice', 'ttt_radiojammer_PlayerCanHearPlayersVoice', ENT.PlayerCanHearVoice )
end