@@ -40,72 +40,70 @@ function Create(self)
40
40
-- Log an error or warning if preset is missing/incorrect
41
41
-- print("Warning: Grapple Gun Guide Arrow preset not found or incorrect type.")
42
42
end
43
+
44
+ self .originalRoundCount = 1
45
+ self .hasGrappleActive = false
43
46
end
44
47
45
48
function Update (self )
46
49
local parent = self :GetRootParent ()
47
50
48
51
-- Ensure the gun is held by a valid, player-controlled Actor.
49
52
if not parent or not IsActor (parent ) then
50
- self :Deactivate () -- If not held by an actor, deactivate.
53
+ self :Deactivate ()
51
54
return
52
55
end
53
56
54
- local parentActor = ToActor (parent ) -- Cast to Actor base type
55
- -- Specific casting to AHuman or ACrab can be done if needed for type-specific logic
57
+ local parentActor = ToActor (parent )
56
58
57
59
if not parentActor :IsPlayerControlled () or parentActor .Status >= Actor .DYING then
58
- self :Deactivate () -- Deactivate if not player controlled or if player is dying.
60
+ self :Deactivate ()
59
61
return
60
62
end
61
63
62
64
local controller = parentActor :GetController ()
63
65
if not controller then
64
- self :Deactivate () -- Should not happen if IsPlayerControlled is true, but good check.
66
+ self :Deactivate ()
65
67
return
66
68
end
67
69
68
- -- REMOVE/COMMENT OUT this section that deactivates in background:
69
- --[[
70
- if parentActor.EquippedBGItem and parentActor.EquippedBGItem.ID == self.ID and parentActor.EquippedItem then
71
- self:Deactivate()
72
- // Potentially return here if no further logic should run for a BG equipped grapple gun.
73
- end
74
- --]]
75
-
76
- -- Allow gun to stay active in background for rope functionality
77
-
78
70
-- Magazine handling (visual representation of the hook's availability)
79
71
if self .Magazine and MovableMan :IsParticle (self .Magazine ) then
80
72
local magazineParticle = ToMOSParticle (self .Magazine )
81
73
82
- -- Double tapping crouch retrieves the hook (if a grapple is active)
83
- -- This logic seems to be for initiating a retrieve action from the gun itself.
84
- -- The actual unhooking is handled by the Grapple.lua script's tap detection.
85
- -- This section might be redundant if Grapple.lua's tap detection is comprehensive.
86
- if magazineParticle .Scale == 1 then -- Assuming Scale 1 means hook is "loaded" / available to fire
87
- -- The following stance offsets seem to be for when the hook is *not* fired yet.
88
- -- Consider if this is the correct condition.
89
- local parentSprite = ToMOSprite (self :GetParent ()) -- Assuming self:GetParent() is the gun's sprite component
74
+ -- Check if we have an active grapple
75
+ local hasActiveGrapple = false
76
+ for mo in MovableMan .AddedActors do
77
+ if mo and mo .PresetName == " Grapple Gun Claw" and mo .parentGun and mo .parentGun .ID == self .ID then
78
+ hasActiveGrapple = true
79
+ break
80
+ end
81
+ end
82
+
83
+ -- Update magazine based on grapple state
84
+ if hasActiveGrapple then
85
+ magazineParticle .RoundCount = 0 -- Empty when grapple is out
86
+ magazineParticle .Scale = 0 -- Hidden
87
+ self .hasGrappleActive = true
88
+ elseif self .hasGrappleActive and not hasActiveGrapple then
89
+ -- Grapple just returned, restore ammo
90
+ magazineParticle .RoundCount = 1
91
+ magazineParticle .Scale = 1
92
+ magazineParticle .Frame = 0
93
+ self .hasGrappleActive = false
94
+ end
95
+
96
+ -- Set stance offset when hook is loaded
97
+ if magazineParticle .Scale == 1 then
98
+ local parentSprite = ToMOSprite (self :GetParent ())
90
99
if parentSprite then
91
100
local spriteWidth = parentSprite :GetSpriteWidth () or 0
92
101
self .StanceOffset = Vector (spriteWidth , 1 )
93
102
self .SharpStanceOffset = Vector (spriteWidth , 1 )
94
103
end
95
-
96
- -- REMOVE the entire crouch-tap section from the gun - it should only be in the hook
97
- -- The gun should NOT handle unhooking directly
98
-
99
- -- Only keep this for other gun functionality, NOT for unhooking:
100
- if controller :IsState (Controller .WEAPON_RELOAD ) then
101
- -- Gun's own reload logic here (if any)
102
- -- Do NOT send unhook signals from here
103
- end
104
-
105
104
end
106
105
107
106
-- Guide arrow visibility logic
108
- -- Show if magazine scale is 0 (hook is fired) AND not sharp aiming, OR if parent is moving fast.
109
107
local shouldShowGuide = false
110
108
if magazineParticle .Scale == 0 and not controller :IsState (Controller .AIM_SHARP ) then
111
109
shouldShowGuide = true
@@ -114,55 +112,26 @@ function Update(self)
114
112
end
115
113
self .guide = shouldShowGuide
116
114
else
117
- self .guide = false -- No magazine or not a particle, so no guide based on it.
115
+ self .guide = false
118
116
end
119
117
120
118
-- Draw the guide arrow if enabled and valid
121
119
if self .guide and self .arrow and self .arrow .ID ~= rte .NoMOID then
122
120
local frame = 0
123
121
if parentActor .Vel and parentActor .Vel :MagnitudeIsGreaterThan (12 ) then
124
- frame = 1 -- Use a different arrow frame for higher speeds
122
+ frame = 1
125
123
end
126
124
127
- -- Calculate positions for drawing the arrow
128
- -- EyePos might not exist on all Actor types, ensure parentActor has it or use a fallback.
129
- local eyePos = parentActor .EyePos or Vector (0 ,0 )
130
- local startPos = (parentActor .Pos + eyePos + self .Pos )/ 3 -- Averaged position
125
+ local eyePos = parentActor .EyePos or Vector (0 ,0 )
126
+ local startPos = (parentActor .Pos + eyePos + self .Pos )/ 3
131
127
local aimAngle = parentActor :GetAimAngle (true )
132
- local aimDistance = parentActor .AimDistance or 50 -- Default AimDistance if not present
128
+ local aimDistance = parentActor .AimDistance or 50
133
129
local guidePos = startPos + Vector (aimDistance + (parentActor .Vel and parentActor .Vel .Magnitude or 0 ), 0 ):RadRotate (aimAngle )
134
130
135
- -- Ensure the arrow MO still exists before trying to draw with it
136
131
if MovableMan :IsValid (self .arrow ) then
137
132
PrimitiveMan :DrawBitmapPrimitive (ActivityMan :GetActivity ():ScreenOfPlayer (controller .Player ), guidePos , self .arrow , aimAngle , frame )
138
133
else
139
- self .arrow = nil -- Arrow MO was deleted, nullify reference
140
- end
141
- end
142
-
143
- -- Ensure magazine is visually "full" and ready if no grapple is active.
144
- -- This assumes the HDFirearm's standard magazine logic handles firing.
145
- -- If a grapple claw MO (the projectile) is active, Grapple.lua will hide the magazine.
146
- -- This section ensures it's visible when no grapple is out.
147
- if self .Magazine and MovableMan :IsParticle (self .Magazine ) then
148
- local magParticle = ToMOSParticle (self .Magazine )
149
- local isActiveGrapple = false
150
- -- Check if there's an active grapple associated with this gun
151
- for mo_instance in MovableMan :GetMOsByPreset (" Grapple Gun Claw" ) do
152
- if mo_instance and mo_instance .parentGun and mo_instance .parentGun .ID == self .ID then
153
- isActiveGrapple = true
154
- break
155
- end
156
- end
157
-
158
- if not isActiveGrapple then
159
- magParticle .RoundCount = 1 -- Visually full
160
- magParticle .Scale = 1 -- Visible
161
- magParticle .Frame = 0 -- Standard frame
162
- else
163
- magParticle .Scale = 0 -- Hidden by active grapple (Grapple.lua also does this)
164
- magParticle .RoundCount = 0 -- Visually empty
165
-
134
+ self .arrow = nil
166
135
end
167
136
end
168
137
end
0 commit comments