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



Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
 Lua on shield help? 
Author Message
User avatar

Joined: Mon Apr 13, 2009 12:27 pm
Posts: 813
Location: Yogyakarta, Indonesia. A slice o' paradise.
Reply with quote
Post 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.


Sat Oct 22, 2011 5:53 pm
Profile YIM WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Lua on shield help?
This script is directly attached to the shield, yes?

Edit: Goddamn ninja.


Last edited by CaveCricket48 on Sat Oct 22, 2011 6:00 pm, edited 1 time in total.



Sat Oct 22, 2011 5:59 pm
Profile
User avatar

Joined: Mon Apr 13, 2009 12:27 pm
Posts: 813
Location: Yogyakarta, Indonesia. A slice o' paradise.
Reply with quote
Post Re: Lua on shield help?
CaveCricket48 wrote:
This script is directly attached to the shield, yes?

Yep.


Sat Oct 22, 2011 5:59 pm
Profile YIM WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Lua on shield help?
Alright, Non's script should work then.


Sat Oct 22, 2011 6:00 pm
Profile
User avatar

Joined: Mon Apr 13, 2009 12:27 pm
Posts: 813
Location: Yogyakarta, Indonesia. A slice o' paradise.
Reply with quote
Post 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?


Sat Oct 22, 2011 6:18 pm
Profile YIM WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Last edited by CaveCricket48 on Sat Oct 22, 2011 10:47 pm, edited 1 time in total.



Sat Oct 22, 2011 6:30 pm
Profile

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post 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.


Sat Oct 22, 2011 9:36 pm
Profile
User avatar

Joined: Mon Apr 13, 2009 12:27 pm
Posts: 813
Location: Yogyakarta, Indonesia. A slice o' paradise.
Reply with quote
Post 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?


Sun Oct 23, 2011 5:55 am
Profile YIM 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: 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.


Sun Oct 23, 2011 7:15 am
Profile WWW
User avatar

Joined: Mon Apr 13, 2009 12:27 pm
Posts: 813
Location: Yogyakarta, Indonesia. A slice o' paradise.
Reply with quote
Post 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?


Sun Oct 23, 2011 8:03 am
Profile YIM WWW

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post 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


Sun Oct 23, 2011 9:36 am
Profile
User avatar

Joined: Mon Apr 13, 2009 12:27 pm
Posts: 813
Location: Yogyakarta, Indonesia. A slice o' paradise.
Reply with quote
Post 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!


Sun Oct 23, 2011 9:50 am
Profile YIM 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: 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.


Sun Oct 23, 2011 7:50 pm
Profile WWW
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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.
Well, if you want to be technical, referencing most variables in LUA involves tables. Also, that took a while to figure out :P


Mon Nov 07, 2011 7:27 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: 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.


Mon Nov 07, 2011 6:51 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 17 posts ]  Go to page 1, 2  Next

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.062s | 15 Queries | GZIP : Off ]