Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[// INITIAL SETUP //]]
- local scriptInfo = {
- Author = 'nforeman',
- Name = 'Global Functions',
- Description = 'Contains common functions for throughout the game.',
- Version = 'v1.0.0',
- DateOfCreation = '9/22/17',
- DateOfUpdate = '1/12/18',
- }
- --[[// OTHER VARIABLES //]]
- local Colors = require(script.Parent:WaitForChild('Colors'))
- local Functions = {}
- --[[// OTHER FUNCTIONS //]]
- local nameColors =
- {
- Color3.new(253/255, 41/255, 67/255), -- BrickColor.new("Bright red").Color,
- Color3.new(1/255, 162/255, 255/255), -- BrickColor.new("Bright blue").Color,
- Color3.new(2/255, 184/255, 87/255), -- BrickColor.new("Earth green").Color,
- BrickColor.new("Bright violet").Color,
- BrickColor.new("Bright orange").Color,
- BrickColor.new("Bright yellow").Color,
- BrickColor.new("Light reddish violet").Color,
- BrickColor.new("Brick yellow").Color,
- }
- local function getNameValue(pName)
- local value = 0
- for index = 1, #pName do
- local cValue = string.byte(string.sub(pName, index, index))
- local reverseIndex = #pName - index + 1
- if #pName%2 == 1 then
- reverseIndex = reverseIndex - 1
- end
- if reverseIndex%4 >= 2 then
- cValue = -cValue
- end
- value = value + cValue
- end
- return value
- end
- local color_offset = 0
- function ComputeNameColor(pName)
- return nameColors[((getNameValue(pName) + color_offset) % #nameColors) + 1]
- end
- --[[// MODULE FUNCTIONS //]]
- Functions.PrintLoading = function(scriptName)
- return string.format('[%s]: ',scriptName) .. 'Loading ...'
- end
- Functions.PrintLoaded = function(scriptName, Now)
- return string.format('[%s]: ',scriptName) .. 'Successfully Loaded (' .. (os.time()-Now) .. ' seconds)'
- end
- Functions.PrintMessage = function(scriptName,message)
- return string.format('[%s]: ',scriptName) .. message
- end
- Functions.WarnMessage = function(scriptName,message)
- return string.format('[%s]: ',scriptName) .. message
- end
- Functions.GetService = function(serviceName)
- local service
- local success,result = pcall(function()
- service = game:GetService(serviceName)
- end)
- if success then
- return service
- else
- warn(Functions.WarnMessage(script.Name, result))
- return workspace
- end
- end
- Functions.GetChildFind = function(parent,childName)
- local child
- local success,result = pcall(function()
- child = parent:FindFirstChild(childName)
- end)
- if success and child then
- return child
- else
- if result then
- warn(Functions.WarnMessage(script.Name, result .. ' Child "' .. childName .. '" not found in "' .. parent.Name .. '"'))
- else
- warn(Functions.WarnMessage(script.Name, 'Child "' .. childName .. '" not found in "' .. parent.Name .. '"'))
- end
- return nil
- end
- end
- Functions.GetChildWait = function(parent,childName)
- local child
- local success,result = pcall(function()
- child = parent:FindFirstChild(childName)
- end)
- if success and child then
- return child
- else
- local w_success, w_result = pcall(function()
- child = parent:WaitForChild(childName)
- end)
- if not child then
- warn(Functions.WarnMessage(script.Name, result .. ' Child' .. childName .. 'not found in ' .. parent.Name))
- return nil
- else
- return child
- end
- end
- end
- Functions.GetRoot = function(player, typeOfPerm)
- if typeOfPerm then
- for i,v in pairs(require(Functions.GetChildWait(script.Parent, 'RootPermissions'))[typeOfPerm]) do
- if v == player.UserId then
- return true
- else
- return false
- end
- end
- else
- return false
- end
- return false
- end
- Functions.NewInstance = function(instanceType)
- local instance
- local success,result = pcall(function()
- instance = Instance.new(instanceType)
- end)
- if success then
- return instance
- else
- warn(Functions.WarnMessage(script.Name, result))
- return Instance.new('Folder')
- end
- end
- Functions.NewPropertiedInstance = function(instanceType,properties)
- local newInstance
- local success,result = pcall(function()
- newInstance = Instance.new(instanceType)
- end)
- if success then
- for propertyName,propertyValue in pairs(properties) do
- local f_success,f_result = pcall(function()
- newInstance[propertyName] = propertyValue
- end)
- if not f_success then
- warn(Functions.WarnMessage(script.Name, f_result))
- end
- end
- return newInstance
- else
- warn(Functions.WarnMessage(script.Name, result))
- return Instance.new('Folder')
- end
- end
- Functions.GetNameColor = function(speaker)
- return ComputeNameColor(speaker.Name)
- end
- Functions.GetColor = function(colorName)
- if colorName ~= '' then
- local colorToReturn = Colors[colorName]
- if colorToReturn then
- return colorToReturn
- else
- return Colors['GREY']
- end
- return Colors['GREY']
- end
- return Colors['GREY']
- end
- Functions.GetColor3 = function(colorTable)
- if colorTable then
- local R,G,B = colorTable['R'],colorTable['G'],colorTable['B']
- return Color3.fromRGB(R,G,B)
- end
- return Color3.fromRGB(170,170,170)
- end
- Functions.CreateRoundedImageButton = function(specialProperties)
- local ImageProperties = {
- Name = specialProperties['Name'] or 'ImageButton',
- BackgroundTransparency = 1,
- BorderSizePixel = 0,
- Position = specialProperties['Position'] or UDim2.new(0,0,0,0),
- Size = specialProperties['Size'] or UDim2.new(1,0,1,0),
- Image = 'rbxassetid://870697538',
- ImageColor3 = specialProperties['ImageColor3'] or Color3.fromRGB(255,255,255,255),
- ScaleType = Enum.ScaleType.Slice,
- SliceCenter = Rect.new(8,8,8,8),
- Parent = specialProperties['Parent'] or Functions.GetService('ReplicatedStorage'),
- ZIndex = specialProperties['ZIndex'] or 1,
- Visible = true,
- }
- return Functions.NewPropertiedInstance('ImageButton',ImageProperties)
- end
- Functions.CreateShadowedTextLabel = function(specialProperties,positionIndicator)
- local Main_LabelProperties = {
- Name = specialProperties['Name'] or 'TextLabel',
- AnchorPoint = specialProperties['AnchorPoint'] or Vector2.new(0,0),
- BackgroundTransparency = 1,
- BorderSizePixel = 0,
- Position = specialProperties['Position'] or UDim2.new(0,0,0,0),
- Size = specialProperties['Size'] or UDim2.new(1,0,1,0),
- Text = specialProperties['Text'] or '',
- TextColor3 = specialProperties['TextColor3'] or Color3.fromRGB(255,255,255),
- Font = specialProperties['Font'] or Enum.Font.SourceSansBold,
- TextScaled = specialProperties['TextScaled'] or true,
- TextSize = specialProperties['TextSize'] or 14,
- TextXAlignment = specialProperties['TextXAlignment'] or Enum.TextXAlignment.Center,
- TextYAlignment = specialProperties['TextYAlignment'] or Enum.TextYAlignment.Center,
- ZIndex = specialProperties['ZIndex'] or 1,
- Parent = specialProperties['Parent'] or Functions.GetService('ReplicatedStorage'),
- Visible = true,
- }
- local MainLabel = Functions.NewPropertiedInstance('TextLabel',Main_LabelProperties)
- local ShadowLabel = MainLabel:Clone()
- ShadowLabel.Parent = MainLabel
- ShadowLabel.Position = UDim2.new(0,positionIndicator,0,positionIndicator)
- ShadowLabel.Size = UDim2.new(1,0,1,0)
- ShadowLabel.AnchorPoint = Vector2.new(0,0)
- local MainLabelTextColor = MainLabel.TextColor3
- ShadowLabel.TextColor3 = Color3.fromRGB((MainLabelTextColor.r*255)-75,(MainLabelTextColor.g*255)-75,(MainLabelTextColor.b*255)-75)
- ShadowLabel.ZIndex = MainLabel.ZIndex -1
- return MainLabel
- end
- return Functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement