Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 94b2b9f

Browse files
committed
Fixes to grenade bandoliers so they behave better when dropped when the actor dies
They now drop at the bomb location if appropriate, and they don't accidentally give you a free grenade Also some cleanups
1 parent 8c59a63 commit 94b2b9f

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

Data/Base.rte/Devices/Shared/Scripts/GrenadeBandolierAttachable.lua

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ local replenishGrenade = function(self, forceEquipGrenade)
2222
if forceEquipGrenade or self.grenadeReplenishDelay < 100 then
2323
self:modifyGrenadeCount(-1);
2424
self.rootParent.UpperBodyState = AHuman.WEAPON_READY;
25-
-- Only actually equip the grenade if the root parent was previously holding one, or we're forcing it to equip it. This avoids issues when, for example, removing a grenade from the root paren'ts inventory via Lua.
25+
-- Only actually equip the grenade if the root parent was previously holding one, or we're forcing it to equip it. This avoids issues when, for example, removing a grenade from the root parent's inventory via Lua.
2626
return (forceEquipGrenade or self.grenadePreviouslyHeldByRootParent) and self.rootParent:EquipNamedDevice(self.grenadeTech, self.grenadeName, true);
2727
else
2828
self.grenadeReplenishGUITimer:Reset();
@@ -91,7 +91,7 @@ function Create(self)
9191
end
9292

9393
function Update(self)
94-
if self.rootParent and self.rootParent.Health > 0 and MovableMan:IsActor(self.rootParent) then
94+
if self.rootParent and self.rootParent.Health > 0 and MovableMan:ValidMO(self.rootParent) then
9595
local rootParentEquippedItemModuleAndPresetName = self.rootParent.EquippedItem ~= nil and self.rootParent.EquippedItem:GetModuleAndPresetName() or nil;
9696
local rootParentIsHoldingGrenade = rootParentEquippedItemModuleAndPresetName == self.grenadeObject:GetModuleAndPresetName();
9797

@@ -154,16 +154,37 @@ function Update(self)
154154
end
155155

156156
function Destroy(self)
157-
if self.rootParent and MovableMan:IsActor(self.rootParent) then
157+
if self.rootParent and MovableMan:ValidMO(self.rootParent) then
158158
self.rootParent:RemoveNumberValue(self.bandolierKey);
159159
end
160160
if self.currentGrenadeCount > 0 then
161+
local bandolierPosition = self.Pos;
162+
local bandolierVel = self.Vel;
163+
local bandolierRotAngle = self.RotAngle;
164+
local bandolierAngularVel = self.AngularVel;
165+
161166
if self.grenadePreviouslyHeldByRootParent then
162-
self.grenadePreviouslyHeldByRootParent.ToDelete = true;
167+
if MovableMan:ValidMO(self.grenadePreviouslyHeldByRootParent) and not self.grenadePreviouslyHeldByRootParent:IsActivated() then
168+
self.grenadePreviouslyHeldByRootParent.ToDelete = true;
169+
self:modifyGrenadeCount(1);
170+
171+
bandolierPosition = self.grenadePreviouslyHeldByRootParent.Pos;
172+
bandolierVel = self.grenadePreviouslyHeldByRootParent.Vel;
173+
bandolierRotAngle = self.grenadePreviouslyHeldByRootParent.RotAngle;
174+
bandolierAngularVel = self.grenadePreviouslyHeldByRootParent.AngularVel;
175+
end
176+
end
177+
if self.currentGrenadeCount > 0 then
178+
self.bandolierObjectForDropping:SetNumberValue("GrenadesRemainingInBandolier", self.currentGrenadeCount);
179+
180+
self.bandolierObjectForDropping.Pos = bandolierPosition;
181+
self.bandolierObjectForDropping.Vel = bandolierVel;
182+
self.bandolierObjectForDropping.RotAngle = bandolierRotAngle;
183+
self.bandolierObjectForDropping.AngularVel = bandolierAngularVel;
184+
185+
self.bandolierObjectForDropping.Mass = self.bandolierMass + (self.grenadeMass * self.currentGrenadeCount);
186+
187+
MovableMan:AddItem(self.bandolierObjectForDropping);
163188
end
164-
self.bandolierObjectForDropping:SetNumberValue("GrenadesRemainingInBandolier", self.currentGrenadeCount + 1);
165-
self.bandolierObjectForDropping.Pos = self.Pos;
166-
self.bandolierObjectForDropping.Mass = self.bandolierMass + (self.grenadeMass * self.currentGrenadeCount);
167-
MovableMan:AddItem(self.bandolierObjectForDropping);
168189
end
169190
end

0 commit comments

Comments
 (0)