I also tried telling it to print all the PresetNames and it did print names, it just didn't include "M249 Top".
Edit: It turns out for some reason if the attachable doesn't hit MOs or get hit by MOs (not sure which), it doesn't find it.
Tue Jan 24, 2012 3:59 am
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: Changing self.Frame for an HDfirearm
Oh, MOs that are GetsHitByMOs = 0 don't get MOIDs.
Tue Jan 24, 2012 4:30 am
Zaggy1024
Joined: Sun Jan 22, 2012 6:39 am Posts: 12
Re: Changing self.Frame for an HDfirearm
Okay, now it's finding the attachable (had to move the searching code to Update(self) because it ran too soon to find the attachable in Create(self)), but when I try to make it change the frame, it doesn't do it (at least visually).
Edit: I made it print the frame that it was set to, and it is changing the value.
Could the problem be that there is no "Frame" property on MovableObjects, so I need to change the object to an MOSprite (and if so, how do you?)?
Edit again: I tried "ToMOSprite", and it didn't give an error, but it made no difference but to make the frame property's value never change at all. >.>
Edit again 2.0: It just magically started working! =D Now to make the script even fancier! =P
Editing the third time: I realized I forgot to try the RootID check (again), so I uncommented it, and it's not finding the attachable anymore.
Code:
for i = 1, MovableMan:GetMOIDCount() - 1 do object = MovableMan:GetMOFromID(i);
if object ~= nil and object.PresetName == "M249 Top" and object.RootID == self.ID then self.TopMO = ToMOSprite(object); print("M249 Top found!"); end end
The problem *seems* to be that the soldier carrying the gun is the "root" of the attachable on the gun, and not the gun itself (only when a soldier is carrying the gun).
Edit AGAIN: I got it working perfectly now (here's hoping I don't find another problem =P)! I even managed to make the code work for more than 3 frames, with ping-pong motion. It's made so that it'll play it at a certain speed and then stop it at the "end" of the animation, and then play it backwards before the reload finishes (the only problem is that I had to make the script have a pre-defined ReloadTime value, since the one from the INI is inaccessible).
Code:
function Create(self) self.MOName = "M249 Top"; -- Change this to the name of your animating MO self.MO = nil; self.ReloadTimer = Timer(); self.ReloadTime = 2800; -- Set this to the ReloadTime from your gun's INI, so that the animation times the reversing of the animation correctly self.FrameTimer = Timer(); self.FrameTime = 50; self.OriginalFrameIndex = 0; -- You can lower this by whatever amount you want to make the animation start later and end sooner self.FrameIndex = 0; -- This variable is here so that the frame number can go well above the FrameCount in the INI (so that it can ping-pong properly) end
function Update(self) if self.MO == nil then -- If there is no MO to animate, find one. for i = 1, MovableMan:GetMOIDCount() - 1 do object = MovableMan:GetMOFromID(i);
if object ~= nil and object.PresetName == self.MOName and object.RootID == self.RootID then self.MO = ToMOSprite(object); end end else -- If there is an MO to animate, animate it. if self:IsReloading() then -- If the gun is reloading if self.FrameTimer:IsPastSimMS(self.FrameTime) then -- ...and if the frame needs changing if self.ReloadTimer:IsPastSimMS(self.ReloadTime / 2) then -- ...and if the reload is halfway through, self.FrameIndex = self.FrameIndex - 1; -- ...it needs to play the animation in reverse (the FrameIndex is probably greater than the number of frames now). else -- If it's not past halfway through the reload, self.FrameIndex = self.FrameIndex + 1; -- ...play the animation forwards. end
self.FrameTimer:Reset(); -- Reset the frame timer. end else -- If the gun isn't reloading self.ReloadTimer:Reset(); -- ...reset the reload timer so that next time a reload starts it's at 0, self.FrameIndex = self.OriginalFrameIndex; -- ...and reset the frame index. end
if self.FrameIndex >= 0 and self:IsReloading() then -- If it's reloading or the FrameIndex isn't negative, self.MO.Frame = self.FrameIndex; -- ...update the frame to the one it should be on. else -- If it's not reloading, or the FrameIndex is negative, self.MO.Frame = 0; -- ...the frame needs to be 0 (if the frame is set to a negative number, it goes to the last frame) end end end
Whee, lotsa comments!
Tue Jan 24, 2012 4:42 am
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
Re: Changing self.Frame for an HDfirearm
That would be self.RootID, not self.ID
Tue Jan 24, 2012 9:23 pm
Zaggy1024
Joined: Sun Jan 22, 2012 6:39 am Posts: 12
Re: Changing self.Frame for an HDfirearm
Yeah, I noticed that (I did try it before, and for some reason it didn't work, but now it does)... it's working now (see my previous post in the edit above the spoiler).
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum