Data Realms Fan Forums http://45.55.195.193/ |
|
Lua on shield help? http://45.55.195.193/viewtopic.php?f=73&t=25946 |
Page 1 of 2 |
Author: | carriontrooper [ Sat Oct 22, 2011 5:53 pm ] |
Post subject: | Lua on shield help? |
So I got this code: Code: function Create(self) for i = 1, MovableMan:GetMOIDCount()-1 do local shield = MovableMan:GetMOFromID(i); if shield.ClassName == "HeldDevice" and shield.PresetName == "Blast Shield" then self.parent = MovableMan:GetMOFromID(shield.RootID); if MovableMan:IsActor(self.parent) then self.parent = ToAHuman(self.parent); end end end --self.walltimer = Timer(); end function CreateBeamWall(self, n) for i = -n, n do self.wall.n = CreateMOPixel("shieldbeam"); self.wall.n.HFlipped = self.HFlipped; if self.HFlipped == true then self.wall.n.Pos = self.Pos + Vector(10,n):RadRotate(self.RotAngle); else self.wall.n.Pos = self.Pos - Vector(10,n):RadRotate(self.RotAngle); end self.wall.n.Vel = self.Vel + Vector(5,n):RadRotate(self.RotAngle); MovableMan:AddParticle(self.wall.n); end end function Update(self) if self.parent.PresetName == "'Anubis'-class Unit" and self.parent.actionphase == 2 then -- if self.Vel == Vector(60,0):RadRotate(self.RotAngle) then self.RotAngle = self.parent.RotAngle; CreateBeamWall(self, 50); end end but it spams errors that self.parent is nil. How do I fix it? How do I find its parent without resorting to distance checks? BTW, it's so that when it's held by an 'Anubis'-class Unit, and the actor activates a Lua 'skill', it emits a blastwave in front of itself. |
Author: | CaveCricket48 [ Sat Oct 22, 2011 5:59 pm ] |
Post subject: | Re: Lua on shield help? |
This script is directly attached to the shield, yes? Edit: Goddamn ninja. |
Author: | carriontrooper [ Sat Oct 22, 2011 5:59 pm ] |
Post subject: | Re: Lua on shield help? |
CaveCricket48 wrote: This script is directly attached to the shield, yes? Yep. |
Author: | CaveCricket48 [ Sat Oct 22, 2011 6:00 pm ] |
Post subject: | Re: Lua on shield help? |
Alright, Non's script should work then. |
Author: | carriontrooper [ Sat Oct 22, 2011 6:18 pm ] |
Post subject: | Re: Lua on shield help? |
Allright, Non's script generates no errors... but the shield wall doesn't appear at all. Here's the new code. Code: --[[function Create(self) for i = 1, MovableMan:GetMOIDCount()-1 do local shield = MovableMan:GetMOFromID(i); if shield.ClassName == "HeldDevice" and shield.PresetName == "Blast Shield" then self.parent = MovableMan:GetMOFromID(shield.RootID); if MovableMan:IsActor(self.parent) then self.parent = ToAHuman(self.parent); end end end --self.walltimer = Timer(); end ]] function CreateBeamWall(self, n) for i = -n, n do self.wall.n = CreateMOPixel("shieldbeam"); self.wall.n.HFlipped = self.HFlipped; if self.HFlipped == true then self.wall.n.Pos = self.Pos + Vector(20,n):RadRotate(self.RotAngle); else self.wall.n.Pos = self.Pos - Vector(20,n):RadRotate(self.RotAngle); end self.wall.n.Vel = self.Vel + Vector(5,n):RadRotate(self.RotAngle); MovableMan:AddParticle(self.wall.n); end end function Update(self) self.actor = MovableMan:GetMOFromID(self.RootID); if MovableMan:IsActor(self.actor) then self.parent = ToActor(self.actor); self.Work = true; else self.Work = false; end if self.Work == true then if self.parent.PresetName == "'Anubis'-class Unit" and self.parent.actionphase == 2 then -- if self.parent.PresetName == "'Anubis'-class Unit" and self.Vel == Vector(60,0):RadRotate(self.RotAngle) then -- if self.Vel == Vector(60,0):RadRotate(self.RotAngle) then self.RotAngle = self.parent.RotAngle; CreateBeamWall(self, 50); end end end Is it the CreateBeamWall that didn't work? should I add ToDelete and ToSettle = false? |
Author: | CaveCricket48 [ Sat Oct 22, 2011 6:30 pm ] |
Post subject: | Re: Lua on shield help? |
I don't think you made your CreateBeamWall function correctly. Functions are (roughly) formatted like: Code: FunctionName(argument1, argument2, [...]) <stuff> return <value> end Edit: Disregard this, I misread the code. |
Author: | zoidberg [ Sat Oct 22, 2011 9:36 pm ] |
Post subject: | Re: Lua on shield help? |
Code: function CreateBeamWall(self, n) for i = -n, n do local wall = CreateMOPixel("shieldbeam") if self.HFlipped then wall.Pos = self.Pos + Vector(20, n):RadRotate(self.RotAngle) else wall.n.Pos = self.Pos - Vector(20, n):RadRotate(self.RotAngle) end wall.Vel = self.Vel + Vector(5, n):RadRotate(self.RotAngle) MovableMan:AddMO(wall) end end this should work. (i don't think that pixels can be hflipped, and that's not the only thing) edit: also, you can't access parent's variables (actionphase, in your case) this way, afaik. store var in sharpness, or anything else, or use kyred's method. |
Author: | carriontrooper [ Sun Oct 23, 2011 5:55 am ] |
Post subject: | Re: Lua on shield help? |
zoidberg wrote: also, you can't access parent's variables (actionphase, in your case) this way, afaik. store var in sharpness, or anything else, or use kyred's method. Hmm, weird, since in another mod-in-development I can successfully 'inherit' a missile's team to its lua-generated splinters, which meant I could 'write' from one lua code into another lua code. But just in case, I wanna know of kyred's method; care to point me in the thread's direction? |
Author: | TheLastBanana [ Sun Oct 23, 2011 7:15 am ] |
Post subject: | Re: Lua on shield help? |
Kyred's method is detailed here. It involves sifting through large tables, so it's not exactly the fastest, but it does let you access variables in other scripted objects. The only variables you can access "normally" are ones defined by the game itself, like Sharpness, HFlipped, Mass, or, as mentioned, Team. |
Author: | carriontrooper [ Sun Oct 23, 2011 8:03 am ] |
Post subject: | Re: Lua on shield help? |
Hmm, thanks... I think I'll make it activate if it goes over a certain speed, but just doing Code: if self.Vel >= Vector(n,0):RadRotate(self.RotAngle) then spams error about vectors. Any way to fix this part? |
Author: | zoidberg [ Sun Oct 23, 2011 9:36 am ] |
Post subject: | Re: Lua on shield help? |
Nonsequitorian wrote: zoidberg wrote: (i don't think that pixels can be hflipped, and that's not the only thing) Why not, Zoidberg? errr... fliping a pixel... it has no front, no back, no rotangle. i can't believe that it could be flipped. carriontrooper wrote: Hmm, thanks... I think I'll make it activate if it goes over a certain speed, but just doing Code: if self.Vel >= Vector(n,0):RadRotate(self.RotAngle) then spams error about vectors. Any way to fix this part? if you put it in update function, then you just haven't "n" defined. and i don't get the point of this check. also, i don't remember correctly, but i think you can't compare vectors like that |
Author: | carriontrooper [ Sun Oct 23, 2011 9:50 am ] |
Post subject: | Re: Lua on shield help? |
Yeah, I got it working now. It will generate loads of awesome when I release it in my SET mod, thanks all! one hint: OOH YEEEAH! |
Author: | TheLastBanana [ Sun Oct 23, 2011 7:50 pm ] |
Post subject: | Re: Lua on shield help? |
No, that's not how it works. Zoidberg is right. Take a look at the Lua documentation for MOSprite. HFlipped and RotAngle are defined as properties of an MOSprite. MOSParticles descend from MOSprite (hence the "MOS" instead of "MO"), meaning they inherit those properties. On the other hand, MOPixels descend directly from MovableObject, meaning that they don't have those properties. You can set those properties, but it stores them in the same way as if you did "self.myVariable = 4" - that is, it won't be accessible by other scripted objects because it's a user-defined property instead of a hardcoded one. |
Author: | Kyred [ Mon Nov 07, 2011 7:27 am ] |
Post subject: | Re: Lua on shield help? |
TheLastBanana wrote: Kyred's method is detailed here. It involves sifting through large tables, so it's not exactly the fastest, but it does let you access variables in other scripted objects. The only variables you can access "normally" are ones defined by the game itself, like Sharpness, HFlipped, Mass, or, as mentioned, Team. |
Author: | TheLastBanana [ Mon Nov 07, 2011 6:51 pm ] |
Post subject: | Re: Lua on shield help? |
Heh, true, although (at least as far as I remember) those tables don't empty themselves, so as the game goes on, it gets slower to look up objects in it. Maybe that was only when PresetMan:ReloadAllScripts is called, though - it's been a while since I've used that technique. |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |