Data Realms Fan Forums
http://45.55.195.193/

Changing self.Frame for an HDfirearm
http://45.55.195.193/viewtopic.php?f=73&t=29648
Page 1 of 2

Author:  Zaggy1024 [ Sun Jan 22, 2012 7:14 am ]
Post subject:  Changing self.Frame for an HDfirearm

I'm trying to make my gun change its sprite when it's reloading, but either the Lua can't change the self.Frame value for HDFirearms, or I'm missing something. Here's the code I've got so far:

Code:
function Create(self)
end

function Update(self)
   if self:IsReloading() then
      self.Frame = 2
   else
      self.Frame = 2
   end
end

Author:  Abdul Alhazred [ Mon Jan 23, 2012 3:01 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

I'm pretty sure you are correct. I do not think it is possible to override what frame to use for firearms with Lua.

Author:  Azukki [ Mon Jan 23, 2012 3:31 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

Can an attachable on a HDFirearm have its sprite changed either?
Even a script for the attachable itself doesn't recognize "self" as valid, unless I'm doing it wrong.

You can change the magazine's frame, but on any weapon that reloads, the mag's naturally absent during that time.
So there's not even a decent work around for tweaking a gun's appearance, it seems. :-(

It would be great if SpriteAnimMode = 0 [don't animate] worked for HDFirearms, and would allow Lua to control the frames.
It'd be helpful for developing future official content too, maybe one of the content devs would be so gracious as to put in a word about it to Data?

Author:  CaveCricket48 [ Mon Jan 23, 2012 4:43 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

You can change the frame of an attachable if the script is on the gun. I didn't know of 'self' not working with attachables, I'll talk to Data about that.

Edit: I just did some testing, 'self' works perfectly fine with scripts on attachables.

Author:  blargiefarg [ Mon Jan 23, 2012 7:14 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

I can confirm what CC48 says. I'm working on a script attached to an HDFirearm, and so far everything works fine, can't say I've attempted to change the frame via Lua though.

Author:  Zaggy1024 [ Mon Jan 23, 2012 9:04 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

Okay, I'm trying to make an attachable (assuming I know even an inkling of how to do it), and it's saying that it "could not match property" on the line which I put "FrameCount = 2".

Code:
AddEffect = Attachable
   InstanceName = M249 Top
   Mass = 0
   HitsMOs = 0
   GetsHitByMOs = 0
   SpriteFile = ContentFile
      FilePath = M249.rte/M249Top.bmp
   FrameCount = 2
   SpriteOffset = Vector
      X = 0
      Y = 0
   EntryWound = AEmitter
      CopyOf = Dent Metal Light
   ExitWound = AEmitter
      CopyOf = Dent Metal Light
   AtomGroup = AtomGroup
      AutoGenerate = 1
      Material = Material
         CopyOf = Military Stuff
      Resolution = 4
      Depth = 0
   DeepCheck = 0
   JointStrength = 50
   JointStiffness = 0.6
   JointOffset = Vector
      X = 0
      Y = 0
   DrawAfterParent = 1

Author:  CaveCricket48 [ Mon Jan 23, 2012 9:10 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

Are you using tabs or spaces for your spacing?

Author:  Zaggy1024 [ Mon Jan 23, 2012 9:11 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

Tabs. I got the attachable bit of the INI from the wiki which used spaces, though. So that can actually cause an error?

Edit: Okay, it's working (it was because of the spaces, INIs are weird =P)... Now I need to know how to find the attachable from the script in the HDFirearm...

Author:  CaveCricket48 [ Mon Jan 23, 2012 9:25 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

Loop through all MOs, find one that has the PresetName of the attachable and has the same RootID as the HDFirearm.

Author:  Zaggy1024 [ Mon Jan 23, 2012 9:55 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

Something like this?

Code:
function Create(self)
   self.TopMO = nil

   for i = 1, MovableMan:GetMOIDCount() - 1 do
      object = MovableMan:GetMOFromID(i);

      if object.InstanceName == "M249 Top" and self.TopMO.RootID == self.ID then
         print('found!')
         self.TopMO = object
      end
   end
end


Currently this doesn't find anything (even with the RootID check not in there).

Author:  CaveCricket48 [ Mon Jan 23, 2012 10:42 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

print should be
Code:
print("found!");

It's probably what's stopping your code from working.

Author:  Zaggy1024 [ Mon Jan 23, 2012 10:58 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

No, both ways work fine for printing in the console and in the code...

I tried making it print all the InstanceNames it found, and all of them were nil, so I assume that means there is no property called InstanceName that the Lua can access. Am I right?

Author:  Asklar [ Mon Jan 23, 2012 11:32 pm ]
Post subject:  Re: Changing self.Frame for an HDfirearm

Wasn't InstanceName a temporal property that can't be read for future references?
You should pick PresetName.

Author:  Zaggy1024 [ Tue Jan 24, 2012 12:24 am ]
Post subject:  Re: Changing self.Frame for an HDfirearm

Changed it to PresetName (yes, in both the INI and the script), and it's still saying it's nil.

Code:
function Create(self)
   self.TopMO = nil

   for i = 1, MovableMan:GetMOIDCount() - 1 do
      object = MovableMan:GetMOFromID(i);

      if object.PresetName == "M249 Top" then-- and self.TopMO.RootID == self.ID
         print("found!");
         self.TopMO = object;
      end
   end
end


Are you guys sure you can actually access an MO's name from Lua?

Author:  CaveCricket48 [ Tue Jan 24, 2012 12:33 am ]
Post subject:  Re: Changing self.Frame for an HDfirearm

Yes. I'm actually working on a mod that stores data in a magazine's PresetName, and it works fine.

Page 1 of 2 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/