UtilScript

From Legacy Roblox Wiki
Revision as of 20:46, 17 January 2011 by >HotThoth
Jump to navigationJump to search

local DefaultSearchName = "#SEARCH NAME HERE#" local cycleIndex = 0

local searchName = game.Lighting:FindFirstChild("SearchForName") if searchName == nil then searchName = Instance.new("StringValue") searchName.Name = "SearchForName" searchName.Value = DefaultSearchName searchName.Parent = game.Lighting end

local clearScript = game.Lighting:FindFirstChild("ClearUtils") if clearScript == nil then clearScript = Instance.new("BoolValue") clearScript.Name = "ClearUtils" clearScript.Value = false clearScript.Parent = game.Lighting end

local cycleSelected = game.Lighting:FindFirstChild("CycleThroughSelected") if cycleSelected == nil then cycleSelected = Instance.new("BoolValue") cycleSelected.Name = "CycleThroughSelected" cycleSelected.Value = false cycleSelected.Parent = game.Lighting end

local cycleSelectedR = game.Lighting:FindFirstChild("ReverseCycleThroughSelected") if cycleSelectedR == nil then cycleSelectedR = Instance.new("BoolValue") cycleSelectedR.Name = "ReverseCycleThroughSelected" cycleSelectedR.Value = false cycleSelectedR.Parent = game.Lighting end

local printCFrame = game.Lighting:FindFirstChild("PrintCFrame") if printCFrame == nil then printCFrame = Instance.new("BoolValue") printCFrame.Name = "PrintCFrame" printCFrame.Value = false printCFrame.Parent = game.Lighting end


function hasChildren(parentObject) parentObject:GetChildren() end


local debounceSearchName = false local searchFinds = {}

function findName(searchSpace, name) if searchSpace == nil then return end if (searchSpace.Name == name) then pcall(table.insert, searchFinds, searchSpace) --table.insert(searchFinds, searchSpace) -- add to hits else -- stop our search depth-wise at first hit -- recursively search deeper through our search tree if (pcall(hasChildren, searchSpace)) then local searchChildren = searchSpace:GetChildren() --print(#searchChildren) for i = 1, #searchChildren do pcall(findName, searchChildren[i], name) end else end end return end

function onSearchName(property) if debounceSearchName or searchName.Value == DefaultSearchName then return -- cannot search for this string else debounceSearchName = true end print("Searching for " .. searchName.Value) local nameToSearchFor = searchName.Value searchName.Value = DefaultSearchName

local selection = game.Selection:Get() searchFinds = {}

-- default search space is the entire workspace if #selection == 0 then selection = game.Workspace:GetChildren() end

for i = 1, #selection do findName(selection[i], nameToSearchFor) end

game.Selection:Set(searchFinds)

print("Search finished!")

debounceSearchName = false end

function cycleStuff(increment) currSelect = game.Selection:Get() if #currSelect > 1 then -- anytime more than 1 is selected, becomes the new group to cycle through cycleIndex = 0 searchFinds = currSelect end

if #searchFinds == 0 then return end

cycleIndex = cycleIndex + increment

if cycleIndex > #searchFinds then cycleIndex = 1 elseif cycleIndex < 1 then cycleIndex = #searchFinds end

game.Selection:Set({searchFinds[cycleIndex]}) end


function outputCFrame(object) print(object.CFrame) end


function onCycleSelected(property) if cycleSelected.Value == false then return else cycleSelected.Value = false end

cycleStuff(1) end

function onCycleSelectedR(property) if cycleSelectedR.Value == false then return else cycleSelectedR.Value = false end

cycleStuff(-1) end

function onPrintCFrame(property) if printCFrame.Value == false then return else printCFrame.Value = false end

selection = game.Selection:Get() if #selection > 0 then print("/////////////////////////////////////////") end for i = 1, #selection do print(selection[i].Name .. " has CFrame: ") pcall(outputCFrame, selection[i]) print("/////////////////////////////////////////") end end


function onClearScript(property) if clearScript.Value == false then return else clearScript.Value = false end

searchName:remove() cycleSelected:remove() cycleSelectedR:remove() printCFrame:remove() clearScript:remove() end


searchName.Changed:connect(onSearchName) cycleSelected.Changed:connect(onCycleSelected) cycleSelectedR.Changed:connect(onCycleSelectedR) printCFrame.Changed:connect(onPrintCFrame) clearScript.Changed:connect(onClearScript)