View unanswered posts | View active topics It is currently Fri Dec 27, 2024 10:55 pm



Reply to topic  [ 23 posts ]  Go to page 1, 2  Next
 Requesting Team Lua Script for Deployable Turret 
Author Message
User avatar

Joined: Wed Dec 17, 2008 11:35 am
Posts: 122
Location: London
Reply with quote
Post Requesting Team Lua Script for Deployable Turret
Hey guys I need a script for a new weapon that I am planning to add to the weapons pack that I am going to release. I have made a cool hovering pinned turret and I am working on a deployer for it. The problem I have come across is that when the deployer creates a Turret the turret turns on the user and kills them. I'm guessing this is because I don't know how to set the team of it or something? I would also like to make it selectable if possible, that'd be a real bonus.

But yeah it's coming along nicely but it just needs this small script to finish it off.

I'd be super grateful to whoever helps me out. [I really have to stop thinking up weapons I can't script. Unless you guys don't mind? :-(]

Thanks in advance,

CBM02


Fri Sep 11, 2009 1:36 pm
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
It needs to be an actor to be controllable (without andy fancy Lua tricks, anyways.) To set the Team, either put "self.Team = <team#>" or do an area check, and the turret makes the closest actor its team. Like the following:

Code:
   local curdist = 70;
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
         if dist.Magnitude < curdist then
   self.Team = actor.Team;
   end
end


EDIT: Oh, and to keep it from firing on its team:

Code:
   local curdist = 200;
   if self.hastarget == false then
      for actor in MovableMan.Actors do
         local avgx = actor.Pos.X - self.Pos.X;
         local avgy = actor.Pos.Y - self.Pos.Y;
         local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
         if dist < curdist and actor.Team ~= self.Team then
   curdist = dist;
   self.target = actor;
   end
end


Fri Sep 11, 2009 10:35 pm
Profile
User avatar

Joined: Wed Dec 17, 2008 11:35 am
Posts: 122
Location: London
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
So like...

Code:

function Update(self)
   local curdist = 70;
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
         if dist.Magnitude < curdist then
   self.Team = actor.Team;
   end
end

   local curdist = 200;
   if self.hastarget == false then
      for actor in MovableMan.Actors do
         local avgx = actor.Pos.X - self.Pos.X;
         local avgy = actor.Pos.Y - self.Pos.Y;
         local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);
         if dist < curdist and actor.Team ~= self.Team then
   curdist = dist;
   self.target = actor;
   
   end

   end
end


that?

And my turret is a crab...

Code:
AddActor = ACrab
   CopyOf = Dep Turret
   InstanceName = Turret
   ScriptPath = DepTurret.rte/Actors/MiniDepTurret/Red.lua
   Buyable = 0

AddAmmo = Round
   PresetName = Round Turret
   ParticleCount = 1
   Particle = ACrab
      CopyOf = Turret
   Shell = None
   FireVelocity = 2
   Separation = 0

But I can't control it. Is it because I fire it out as a particle? How else could I deploy it? :P

Edit: The Lua isn't working, probably my fault as I'm totally clueless about Lua structure and stuff. I seem to notice if there is a tiny error in a Lua script the whole thing doesn't function.


Sat Sep 12, 2009 1:08 pm
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
Hmm, didn't know your turret was a crab. In that case, you don't need that second chunk of Lua. Just change the first Lua chunk to this:

Code:
   local curdist = 70;
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
         if dist.Magnitude < curdist and actor.ID ~= self.ID then
   self.Team = actor.Team;
   end
end


Change the "local curdist" for the range you want the turret to look for an actor to change its Team to. And all that needs to be in "function Create(self)".


Sat Sep 12, 2009 3:38 pm
Profile
User avatar

Joined: Wed Dec 17, 2008 11:35 am
Posts: 122
Location: London
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
Code:
function Create(self)

   local curdist = 70;
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
         if dist.Magnitude < curdist and actor.ID ~= self.ID then
   self.Team = actor.Team;
   end
end
end


Still refusing to work. :P

Any other ideas?


Sat Sep 12, 2009 6:41 pm
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
Check for ini problems, like the "ScriptPath" line. Other than that, I don't see why it's not working.


Sat Sep 12, 2009 7:08 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
I'm sorry, but I'm confused as to what this is.

Is the turret

a.) Mannable

b.) start with a team

So you want it to not fire on the team of whoever's manning it?

Sorry, read to OP, just not getting it as a whole.


Sat Sep 12, 2009 7:11 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
The turret is an ACrab that can be placed in bunker building phase and deployed from a gun. The problem is the the turret is not on the correct Team when deployed from the gun.


Sat Sep 12, 2009 7:18 pm
Profile
User avatar

Joined: Wed Dec 17, 2008 11:35 am
Posts: 122
Location: London
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
CaveCricket48 wrote:
The turret is an ACrab that can be placed in bunker building phase and deployed from a gun. The problem is the the turret is not on the correct Team when deployed from the gun.

Correct.

I really don't get why it's not working then. I checked the .ini and added it to the crab that gets fired out. Or should I add it to the gun? o.O

Also the turret is killing everything at the moment. It doesn't seem to assign it's self to any team... it's like it's not even using the Lua script. :-(


Sat Sep 12, 2009 8:10 pm
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
When it is fired is it just a ball or is it the turret?
I don't think it will work if it gets fired out any other way than a turret.


Sat Sep 12, 2009 11:25 pm
Profile WWW
User avatar

Joined: Wed Dec 17, 2008 11:35 am
Posts: 122
Location: London
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
It gets fired out as the turret. [ACrab] But it doesn't figure out what team it is on then it kills everyone in the area. It doesn't seem like the Lua script is working but I've checked the .ini and everything seems to be fine. So I'm not sure what's wrong with it... :-(

Uh got this come up...

Image

Code:
function Create(self)

   local curdist = 20;
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
         if dist.Magnitude < curdist and actor.ID ~= self.ID then
   self.Team = actor.Team;
   end
end

end

That is Red.Lua... But the only 0 in there is okay? o.O


Sat Sep 12, 2009 11:44 pm
Profile WWW
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
Code:
function Create(self)
   local curdist = 20
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
      if dist.Magnitude < curdist and actor.ID ~= self.ID then
         self.Team = actor.Team;
      end
   end
end

If I am correct the curdist = 20 isn't in a loop and therefore doesn't need a semi-colon.


Last edited by CrazyMLC on Sun Sep 13, 2009 12:26 am, edited 1 time in total.



Sun Sep 13, 2009 12:20 am
Profile WWW
User avatar

Joined: Wed Dec 17, 2008 11:35 am
Posts: 122
Location: London
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
There wasn't ment to be a ";" there? I wouldn't have known that.

Thanks, lets try that. xP


Sun Sep 13, 2009 12:21 am
Profile WWW
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
That's not the problem, ;'s are basically optional, and just part of correct syntax.


Sun Sep 13, 2009 12:25 am
Profile
User avatar

Joined: Wed Dec 17, 2008 11:35 am
Posts: 122
Location: London
Reply with quote
Post Re: Requesting Team Lua Script for Deployable Turret
Nope, still not working, same error. Grif ish right... :P

Well what other "unexpected symbol" is there... I mean... I looks like any other Lua i've seen... This sucks, if I got it teaming right I could tune it up and relese it. This is the only thing holding me back. :-(


Last edited by CombatMedic02 on Sun Sep 13, 2009 12:33 am, edited 2 times in total.



Sun Sep 13, 2009 12:27 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 23 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.045s | 14 Queries | GZIP : Off ]