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



Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
 Attaching using lua 
Author Message
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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.


Wed Jul 22, 2009 9:07 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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.


Wed Jul 22, 2009 11:09 pm
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post Re: Attaching using lua
Trying to attach an ACrab to an ACDropShip. >___>'
Go or No Go?


Wed Jul 22, 2009 11:13 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Wed Sep 05, 2007 4:14 am
Posts: 3966
Location: Canadida
Reply with quote
Post 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.


Wed Jul 22, 2009 11:18 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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?


Wed Jul 22, 2009 11:34 pm
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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. >___>


Wed Jul 22, 2009 11:41 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Wed Jul 22, 2009 11:46 pm
Profile
User avatar

Joined: Mon Oct 06, 2008 2:04 am
Posts: 1559
Reply with quote
Post Re: Attaching using lua
Piipu's Lua guns also has stuff you can look at.


Thu Jul 23, 2009 2:54 am
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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 >____>'


Thu Jul 23, 2009 1:27 pm
Profile

Joined: Sat Dec 02, 2006 12:41 am
Posts: 27
Location: Germany
Reply with quote
Post 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


Thu Jul 23, 2009 1:47 pm
Profile WWW
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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


Thu Jul 23, 2009 2:16 pm
Profile
User avatar

Joined: Sun May 11, 2008 12:50 pm
Posts: 899
Reply with quote
Post Re: Attaching using lua
Are you attaching a turret to the new A-4 or something?


Thu Jul 23, 2009 2:48 pm
Profile WWW
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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


Thu Jul 23, 2009 3:17 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Thu Jul 23, 2009 4:24 pm
Profile
User avatar

Joined: Wed Nov 22, 2006 3:19 pm
Posts: 2073
Reply with quote
Post 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?


Thu Jul 23, 2009 4:37 pm
Profile
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.064s | 15 Queries | GZIP : Off ]