| Author | 
            Message | 
        
        
			| 
				
				 CombatMedic02 
				
				
					 Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CaveCricket48 
				
				
					 Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CombatMedic02 
				
				
					 Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
				 
				 
			 | 
			
				
				  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?   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 | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CaveCricket48 
				
				
					 Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CombatMedic02 
				
				
					 Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
				 
				 
			 | 
			
				
				  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.   Any other ideas?  
					
  
			 | 
		
		
			| Sat Sep 12, 2009 6:41 pm | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CaveCricket48 
				
				
					 Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 Mind 
				
				
					 Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CaveCricket48 
				
				
					 Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CombatMedic02 
				
				
					 Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CrazyMLC 
				
				
					 Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CombatMedic02 
				
				
					 Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
				 
				 
			 | 
			
				
				  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...  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 | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CrazyMLC 
				
				
					 Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CombatMedic02 
				
				
					 Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 Grif 
				REAL AMERICAN HERO 
				
					 Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
				 
				 
			 | 
			
				
				  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 | 
			
				
					 
					
					 
				  
			 | 
    	
		
	
	
		  | 
	
	
			| 
				
				 CombatMedic02 
				
				
					 Joined: Wed Dec 17, 2008 11:35 am Posts: 122 Location: London
				 
				 
			 | 
			
				
				  Re: Requesting Team Lua Script for Deployable Turret  
					
						Nope, still not working, same error. Grif ish right...   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 | 
			
				
					 
					
					 
				    
			 | 
    	
		
	
	
		  | 
	
	
	
		 |