Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.72 KB | None | 0 0
  1.  
  2. rules = {
  3. label = {},
  4. window = {},
  5. staticimage = {},
  6. edit = {},
  7. gridlist = {},
  8. button = {},
  9. memo = {}
  10. }
  11. addEventHandler("onClientResourceStart", resourceRoot,
  12. function()
  13. local screenW, screenH = guiGetScreenSize()
  14. rules.window[1] = guiCreateWindow((screenW - 695) / 2, (screenH - 625) / 2, 695, 625, "AuroraRPG - Community Rules", false)
  15. guiWindowSetSizable(rules.window[1], false)
  16. guiSetVisible( rules.window[1], false )
  17. guiWindowSetMovable( rules.window[1], false )
  18.  
  19. rules.label[1] = guiCreateLabel(181, 149, 324, 16, "You have been forced to read the rules by : ", false, rules.window[1])
  20. rules.staticimage[1] = guiCreateStaticImage(15, 25, 657, 124, ":AURforceRules/logo.png", false, rules.window[1])
  21. rules.memo[1] = guiCreateMemo(15, 194, 667, 403, "", false, rules.window[1])
  22. rules.label[2] = guiCreateLabel(181, 169, 324, 15, "Time Left :", false, rules.window[1])
  23. rules.label[3] = guiCreateLabel(640, 602, 42, 13, "@Ashford", false, rules.window[1])
  24. guiMemoSetReadOnly( rules.memo[1], true )
  25.  
  26. rules.window[2] = guiCreateWindow((screenW - 425) / 2, (screenH - 529) / 2, 425, 529, "AuroraRPG - Force Rules", false)
  27. guiWindowSetSizable(rules.window[2], false)
  28. guiSetVisible( rules.window[2], false )
  29. guiWindowSetMovable( rules.window[2], false )
  30.  
  31. local rules_file = fileOpen( "rules/en.txt", true )
  32. local rules_content = fileRead( rules_file, 5000 )
  33. guiSetText( rules.memo[1], rules_content )
  34.  
  35.  
  36.  
  37. rules.gridlist[1] = guiCreateGridList(16, 80, 211, 430, false, rules.window[2])
  38. guiGridListAddColumn(rules.gridlist[1], "PlayerName", 0.9)
  39. rules.edit[1] = GuiEdit(16, 53, 211, 22, "Playername...", false, rules.window[2])
  40. rules.label[4] = guiCreateLabel(19, 30, 208, 18, "Search for players...", false, rules.window[2])
  41. rules.edit[2] = GuiEdit(237, 80, 172, 28, "", false, rules.window[2])
  42. rules.label[5] = guiCreateLabel(238, 57, 171, 18, "Duration(Minutes)", false, rules.window[2])
  43. rules.button[1] = GuiButton(238, 118, 172, 26, "Force rules", false, rules.window[2])
  44. rules.button[2] = GuiButton(238, 154, 172, 26, "Unforce rules", false, rules.window[2])
  45. rules.button[3] = GuiButton(237, 484, 172, 26, "Close", false, rules.window[2])
  46.  
  47. for i=1, #rules.label do
  48. if ( i == 3 ) then
  49. guiSetFont( rules.label[i], "default-small" )
  50. else
  51. guiSetFont( rules.label[i], "default-bold-small")
  52. guiLabelSetHorizontalAlign(rules.label[i], "center", false)
  53. guiLabelSetVerticalAlign(rules.label[i], "center")
  54. end
  55. end
  56. end
  57. )
  58.  
  59.  
  60.  
  61.  
  62.  
  63. addEventHandler("onClientGUIChanged", root,
  64. function()
  65. if ( source == rules.edit[1] ) then
  66. guiGridListClear( rules.gridlist[1] )
  67. for _, thePlayer in pairs( Element.getAllByType("player") ) do
  68. if string.find( string.lower( thePlayer.name ), string.lower( guiGetText( rules.edit[1] ) ) ) then
  69. local row = guiGridListAddRow( rules.gridlist[1] )
  70. guiGridListSetItemText( rules.gridlist[1], row, 1, thePlayer.name, false, false )
  71. if ( thePlayer.team ) then
  72. guiGridListSetItemColor( rules.gridlist[1], row, 1, thePlayer.team:getColor() )
  73. else
  74. guiGridListSetItemColor( rules.gridlist[1], row, 1, 255, 0, 0 )
  75. end
  76. end
  77. end
  78. end
  79. end
  80. )
  81.  
  82. addEvent("rules:showGUI", true )
  83. addEventHandler("rules:showGUI", root,
  84. function ()
  85. if ( guiGetVisible( rules.window[2] ) ) then return end
  86. guiSetVisible( rules.window[2], true )
  87. showCursor( true )
  88. reloadList()
  89. end
  90. )
  91.  
  92.  
  93. function reloadList()
  94. guiGridListClear( rules.gridlist[1] )
  95. for _, onlinePlayers in pairs( Element.getAllByType("player") ) do
  96. local row = guiGridListAddRow( rules.gridlist[1] )
  97. guiGridListSetItemText( rules.gridlist[1], row, 1, onlinePlayers.name, false, false )
  98. if ( onlinePlayers.team ) then
  99. guiGridListSetItemColor( rules.gridlist[1], row, 1, onlinePlayers.team:getColor() )
  100. else
  101. guiGridListSetItemColor( rules.gridlist[1], row, 1, 255, 0, 0 )
  102. end
  103. end
  104. end
  105.  
  106. addEventHandler("onClientGUIClick", root,
  107. function()
  108. if ( source == rules.button[1] ) then
  109. forceRules()
  110. elseif ( source == rules.button[2] ) then
  111. unforceRules()
  112. elseif ( source == rules.button[3] ) then
  113. hideGUI()
  114. end
  115. end
  116. )
  117.  
  118.  
  119.  
  120.  
  121.  
  122. function forceRules()
  123. local selectedRow = guiGridListGetSelectedItem( rules.gridlist[1] )
  124. if ( selectedRow == nil or selectedRow == -1 ) then
  125. outputChatBox("You didn't select a player.", 255, 0, 0 )
  126. else
  127. local thePlayer = Player( guiGridListGetItemText( rules.gridlist[1], selectedRow, 1 ) )
  128. local duration = guiGetText( rules.edit[2] )
  129. local theAdmin = localPlayer.name
  130. if not ( duration:match('^%d+$') ) then
  131. outputChatBox("Duration is invalid.", 255, 0, 0 )
  132. elseif ( duration:match("^%s*$") ) then
  133. outputChatBox("Duration field can't be empty.", 255, 0, 0 )
  134. else
  135. triggerServerEvent("rules:forcerules", localPlayer, theAdmin, thePlayer, duration )
  136. end
  137. end
  138. end
  139.  
  140.  
  141.  
  142. function unforceRules()
  143. local selectedRow = guiGridListGetSelectedItem( rules.gridlist[1] )
  144. if ( selectedRow == nil or selectedRow == -1 ) then
  145. outputChatBox("You didn't select a player.", 255, 0, 0 )
  146. else
  147. local thePlayer = Player( guiGridListGetItemText( rules.gridlist[1], selectedRow, 1 ) )
  148. if ( thePlayer ) then
  149. triggerServerEvent("rules:unforcerules", localPlayer, thePlayer )
  150. end
  151. end
  152. end
  153.  
  154.  
  155.  
  156. function hideGUI()
  157. if ( not guiGetVisible( rules.window[2] ) ) then return end
  158. guiSetVisible( rules.window[2], false )
  159. if isCursorShowing() then showCursor( false ) end
  160. end
  161.  
  162. isPlayerReading = false
  163. forceDuration = nil
  164. theStaff = nil
  165.  
  166. addEvent("rules:showrules", true )
  167. addEventHandler("rules:showrules", root,
  168. function( theAdmin, duration )
  169. if ( not isPlayerReading ) then
  170. Timer( checkForce, 1000, 1 )
  171. isPlayerReading = true
  172. forceDuration = ( duration * 60000 ) / 1000
  173. theStaff = theAdmin
  174. else
  175. forceDuration = ( duration * 60000 ) / 1000
  176. theStaff = nil
  177. end
  178. end
  179. )
  180.  
  181.  
  182. function checkForce()
  183. if ( not isPlayerReading or forceDuration <= 0 ) then
  184. triggerServerEvent("rules:unforcerules", localPlayer, localPlayer )
  185. if ( guiGetVisible( rules.window[1] ) ) then
  186. guiSetVisible( rules.window[1], false )
  187. if isCursorShowing() then showCursor( false ) end
  188. end
  189. isPlayerReading = false
  190. else
  191. forceDuration = forceDuration - 1
  192. if ( not guiGetVisible( rules.window[1] ) ) then guiSetVisible( rules.window[1], true ) showCursor( true ) end
  193. guiSetText( rules.label[1], "You have been forced to read the rules by : "..theStaff )
  194. guiSetText( rules.label[2], "Time Left : "..forceDuration.." seconds" )
  195. localPlayer:setData("forceDuration", forceDuration )
  196. Timer( checkForce, 1000, 1 )
  197. end
  198. end
  199.  
  200. addEvent("rules:removeforce", true )
  201. addEventHandler("rules:removeforce", root,
  202. function()
  203. isPlayerReading = false
  204. forceDuration = nil
  205. end
  206. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement