Re: Changing An HDFirearm Sprite Using Lua
Your problem was that you referenced a (global) variable that had never been defined. By defining FCCALOG in the create function you allowed it to be referenced.
To change the sprite just make multiple frames and set it to the frame you want. I can't say with 100% surety that this'll fix it but it'll definitely be neater, get rid of the line self.Frame = 0 in the update and add self.Frame = FCCA instead since frame and FCCA seem to always be the same.
Also, I may be mistaken here since I'm not exactly sure what you're trying to achieve but you could probably simplify all the timer stuff to the following, though it may mess up the stuff at the end.
Code:
if self.timer:IsPastSimMS(250) then
self.FCCA = self.FCCA + 1;
self.Timer:Reset();
end
Similarly, it probably makes more sense to check if the gun is firing before doing the timer stuff in the first place instead of resetting the timer whenever it's not but that's not a big deal I think.
In general, when looking for errors I'd suggest throwing in prints to find the problem, printing for each timer change would probably help you out.
Finally, note that since you're using global variables the script will affect every gun that uses it so when one fires they all change frames and the minimum distance of all of them will be affected. To get around that either use things like the gun's sharpness to determine stuff for the bullet or make a global table containing all the guns, sort through everything in that table for the closest gun and use its FCCALOG[i] value. Or maybe I'm looking at this in the wrong way and there's an easier solution, hard to say since I don't really know what the gun does.
Long winded post aside, good luck, keep at it, I'm sure you'll figure it out.