RoScripts
|
  |
| Joined: 27 Oct 2012 |
| Total Posts: 1824 |
|
|
| 29 Oct 2012 08:46 PM |
It currently follows Players and other Zombies too. I've tried editing it, but I can't seem to make it work. Can anyone please help? And yes I took this script from free models.
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 1000 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent.Parent) then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end
while true do wait(0.1) local target = findNearestTorso(script.Parent.Parent.Torso.Position) if target ~= nil then script.Parent.Parent.Humanoid:MoveTo(target.Position, target) end end |
|
|
| Report Abuse |
|
|
gamer961
|
  |
| Joined: 20 Jul 2011 |
| Total Posts: 800 |
|
|
| 29 Oct 2012 08:49 PM |
| Rename Zombie Torsos maybe? |
|
|
| Report Abuse |
|
|
RoScripts
|
  |
| Joined: 27 Oct 2012 |
| Total Posts: 1824 |
|
|
| 29 Oct 2012 08:52 PM |
@Gamer
I tried that. Complete mess. Arms kept falling off, scripts wouldn't work anymore, etc.
I don't want to go back to that again. |
|
|
| Report Abuse |
|
|
1pie23
|
  |
| Joined: 11 Jul 2010 |
| Total Posts: 1865 |
|
|
| 29 Oct 2012 08:54 PM |
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 1000 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent.Parent) then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) and (game.Players:findFirstChild(human.Parent.Name) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end
while true do wait(0.1) local target = findNearestTorso(script.Parent.Parent.Torso.Position) if target ~= nil then script.Parent.Parent.Humanoid:MoveTo(target.Position, target) end end |
|
|
| Report Abuse |
|
|
RoScripts
|
  |
| Joined: 27 Oct 2012 |
| Total Posts: 1824 |
|
| |
|
RoScripts
|
  |
| Joined: 27 Oct 2012 |
| Total Posts: 1824 |
|
| |
|
|
| 29 Oct 2012 09:44 PM |
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 1000 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent.Parent) then if game:findFirstChild("Players") then if game:findFirstChild("Players"):findFirstChild(temp2.Name) then if game:findFirstChild("Players"):findFirstChild(temp2.Name).className == "Player" then temp = temp2:findFirstChild("Torso") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end end end end return torso end
while true do wait(0.1) local target = findNearestTorso(script.Parent.Parent.Torso.Position) if target ~= nil then script.Parent.Parent.Humanoid:MoveTo(target.Position, target) end end |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2012 10:02 PM |
In case those don't work. This is how I've been doing it (but I like the one that checks if TempTarget is Player-Class)
local AI = script.Parent local AIName = AI.Name . . . if (temp2.className == "Model") and (temp2 ~= script.Parent.Parent) and Temp2.Name -= AIName then
|
|
|
| Report Abuse |
|
|
RoScripts
|
  |
| Joined: 27 Oct 2012 |
| Total Posts: 1824 |
|
|
| 29 Oct 2012 10:14 PM |
@FireBlade
I honestly can't thank you enough! I love you! (Literally, lol)
Would you like a copy of the project I'm doing?
@BJ
Thank you for the help, Fire already solved it. |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2012 10:17 PM |
xD No, I just added a few lines of code (your thanks is enough of a payment). Have fun with your game.
Just a fair warning:
You may want to be careful what you name your AIs because things could get messy if you name one of them a player's username (which is one flaw in the solution I showed you). |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2012 10:24 PM |
I see you already have a working solution, but I'd also like to show you how I would do this:
do local Players = Game:GetService("Players") function GetClosestPlayer() local Distance, Player = math.huge for i,v in pairs(Players:GetPlayers()) do local DistanceFromZombie = v:DistanceFromCharacter( script.Parent:GetModelCFrame().p ) if v.Character and DistanceFromZombie < Distance then Distance = DistanceFromZombie Player = v end end return Player end end
This would only have to iterate through the Players rather than every object in the game, thus being more efficient. My version is also shorter and easier on the eyes. ;P |
|
|
| Report Abuse |
|
|
RoScripts
|
  |
| Joined: 27 Oct 2012 |
| Total Posts: 1824 |
|
|
| 29 Oct 2012 10:34 PM |
@Fire
Thanks! Are you sure you don't want a copy?
@Scar
I'll just take a sample of this script just in case I need it. And thanks! |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2012 10:36 PM |
| No, thanks. Like I said before, just have fun with it. |
|
|
| Report Abuse |
|
|
RoScripts
|
  |
| Joined: 27 Oct 2012 |
| Total Posts: 1824 |
|
|
| 29 Oct 2012 10:45 PM |
| Well thank you very much. If you need me (Or any favors) hit me up on my main. I'll message you my main. I don't like people knowing it. |
|
|
| Report Abuse |
|
|
|
| 29 Oct 2012 11:07 PM |
Thanks Scar,
I always wondered why that FindNearest, check EVERYTHING.
I assume that this is tested, in a working Model. I'll replace the FindNeaest in my Speed AI. See if I get any bug reports.
Thanks, Brain
|
|
|
| Report Abuse |
|
|
|
| 29 Oct 2012 11:20 PM |
ScarFacial,
Why don't u check if Player is alive, and if he has a Torso or not?
Is that not nessasary? Brian
|
|
|
| Report Abuse |
|
|
| |
|