Author |
Message |
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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 |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
Re: Attaching using lua
Trying to attach an ACrab to an ACDropShip. >___>' Go or No Go?
|
Wed Jul 22, 2009 11:13 pm |
|
|
Foa
Data Realms Elite
Joined: Wed Sep 05, 2007 4:14 am Posts: 3966 Location: Canadida
|
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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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 |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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 |
|
|
LowestFormOfWit
Joined: Mon Oct 06, 2008 2:04 am Posts: 1559
|
Re: Attaching using lua
Piipu's Lua guns also has stuff you can look at.
|
Thu Jul 23, 2009 2:54 am |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
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 |
|
|
BlackNecro
Joined: Sat Dec 02, 2006 12:41 am Posts: 27 Location: Germany
|
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 |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
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 |
|
|
Roon3
Joined: Sun May 11, 2008 12:50 pm Posts: 899
|
Re: Attaching using lua
Are you attaching a turret to the new A-4 or something?
|
Thu Jul 23, 2009 2:48 pm |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
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. 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 |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
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 |
|
|
MaximDude
Joined: Wed Nov 22, 2006 3:19 pm Posts: 2073
|
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. 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 |
|
|
|