Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Simplest full scan of an object's hierarchy
- function scan(x) if true then end for _,v in pairs(x:GetChildren()) do scan(v) end end
- scan(workspace) --anything
- --Linear sort
- function sort(tab)
- local sorted = {}
- for _,a in pairs(tab) do
- local index = #sorted+1
- for i,b in pairs(sorted) do
- if a < b then
- index = i
- break
- end
- end
- table.insert(sorted,index,a)
- end
- return sorted
- end
- --Random float, self explanatory
- function randFloat(min,max)
- min, max = min or 1, max or 0
- return min + math.random()*(max-min)
- end
- --Rounding
- function round(num,place)
- if place then
- return math.floor(num * 10^place + .5) / 10^place
- else
- return math.floor(num+.5)
- end
- end
- --Great tostring for tables, so useful. Can stylize however you want actually.
- function printTable(tab,isArray)
- local str = "{"
- if isArray then
- for i=1,#tab do
- str = str .. " " .. tostring(tab[i]) .. ","
- end
- else
- for i,v in pairs(tab) do
- str = str .. " [" .. tostring(i) .. "]: " .. tostring(v) .. ","
- end
- end
- str = str:sub(1,math.max(1,#str-1)) .. " }"
- print(str)
- end
- --Fisher Yates algorithm I got off google
- function shuffle(array)
- local output = { }
- local random = math.random
- for index = 1, #array do
- local offset = index - 1
- local value = array[index]
- local randomIndex = offset*random()
- local flooredIndex = randomIndex - randomIndex%1
- if flooredIndex == offset then
- output[#output + 1] = value
- else
- output[#output + 1] = output[flooredIndex + 1]
- output[flooredIndex + 1] = value
- end
- end
- return output
- end
- --Player from part, good for noobs
- function GetPlayerFromPart(part)
- local char = part.Parent
- if char:FindFirstChild('Humanoid') then
- return game.Players:GetPlayerFromCharacter(char)
- end
- end
- --Very useful to loop through players you know have at least semi loaded characters. can customize
- --team parameter OPTIONAL
- function GetReadyPlayers(team)
- local players = {}
- for _,p in pairs( (team or game.Players):GetPlayers() ) do
- local char = p.Character
- if char and char.PrimaryPart and char:FindFirstChild('HumanoidRootPart') and char:FindFirstChild('Humanoid') and char.Humanoid.Health>0 then
- table.insert(players,p)
- end
- end
- return players
- end
- --Good for any touch function for PvP or any small parts; fights lag
- function areTouching(pos1,pos2,dist)
- return (pos2 - pos1).magnitude < (dist or 9)
- end
Add Comment
Please, Sign In to add comment