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