Author |
Message |
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
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 |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Changing attachable frames via .Lua
Yep, you can definitely change a head frame with Lua.
|
Wed Aug 25, 2010 10:01 pm |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Changing attachable frames via .Lua
Maybe try doing ToAttachable on self.Head?
|
Thu Aug 26, 2010 12:12 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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 |
|
|
Areku
Joined: Fri Oct 17, 2008 9:46 pm Posts: 5212 Location: The Grills Locker.
|
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 |
|
|
|