@@ -11,6 +11,8 @@ local ACF = ACF
11
11
local Classes = ACF .Classes
12
12
local Utilities = ACF .Utilities
13
13
local Clock = Utilities .Clock
14
+ local MaxDistance = ACF .LinkDistance * ACF .LinkDistance
15
+ local UnlinkSound = " physics/metal/metal_box_impact_bullet%s.wav"
14
16
15
17
local function UpdateTotalAmmo (Entity )
16
18
local Total = 0
@@ -26,9 +28,22 @@ local function UpdateTotalAmmo(Entity)
26
28
WireLib .TriggerOutput (Entity , " Total Ammo" , Total )
27
29
end
28
30
31
+ local function CheckDistantLink (Entity , Crate , EntPos )
32
+ local CrateUnlinked = false
33
+
34
+ if EntPos :DistToSqr (Crate :GetPos ()) > MaxDistance then
35
+ local Sound = UnlinkSound :format (math.random (1 , 3 ))
36
+
37
+ Entity :EmitSound (Sound , 70 , math.random (99 , 109 ), ACF .Volume )
38
+ Crate :EmitSound (Sound , 70 , math.random (99 , 109 ), ACF .Volume )
39
+
40
+ CrateUnlinked = Entity :Unlink (Crate )
41
+ end
42
+
43
+ return CrateUnlinked
44
+ end
45
+
29
46
do -- Spawning and Updating --------------------
30
- local UnlinkSound = " physics/metal/metal_box_impact_bullet%s.wav"
31
- local MaxDistance = ACF .LinkDistance * ACF .LinkDistance
32
47
local CheckLegal = ACF .CheckLegal
33
48
local WireIO = Utilities .WireIO
34
49
local Entities = Classes .Entities
@@ -157,21 +172,6 @@ do -- Spawning and Updating --------------------
157
172
UpdateTotalAmmo (Entity )
158
173
end
159
174
160
- local function CheckDistantLinks (Entity , Source )
161
- local Position = Entity :GetPos ()
162
-
163
- for Link in pairs (Entity [Source ]) do
164
- if Position :DistToSqr (Link :GetPos ()) > MaxDistance then
165
- local Sound = UnlinkSound :format (math.random (1 , 3 ))
166
-
167
- Entity :EmitSound (Sound , 70 , math.random (99 , 109 ), ACF .Volume )
168
- Link :EmitSound (Sound , 70 , math.random (99 , 109 ), ACF .Volume )
169
-
170
- Entity :Unlink (Link )
171
- end
172
- end
173
- end
174
-
175
175
hook .Add (" ACF_OnSetupInputs" , " ACF Rack Motor Delay" , function (Entity , List , _ , Rack )
176
176
if Entity :GetClass () ~= " acf_rack" then return end
177
177
if not Rack .CanDropMissile then return end
@@ -239,7 +239,11 @@ do -- Spawning and Updating --------------------
239
239
timer .Create (" ACF Rack Clock " .. Rack :EntIndex (), 3 , 0 , function ()
240
240
if not IsValid (Rack ) then return end
241
241
242
- CheckDistantLinks (Rack , " Crates" )
242
+ local Position = Rack :GetPos ()
243
+
244
+ for Link in pairs (Rack .Crates ) do
245
+ CheckDistantLink (Rack , Link , Position )
246
+ end
243
247
end )
244
248
245
249
timer .Create (" ACF Rack Ammo " .. Rack :EntIndex (), 1 , 0 , function ()
@@ -285,6 +289,14 @@ do -- Spawning and Updating --------------------
285
289
286
290
HookRun (" ACF_OnEntityUpdate" , " acf_rack" , self , Data , Rack )
287
291
292
+ local Crates = self .Crates
293
+
294
+ if next (Crates ) then
295
+ for Crate in pairs (Crates ) do
296
+ self :Unlink (Crate )
297
+ end
298
+ end
299
+
288
300
self :UpdateOverlay (true )
289
301
290
302
net .Start (" ACF_UpdateEntity" )
@@ -386,6 +398,7 @@ do -- Entity Link/Unlink -----------------------
386
398
if Weapon .Crates [Target ] then return false , " This rack is already linked to this crate." end
387
399
if Target .Weapons [Weapon ] then return false , " This rack is already linked to this crate." end
388
400
if Target .IsRefill then return false , " Refill crates cannot be linked!" end
401
+ if Target :GetPos ():DistToSqr (Weapon :GetPos ()) > MaxDistance then return false , " This crate is too far away from this rack." end
389
402
390
403
local Blacklist = Target .RoundData .Blacklist
391
404
@@ -624,7 +637,7 @@ do -- Loading ----------------------------------
624
637
local Index , Point = self :GetNextMountPoint (" Empty" )
625
638
local Crate = GetNextCrate (self )
626
639
627
- if not self .Firing and Index and Crate then
640
+ if not self .Firing and Index and Crate and not CheckDistantLink ( self , Crate , self : GetPos ()) then
628
641
local Missile = AddMissile (self , Point , Crate )
629
642
local ReloadTime = Missile .ReloadTime
630
643
0 commit comments