View unanswered posts | View active topics It is currently Fri Dec 27, 2024 7:44 am



Reply to topic  [ 6 posts ] 
 Changing attachable frames via .Lua 
Author Message
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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?


Wed Aug 25, 2010 9:52 pm
Profile WWW
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post Re: Changing attachable frames via .Lua
Yep, you can definitely change a head frame with Lua.


Wed Aug 25, 2010 10:01 pm
Profile WWW
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post 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


Wed Aug 25, 2010 11:10 pm
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Changing attachable frames via .Lua
Maybe try doing ToAttachable on self.Head?


Thu Aug 26, 2010 12:12 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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.


Thu Aug 26, 2010 12:15 am
Profile WWW
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Changing attachable frames via .Lua
Yep, both of you guys are right. Works like a charm now, Many thanks.


Thu Aug 26, 2010 12:36 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users


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

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.038s | 13 Queries | GZIP : Off ]