Data Realms Fan Forums
http://45.55.195.193/

Attaching using lua
http://45.55.195.193/viewtopic.php?f=73&t=15970
Page 1 of 2

Author:  MaximDude [ Wed Jul 22, 2009 9:07 pm ]
Post subject:  Attaching using lua

How can I attach a certain object to another object (A dropship in this case) using lua?
Some basic code/instructions would be apreciated.

Author:  Grif [ Wed Jul 22, 2009 11:09 pm ]
Post subject:  Re: Attaching using lua

Depends what you mean.

If you mean get one to move with the other, that's one thing.

If you mean actually attach one thing to another, you're SOL.

Author:  MaximDude [ Wed Jul 22, 2009 11:13 pm ]
Post subject:  Re: Attaching using lua

Trying to attach an ACrab to an ACDropShip. >___>'
Go or No Go?

Author:  Foa [ Wed Jul 22, 2009 11:18 pm ]
Post subject:  Re: Attaching using lua

MaximDude wrote:
Trying to attach an ACrab to an ACDropShip. >___>'
Go or No Go?

It is a go, but, I don't know where it is.
Ask mail.

Author:  Grif [ Wed Jul 22, 2009 11:34 pm ]
Post subject:  Re: Attaching using lua

Depends what you mean means SPECIFY.

You can't just be like "self:AttachTo(thatdropshipoverthere)"

do you just want the two things to move with each other?

Author:  MaximDude [ Wed Jul 22, 2009 11:41 pm ]
Post subject:  Re: Attaching using lua

Grif wrote:
Depends what you mean means SPECIFY.

You can't just be like "self:AttachTo(thatdropshipoverthere)"

do you just want the two things to move with each other?


Yes, I want them to move with each other.

Basically, what i'm trying to do is a gunship the easy way.
A turret attached upside down to a dropship, thats it. >___>

Author:  Grif [ Wed Jul 22, 2009 11:46 pm ]
Post subject:  Re: Attaching using lua

function Create(self)
self.turret = CreateACrab("crabname",".rte");
self.turret.Pos = Vector(self.Pos.X,self.Pos.Y + 72);
self.turret.Vel = self.Vel;
MovableMan:AddActor(self.turret);
end

function Update(self)
if MovableMan:IsActor(self.turret) == true then
self.turret.Pos = Vector(self.Pos.X,self.Pos.Y + 72);
self.turret.Vel = self.Vel;
end
end

Author:  LowestFormOfWit [ Thu Jul 23, 2009 2:54 am ]
Post subject:  Re: Attaching using lua

Piipu's Lua guns also has stuff you can look at.

Author:  MaximDude [ Thu Jul 23, 2009 1:27 pm ]
Post subject:  Re: Attaching using lua

Grif wrote:
function Create(self)
self.turret = CreateACrab("crabname",".rte");
self.turret.Pos = Vector(self.Pos.X,self.Pos.Y + 72);
self.turret.Vel = self.Vel;
MovableMan:AddActor(self.turret);
end

function Update(self)
if MovableMan:IsActor(self.turret) == true then
self.turret.Pos = Vector(self.Pos.X,self.Pos.Y + 72);
self.turret.Vel = self.Vel;
end
end


Ok, so that works, but there are some issues.

The turret seems to start spinning around when it is hit, so I gave it a PinStrength, but now it just stays still while moving.

I want it to sway together with the ship body, how can that be done?
- Got this working, though when swaying it still stays pinned at the same spot, but that doesn't bother me.

Oh, and the turret seems to just fall off when the ship is destoryed or returned, how do I make it gib if the ship dies and dissapear when its returned?

I'm starting to understand this whole lua stuff but it is still damn confusing >____>'

Author:  BlackNecro [ Thu Jul 23, 2009 1:47 pm ]
Post subject:  Re: Attaching using lua

For the rotating part do something like.
Code:
self.turret.Pos = self.Pos + Vector(math.cos(self.Angle)*xoffset,math.sin(self.Angle)*yoffset)

Not sure if it works but worth a try.

For the destroying part.
Code:
function Destroy(self)
self.turret:GibThis()
end

Author:  MaximDude [ Thu Jul 23, 2009 2:16 pm ]
Post subject:  Re: Attaching using lua

BlackNecro wrote:
For the rotating part do something like.
Code:
self.turret.Pos = self.Pos + Vector(math.cos(self.RotAngle)*xoffset,math.sin(self.RotAngle)*yoffset)

Not sure if it works but worth a try.


Doesn't really change anything, it still rotates around the spot its attached to.
Doesn't matter though, I can ignore that.

BlackNecro wrote:
For the destroying part.
Code:
function Destroy(self)
self.turret:GibThis()
end


Ok, this works just fine.

Thanks for the help Grif, BlackNecro. :D

Author:  Roon3 [ Thu Jul 23, 2009 2:48 pm ]
Post subject:  Re: Attaching using lua

Are you attaching a turret to the new A-4 or something?

Author:  MaximDude [ Thu Jul 23, 2009 3:17 pm ]
Post subject:  Re: Attaching using lua

Roon3 wrote:
Are you attaching a turret to the new A-4 or something?


Nope.
Its my own little gunship.

Here are a few shots of it.

Image

Image

Works like a charm, it looks funky when upside down though, cause the turret is pinned in one spot and just rotates around it.

My only complaint is that the AI is freakin' stupid, it takes like 2-3 seconds for it so start shooting. >____>'

I'll be releasing it (Along with other stuff) soon :D

Author:  Grif [ Thu Jul 23, 2009 4:24 pm ]
Post subject:  Re: Attaching using lua

I would recommend against using Destroy self code, it has a tendency to cause crashes (that code would crash if the turret gibbed before the dropship):

in update:
if self:IsDead() == true then
if MovableMan:IsActor(self.turret) == true then
self.turret:GibThis();
end
end

Author:  MaximDude [ Thu Jul 23, 2009 4:37 pm ]
Post subject:  Re: Attaching using lua

Grif wrote:
I would recommend against using Destroy self code, it has a tendency to cause crashes (that code would crash if the turret gibbed before the dropship):

in update:
if self:IsDead() == true then
if MovableMan:IsActor(self.turret) == true then
self.turret:GibThis();
end
end


Oh, I see.

Anyway, that works like a charm. When I tried earlier I had some error with IsDead, something with it being overloaded. :???: Probably because I put it without the ''if MovableMan:IsActor(self.turret) == true then'' part. >____>'

Thanks again. :D

Edit:

Oh, just one little issue, it falls down when the ship is returned.
What do I use to check whether it is still attached so I can gib it if its not?

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