Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.22 KB | None | 0 0
  1. --[[// INITIAL SETUP //]]
  2. local scriptInfo = {
  3. Author = 'nforeman',
  4. Name = 'Global Functions',
  5. Description = 'Contains common functions for throughout the game.',
  6. Version = 'v1.0.0',
  7. DateOfCreation = '9/22/17',
  8. DateOfUpdate = '1/12/18',
  9. }
  10.  
  11.  
  12.  
  13. --[[// OTHER VARIABLES //]]
  14. local Colors = require(script.Parent:WaitForChild('Colors'))
  15. local Functions = {}
  16.  
  17.  
  18.  
  19. --[[// OTHER FUNCTIONS //]]
  20. local nameColors =
  21. {
  22. Color3.new(253/255, 41/255, 67/255), -- BrickColor.new("Bright red").Color,
  23. Color3.new(1/255, 162/255, 255/255), -- BrickColor.new("Bright blue").Color,
  24. Color3.new(2/255, 184/255, 87/255), -- BrickColor.new("Earth green").Color,
  25. BrickColor.new("Bright violet").Color,
  26. BrickColor.new("Bright orange").Color,
  27. BrickColor.new("Bright yellow").Color,
  28. BrickColor.new("Light reddish violet").Color,
  29. BrickColor.new("Brick yellow").Color,
  30. }
  31.  
  32. local function getNameValue(pName)
  33. local value = 0
  34. for index = 1, #pName do
  35. local cValue = string.byte(string.sub(pName, index, index))
  36. local reverseIndex = #pName - index + 1
  37. if #pName%2 == 1 then
  38. reverseIndex = reverseIndex - 1
  39. end
  40. if reverseIndex%4 >= 2 then
  41. cValue = -cValue
  42. end
  43. value = value + cValue
  44. end
  45. return value
  46. end
  47.  
  48. local color_offset = 0
  49. function ComputeNameColor(pName)
  50. return nameColors[((getNameValue(pName) + color_offset) % #nameColors) + 1]
  51. end
  52.  
  53. --[[// MODULE FUNCTIONS //]]
  54.  
  55. Functions.PrintLoading = function(scriptName)
  56. return string.format('[%s]: ',scriptName) .. 'Loading ...'
  57. end
  58.  
  59. Functions.PrintLoaded = function(scriptName, Now)
  60. return string.format('[%s]: ',scriptName) .. 'Successfully Loaded (' .. (os.time()-Now) .. ' seconds)'
  61. end
  62.  
  63. Functions.PrintMessage = function(scriptName,message)
  64. return string.format('[%s]: ',scriptName) .. message
  65. end
  66.  
  67. Functions.WarnMessage = function(scriptName,message)
  68. return string.format('[%s]: ',scriptName) .. message
  69. end
  70.  
  71. Functions.GetService = function(serviceName)
  72. local service
  73. local success,result = pcall(function()
  74. service = game:GetService(serviceName)
  75. end)
  76. if success then
  77. return service
  78. else
  79. warn(Functions.WarnMessage(script.Name, result))
  80. return workspace
  81. end
  82. end
  83.  
  84. Functions.GetChildFind = function(parent,childName)
  85. local child
  86. local success,result = pcall(function()
  87. child = parent:FindFirstChild(childName)
  88. end)
  89. if success and child then
  90. return child
  91. else
  92. if result then
  93. warn(Functions.WarnMessage(script.Name, result .. ' Child "' .. childName .. '" not found in "' .. parent.Name .. '"'))
  94. else
  95. warn(Functions.WarnMessage(script.Name, 'Child "' .. childName .. '" not found in "' .. parent.Name .. '"'))
  96. end
  97. return nil
  98. end
  99. end
  100.  
  101. Functions.GetChildWait = function(parent,childName)
  102. local child
  103. local success,result = pcall(function()
  104. child = parent:FindFirstChild(childName)
  105. end)
  106. if success and child then
  107. return child
  108. else
  109. local w_success, w_result = pcall(function()
  110. child = parent:WaitForChild(childName)
  111. end)
  112. if not child then
  113. warn(Functions.WarnMessage(script.Name, result .. ' Child' .. childName .. 'not found in ' .. parent.Name))
  114. return nil
  115. else
  116. return child
  117. end
  118. end
  119. end
  120.  
  121. Functions.GetRoot = function(player, typeOfPerm)
  122. if typeOfPerm then
  123. for i,v in pairs(require(Functions.GetChildWait(script.Parent, 'RootPermissions'))[typeOfPerm]) do
  124. if v == player.UserId then
  125. return true
  126. else
  127. return false
  128. end
  129. end
  130. else
  131. return false
  132. end
  133. return false
  134. end
  135.  
  136. Functions.NewInstance = function(instanceType)
  137. local instance
  138. local success,result = pcall(function()
  139. instance = Instance.new(instanceType)
  140. end)
  141. if success then
  142. return instance
  143. else
  144. warn(Functions.WarnMessage(script.Name, result))
  145. return Instance.new('Folder')
  146. end
  147. end
  148.  
  149. Functions.NewPropertiedInstance = function(instanceType,properties)
  150. local newInstance
  151. local success,result = pcall(function()
  152. newInstance = Instance.new(instanceType)
  153. end)
  154. if success then
  155. for propertyName,propertyValue in pairs(properties) do
  156. local f_success,f_result = pcall(function()
  157. newInstance[propertyName] = propertyValue
  158. end)
  159. if not f_success then
  160. warn(Functions.WarnMessage(script.Name, f_result))
  161. end
  162. end
  163. return newInstance
  164. else
  165. warn(Functions.WarnMessage(script.Name, result))
  166. return Instance.new('Folder')
  167. end
  168. end
  169.  
  170. Functions.GetNameColor = function(speaker)
  171. return ComputeNameColor(speaker.Name)
  172. end
  173.  
  174. Functions.GetColor = function(colorName)
  175. if colorName ~= '' then
  176. local colorToReturn = Colors[colorName]
  177. if colorToReturn then
  178. return colorToReturn
  179. else
  180. return Colors['GREY']
  181. end
  182. return Colors['GREY']
  183. end
  184. return Colors['GREY']
  185. end
  186.  
  187. Functions.GetColor3 = function(colorTable)
  188. if colorTable then
  189. local R,G,B = colorTable['R'],colorTable['G'],colorTable['B']
  190. return Color3.fromRGB(R,G,B)
  191. end
  192. return Color3.fromRGB(170,170,170)
  193. end
  194.  
  195. Functions.CreateRoundedImageButton = function(specialProperties)
  196. local ImageProperties = {
  197. Name = specialProperties['Name'] or 'ImageButton',
  198. BackgroundTransparency = 1,
  199. BorderSizePixel = 0,
  200. Position = specialProperties['Position'] or UDim2.new(0,0,0,0),
  201. Size = specialProperties['Size'] or UDim2.new(1,0,1,0),
  202. Image = 'rbxassetid://870697538',
  203. ImageColor3 = specialProperties['ImageColor3'] or Color3.fromRGB(255,255,255,255),
  204. ScaleType = Enum.ScaleType.Slice,
  205. SliceCenter = Rect.new(8,8,8,8),
  206. Parent = specialProperties['Parent'] or Functions.GetService('ReplicatedStorage'),
  207. ZIndex = specialProperties['ZIndex'] or 1,
  208. Visible = true,
  209. }
  210. return Functions.NewPropertiedInstance('ImageButton',ImageProperties)
  211. end
  212. Functions.CreateShadowedTextLabel = function(specialProperties,positionIndicator)
  213. local Main_LabelProperties = {
  214. Name = specialProperties['Name'] or 'TextLabel',
  215. AnchorPoint = specialProperties['AnchorPoint'] or Vector2.new(0,0),
  216. BackgroundTransparency = 1,
  217. BorderSizePixel = 0,
  218. Position = specialProperties['Position'] or UDim2.new(0,0,0,0),
  219. Size = specialProperties['Size'] or UDim2.new(1,0,1,0),
  220. Text = specialProperties['Text'] or '',
  221. TextColor3 = specialProperties['TextColor3'] or Color3.fromRGB(255,255,255),
  222. Font = specialProperties['Font'] or Enum.Font.SourceSansBold,
  223. TextScaled = specialProperties['TextScaled'] or true,
  224. TextSize = specialProperties['TextSize'] or 14,
  225. TextXAlignment = specialProperties['TextXAlignment'] or Enum.TextXAlignment.Center,
  226. TextYAlignment = specialProperties['TextYAlignment'] or Enum.TextYAlignment.Center,
  227. ZIndex = specialProperties['ZIndex'] or 1,
  228. Parent = specialProperties['Parent'] or Functions.GetService('ReplicatedStorage'),
  229. Visible = true,
  230. }
  231. local MainLabel = Functions.NewPropertiedInstance('TextLabel',Main_LabelProperties)
  232. local ShadowLabel = MainLabel:Clone()
  233. ShadowLabel.Parent = MainLabel
  234. ShadowLabel.Position = UDim2.new(0,positionIndicator,0,positionIndicator)
  235. ShadowLabel.Size = UDim2.new(1,0,1,0)
  236. ShadowLabel.AnchorPoint = Vector2.new(0,0)
  237. local MainLabelTextColor = MainLabel.TextColor3
  238. ShadowLabel.TextColor3 = Color3.fromRGB((MainLabelTextColor.r*255)-75,(MainLabelTextColor.g*255)-75,(MainLabelTextColor.b*255)-75)
  239. ShadowLabel.ZIndex = MainLabel.ZIndex -1
  240. return MainLabel
  241. end
  242.  
  243. return Functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement