generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Turrets need to fire at the opponents

Previous Thread :: Next Thread 
powerblade is not online. powerblade
Joined: 14 Sep 2008
Total Posts: 6950
15 Jun 2012 05:59 PM
I have some heavily modified eye turrets that I can edit almost any way I want, no problem, except for a certain problem. They fire at the nearest possible person, despite who it is.

What lines will I need to add so that it will not fire at a certain team? I'm no big scripter, but this sounds simple enough. What do I need and where do I put it?

Here is a model for an example: http://www.roblox.com/Mr-Blue-item?id=78297373

Thank you.
Report Abuse
killjoy37 is not online. killjoy37
Joined: 27 Aug 2008
Total Posts: 2821
15 Jun 2012 06:14 PM
So does it fire at a specific team, or do you want it to?
Report Abuse
powerblade is not online. powerblade
Joined: 14 Sep 2008
Total Posts: 6950
15 Jun 2012 06:42 PM
I want it to, yes, fire at a specific team. Thank you.

If possible, make a version where it will fire at all except one team.
Report Abuse
GreenDay987Alt is not online. GreenDay987Alt
Joined: 01 Apr 2012
Total Posts: 246
15 Jun 2012 06:49 PM
if TeamColor = "Bright blue" then
script here
else
script here


Maybe...?






~Leave me in the city with 50 bucks and watch me come back a millionaire~
Report Abuse
GreenDay987Alt is not online. GreenDay987Alt
Joined: 01 Apr 2012
Total Posts: 246
15 Jun 2012 06:50 PM
Oops, typo.

if TeamColor == "Bright blue" then
blah
else
blah

Maybe?





~Leave me in the city with 50 bucks and watch me come back a millionaire~
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
15 Jun 2012 06:51 PM
if Player.TeamColor ~= BrickColor.new("Bright blue") then
--Code

† KMXD †
Report Abuse
powerblade is not online. powerblade
Joined: 14 Sep 2008
Total Posts: 6950
15 Jun 2012 07:45 PM
...

That tells me nothing. >.>
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
15 Jun 2012 08:42 PM
@power

Find the line of code where it targets the player and make sure that it checks its team color before firing. If the team color is the color that shouldn't be shot at, then it should ignore it.


if Player.TeamColor ~= BrickColor.new("Bright blue") then

Report Abuse
powerblade is not online. powerblade
Joined: 14 Sep 2008
Total Posts: 6950
15 Jun 2012 08:57 PM
Ah. Thank you.
Report Abuse
powerblade is not online. powerblade
Joined: 14 Sep 2008
Total Posts: 6950
15 Jun 2012 09:06 PM
I'm going to sound like a total idiot about scripting, which of course I am.
---------------------------------------------------------------------------------

function findTorso(pos)
local torso = nil
local dist = 75
local child = workspace:children()
for i=1, #child do
if child[i].className == "Model" then
local h = child[i]:findFirstChild("Humanoid")
if h ~= nil then
local check = child[i]:findFirstChild("Torso")
if check ~= nil then
if (check.Position - pos).magnitude < dist then
torso = check
dist = (check.Position - pos).magnitude
end
end
end
end
end
return torso
end

while true do
wait()
local torso = findTorso(script.Parent.Position)
if torso ~= nil then
script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position)
end
end

--------------------------------------------------------
Where does that line go in there?
Also, there are two scripts. Here is the other one. Please explain to me where it goes in both.
--------------------------------------------------------

function findTorso(pos)
local torso = nil
local dist = 75
local child = workspace:children()
for i=1, #child do
if child[i].className == "Model" then
local h = child[i]:findFirstChild("Humanoid")
if h ~= nil then
local check = child[i]:findFirstChild("Torso")
if check ~= nil then
if (check.Position - pos).magnitude < dist then
torso = check
dist = (check.Position - pos).magnitude
end
end
end
end
end
return torso
end

function fire(pos)
local ball = Instance.new("Part")
ball.Shape = "Ball"
ball.formFactor = "Symmetric"
ball.Size = Vector3.new(3,3,3)
ball.BrickColor = BrickColor.new("Bright blue")
ball.Transparency = 0.5
ball.TopSurface = 0
ball.BottomSurface = 0
ball.Locked = true
ball.Name = "Eye Drop!"
ball.CFrame = CFrame.new(script.Parent.CFrame * Vector3.new(0,0,-6), pos)

local velocity = Instance.new("BodyVelocity")
velocity.velocity = (script.Parent.CFrame.lookVector) * 20
velocity.Parent = ball

local newscript = script.BallScript:clone()
newscript.Disabled = false
newscript.Parent = ball

ball.Parent = workspace
end

while true do
wait(math.random(3,7))
local torso = findTorso(script.Parent.Position)
if torso ~= nil then
fire(torso.Position)
end
end

-----------------------------------------------
Report Abuse
powerblade is not online. powerblade
Joined: 14 Sep 2008
Total Posts: 6950
15 Jun 2012 11:37 PM
Bump.
Report Abuse
powerblade is not online. powerblade
Joined: 14 Sep 2008
Total Posts: 6950
16 Jun 2012 12:49 AM
Bump once again...
Report Abuse
powerblade is not online. powerblade
Joined: 14 Sep 2008
Total Posts: 6950
17 Jun 2012 03:22 AM
Bump yet again.
Report Abuse
thecaptain97 is not online. thecaptain97
Joined: 17 Jun 2010
Total Posts: 4987
17 Jun 2012 03:38 AM
This is a big Script for something so Simple.
Report Abuse
powerblade is not online. powerblade
Joined: 14 Sep 2008
Total Posts: 6950
17 Jun 2012 05:15 AM
@Thecaptain

It's old and the original model isn't mine. Can you make a better script if possible please? Something editable?
Report Abuse
DarkStrike3 is not online. DarkStrike3
Joined: 03 Feb 2012
Total Posts: 1263
17 Jun 2012 11:35 AM
use 'if' and 'elseif' in the script.

Also from what you sound like, you want someone to go into the model itself and ADD it, do me a favor, TRY making it work, then come back, don't come back, want this, but not do anything.
Report Abuse
BJCarpenter is online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
17 Jun 2012 12:24 PM
the find torso may be a good place to check team. I will try to help, But u will have to do it...

function findTorso(pos) -- pos is Origin
local torso = nil
local dist = 75 -- Range
local child = workspace:children() -- a list of all Parts in Workspace
for i=1, #child do
if child[i].className == "Model" then -- Is it a model?

local h = child[i]:findFirstChild("Humanoid")
if h ~= nil then -- Is it a humanoid?

local check = child[i]:findFirstChild("Torso")
if check ~= nil then -- Does it have a torso?

if (check.Position - pos).magnitude < dist then -- Is it closer than Range, or the last torso we found?

-- Here may be a good place to ask your question...


torso = check -- This torso counts as a possible target.

dist = (check.Position - pos).magnitude
end -- closer?
end -- intact?
end -- human?
end -- model?
end -- For loop
return torso
end -- fuction

while true do
wait()
local torso = findTorso(script.Parent.Position)
if torso ~= nil then
script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position)
end
end


Good luck
Brian
Report Abuse
policechiefronaldo is not online. policechiefronaldo
Joined: 01 May 2010
Total Posts: 2789
17 Jun 2012 12:35 PM
function findTorso(pos)
local torso = nil
local dist = 75
local child = workspace:children()
for i=1, #child do
if child[i].className == "Model" then
local h = child[i]:findFirstChild("Humanoid")
if h ~= nil then
local check = child[i]:findFirstChild("Torso")
if check ~= nil then
if (check.Position - pos).magnitude < dist then
torso = check
dist = (check.Position - pos).magnitude
end
end
end
end
end
return torso
end

while true do
wait()
local torso = findTorso(script.Parent.Position)
if torso ~= nil then
script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position)
end
end
Report Abuse
BJCarpenter is online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
17 Jun 2012 12:41 PM
while true do
wait() -- This doesn't look good! You don't want to be polling every Part in the Workplace constanly! for targets. Try Wait(.3) - wait(1)
local torso = findTorso(script.Parent.Position)
if torso ~= nil then
script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position)
end
end



local child = workspace:children() -- Yes, this is old. This will still work, but search on "GetChildren" in the Wiki for the new version, or one day it WILL break.

http://wiki.roblox.com/index.php/Function_Dump/Mathematical_Functions
Report Abuse
thecaptain97 is not online. thecaptain97
Joined: 17 Jun 2010
Total Posts: 4987
17 Jun 2012 12:41 PM
Distance = 75
Owner = "BrickTheBlock"
function scanGame()
Bricks = game.Workspace:GetChildren()
for i=1,#Bricks do
if Bricks[i]:IsA("Model") and Bricks[i]:findFirstChild("Humanoid") then
if Bricks[i].Humanoid.Health >= 1 and game.Players[Bricks[i].Name].TeamColor == BrickColor.new("Bright blue") then
if game.Players[Bricks[i].Name].Name ~= Owner then
if (Bricks[i].Torso.Position - script.Parent.Position).magnitude < Distance then
Torso = Bricks[i].Torso
Aim = (Torso.Position - script.Parent.Position).unit
Pos = script.Parent.Position
PosCal = Pos + (Aim * 1)
script.Parent.BodyGyro.cframe = CFrame.new(Pos, Pos + Aim)
Bullet = Instance.new("Part")
Bullet.Velocity = Aim * 595
Bullet.Size = Vector3.new(.5,.5,.5)
Bullet.Parent = game.Workspace
Bullet.Position = script.Parent.Parent.Barrel.Position
Bullet.Shape = 0
Bullet.BrickColor = BrickColor.new("Bright yellow")
Force = Instance.new("BodyForce")
Force.force = Vector3.new(0,100,0)
Force.Parent = Bullet
mesh = script.Parent.Parent.Mesh:Clone()
mesh.Parent = Bullet
game:GetService("Debris"):AddItem(Bullet, 5)
BScript = script.Parent.Bullet:Clone()
BScript.Disabled = false
BScript.Parent = Bullet
end
end
end
end
end
end

Fired = 0
while wait(.5) do
scanGame()
end
Report Abuse
BJCarpenter is online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
17 Jun 2012 12:55 PM
(This is programming on the fly, so it WILL have errosr)

You may want something more like this:

while true do
wait(1) -- This doesn't look good! You don't want to be polling every Part in the Workplace constanly! for targets. Try Wait(.3) - wait(1)

local Origin =script.Parent.Position
local torso = findTorso(Origin)

while torso ~= nil then -- still alive?

if (torso.Position - Origin).magnitude < 76 then
script.Parent.CFrame = CFrame.new(Origin, torso.Position) -- aim
else
torso = nil -- he has wandered-off; consider him dead.
end -- if Player has wandered-off?

end -- while target is aliv,e track target
end -- while - find new target

Report Abuse
BJCarpenter is online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
17 Jun 2012 12:57 PM
Sorry, forgot the wait.



if (torso.Position - Origin).magnitude < 76 then
script.Parent.CFrame = CFrame.new(Origin, torso.Position) -- aim
wait(.1) -- Sorry, forgot the wait.
else
torso = nil -- he has wandered-off; consider him dead.
end -- if Player has wandered-off?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image