Data Realms Fan Forums
http://45.55.195.193/

Changing attachable frames via .Lua
http://45.55.195.193/viewtopic.php?f=73&t=19609
Page 1 of 1

Author:  Areku [ Wed Aug 25, 2010 9:52 pm ]
Post subject:  Changing attachable frames via .Lua

I've spent some time recently making a small script to change an actor's head's frame when he is hit, to add some depth to his reactions. Well, I'm using the attachable hack to define a pointer to the actor's head, and when the appropriate conditions are met, change it's frame and print a small confirmation message.

When the actor is hit, everything triggers correctly, and the message comes out, but nothing happens with his head. This has got me thinking: is it even possible to access an attachable's frame via .Lua? If yes, then I'll go recheck my script. Otherwise, I'll just drop this until B24.

Any ideas?

Author:  TheLastBanana [ Wed Aug 25, 2010 10:01 pm ]
Post subject:  Re: Changing attachable frames via .Lua

Yep, you can definitely change a head frame with Lua.

Author:  Areku [ Wed Aug 25, 2010 11:10 pm ]
Post subject:  Re: Changing attachable frames via .Lua

Hmm. I wonder what's wrong, then? Here's the script, just in case you spot something I'm missing: (And the ValidMO check is disabled because I never got it to recognize the head as a proper MO.)

Code:
function Create(self)

   self.Head = nil;
   self.PrevHealth = 100;
   self.IsHeadGood = 0;
   self.IsHeadBad = 0;
   self.timer = Timer();
   self.healthtimer = Timer();
   self.headtimer = Timer();



   for i = 1,MovableMan:GetMOIDCount()-1 do
      self.finder = MovableMan:GetMOFromID(i);
      if self.finder.PresetName == "Skeleton Changer Head" and self.finder.RootID == self.ID then
         self.Head = MovableMan:GetMOFromID(self.finder.ID);
         print(("Found head: ") .. (self.Head.PresetName));
      end
   end

   



   
end



function Update(self)



   if self.timer:IsPastSimMS(50) then
      --if MovableMan:ValidMO(self.Head) then
         if self.Health < self.PrevHealth then
            self.PrevHealth = self.Health;
            self.IsHeadBad = 1;
            self.headtimer:Reset();
         end

         if self.IsHeadBad == 1 then
            if not self.headtimer:IsPastSimMS(3000) then
               print("Head is bad for now!");
               self.Head.Frame = 2;
            else
               self.Head.Frame = 1;
               self.IsHeadBad = 0;
            end
         end
            




      --end
      
      
      if self.healthtimer:IsPastSimMS(500) then
         self.PrevHealth = self.Health;
         self.healthtimer:Reset();
      end


      



      self.timer:Reset();
   end

   --print(self.PrevHealth);





end

Author:  Grif [ Thu Aug 26, 2010 12:12 am ]
Post subject:  Re: Changing attachable frames via .Lua

Maybe try doing ToAttachable on self.Head?

Author:  TheLastBanana [ Thu Aug 26, 2010 12:15 am ]
Post subject:  Re: Changing attachable frames via .Lua

Yeah, you need to do ToMOSRotating, in the least. MovableObject doesn't have a Frame variable, so the lowest class you could use is MOSprite. I don't think you can cast to that, though.

Author:  Areku [ Thu Aug 26, 2010 12:36 am ]
Post subject:  Re: Changing attachable frames via .Lua

Yep, both of you guys are right. Works like a charm now, Many thanks.

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