I tried to apply parts of script you are making for me to make a chain of rounds that could change frames depending on roundcount or if the gun's reloading (belt fed, so the belt just.. wouldn't be there) but I got to a stage where there are no errors, yet I can't figure out what's wrong.
If the main code of the thread is frustrating you enough already you can just skip this spoiler.
This is a modified version of your gun chambering code, it just has some SetNumberValues stuck in.
Code:
function Create(self)
self.parent = nil;
self.pullTimer = Timer();
self.newMag = false;
self.chamber = true; --
--self.pullTimer:Reset(); --
self.num = math.pi; --
self.sfx = true; --
self.negNum = 0;
self.sLength = self.SharpLength;
local actor = MovableMan:GetMOFromID(self.RootID);
if actor and IsAHuman(actor) then
self.parent = ToAHuman(actor);
end
end
function Update(self)
local actor = MovableMan:GetMOFromID(self.RootID);
if actor and IsAHuman(actor) then
self.parent = ToAHuman(actor);
else
self.parent = nil;
-- cock and load on pickup
--self.chamber = true; --
--self.pullTimer:Reset(); --
--self.num = math.pi; --
--self.sfx = true; --
end
if self.HFlipped then
self.negNum = -1;
else
self.negNum = 1;
end
if self.parent then
if self.Magazine then
self:SetNumberValue("Magazine", self.Magazine.RoundCount)
if self.newMag == true then
self.chamber = true;
self.pullTimer:Reset();
self.num = math.pi;
self.sfx = true;
self.newMag = false;
end
else
self.newMag = true;
self:SetNumberValue("Reloading", 1)
end
if self.chamber == true then
self:Deactivate();
--self.parent:GetController():SetState(Controller.WEAPON_FIRE,false);
if self.pullTimer:IsPastSimMS(1500) then
--self.parent:GetController():SetState(Controller.AIM_SHARP,false);
--self.Frame = 1;
if self.sfx ~= false then
sfx = CreateAEmitter("Chamber " .. self.PresetName);
sfx.Pos = self.Pos;
MovableMan:AddParticle(sfx);
self.sfx = false;
end
self.SharpLength = self.SharpLength+(self.sLength/30)*math.sin(2*self.num);
self.RotAngle = self.RotAngle +self.negNum*math.sin(self.num)/2;
self.num = self.num - math.pi*0.08;
end
if self.num <= 0 then
self.num = 0;
self.chamber = false;
self.SharpLength = self.sLength;
end
end
end
end
The above is attached to the gun. The next bit of code is attached to the chain of rounds, which is an attachable similar to the one we are using for this chargegun right now. (actually, I just copy pasted it over and changed the filepath and name)
Code:
function Create(self)
self.Frame = 0;
end
function Update(self)
if self.parent == nil then -- if self.parent isn't defined
mo = MovableMan:GetMOFromID(self.RootID);
if mo then
if IsHDFirearm(mo) then -- if root ID is the gun
self.parent = ToHDFirearm(mo);
elseif IsAHuman(mo) then -- if root ID is the actor holding the gun
if ToAHuman(mo).EquippedItem and IsHDFirearm(ToAHuman(mo).EquippedItem) then
self.parent = ToHDFirearm(ToAHuman(mo).EquippedItem);
end
end
end
else
self.parent.Magazine.RoundCount = self.parent:GetNumberValue("Magazine")
if self.parent:NumberValueExists("Reloading") then
self.Frame = 1;
end
if self.parent.Magazine.RoundCount == 5 then
self.Frame = 2;
elseif self.parent.Magazine.RoundCount == 4 then
self.Frame = 3;
elseif self.parent.Magazine.RoundCount == 3 then
self.Frame = 4;
elseif self.parent.Magazine.RoundCount == 2 then
self.Frame = 5;
elseif self.parent.Magazine.RoundCount == 1 then
self.Frame = 1;
end
end
end
You can also notice I didn't include alternating sprites (The chain is made up of darker and lighter rounds so it looks like an actual chain, but they don't move when firing which looks odd) because I had no idea how to. At all.
Should be much simpler than this whole charge-up stuff, if you're up for it. The problem is that it of course gives no errors yet still doesn't do anything, not when reloading or at 5 rounds and under.
Cheers. (