Advertisement
Guest User

vs_server.lua

a guest
Dec 2nd, 2017
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. ------------------ change this -------------------
  2.  
  3. admins = {
  4. 'steam:11000010E6ACC54',
  5. 'steam:110000112AF3A51'
  6. }
  7.  
  8. --------------------------------------------------
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. -------------------- DON'T CHANGE THIS --------------------
  28. AvailableWeatherTypes = {
  29. 'EXTRASUNNY',
  30. 'CLEAR',
  31. 'NEUTRAL',
  32. 'SMOG',
  33. 'FOGGY',
  34. 'OVERCAST',
  35. 'CLOUDS',
  36. 'CLEARING',
  37. 'RAIN',
  38. 'THUNDER',
  39. 'SNOW',
  40. 'BLIZZARD',
  41. 'SNOWLIGHT',
  42. 'XMAS',
  43. 'HALLOWEEN',
  44. }
  45. CurrentWeather = "EXTRASUNNY"
  46. Time = {}
  47. Time.h = 9
  48. Time.m = 0
  49.  
  50.  
  51.  
  52. RegisterServerEvent('requestSync')
  53. AddEventHandler('requestSync', function()
  54. TriggerClientEvent('updateWeather', -1, CurrentWeather)
  55. TriggerClientEvent('updateTime', -1, Time.h, Time.m)
  56. end)
  57.  
  58. RegisterCommand('weather', function(source, args, rawCommand)
  59. if source == 0 then
  60. local validWeatherType = false
  61. if args[1] == nil then
  62. print("Invalid syntax, correct syntax is: /weather <weathertype> ")
  63. return
  64. else
  65. for i,wtype in ipairs(AvailableWeatherTypes) do
  66. if wtype == string.upper(args[1]) then
  67. validWeatherType = true
  68. end
  69. end
  70. if validWeatherType then
  71. print("Weather has been upated.")
  72. CurrentWeather = string.upper(args[1])
  73. TriggerEvent('requestSync')
  74. else
  75. print("Invalid weather type, valid weather types are: \nEXTRASUNNY CLEAR NEUTRAL SMOG FOGGY OVERCAST CLOUDS CLEARING RAIN THUNDER SNOW BLIZZARD SNOWLIGHT XMAS HALLOWEEN ")
  76. end
  77. end
  78. else
  79. if isAllowedToChange(source) then
  80. local validWeatherType = false
  81. if args[1] == nil then
  82. TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1Invalid syntax, use ^0/weather <weatherType> ^1instead!')
  83. else
  84. for i,wtype in ipairs(AvailableWeatherTypes) do
  85. if wtype == string.upper(args[1]) then
  86. validWeatherType = true
  87. end
  88. end
  89. if validWeatherType then
  90. TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^3Weather has been upated, new weather: ' .. string.lower(args[1]))
  91. CurrentWeather = string.upper(args[1])
  92. TriggerEvent('requestSync')
  93. else
  94. TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1Invalid weather type, valid weather types are: ^0\nEXTRASUNNY CLEAR NEUTRAL SMOG FOGGY OVERCAST CLOUDS CLEARING RAIN THUNDER SNOW BLIZZARD SNOWLIGHT XMAS HALLOWEEN ')
  95. end
  96. end
  97. else
  98. TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1You do not have access to that command.')
  99. print('Access for command /weather denied.')
  100. end
  101. end
  102. end, false)
  103.  
  104.  
  105. RegisterCommand('morning', function(source)
  106. if source == 0 then
  107. print("Use the \"/time\" command instead!")
  108. return
  109. end
  110. if isAllowedToChange(source) then
  111. Time.h = 9
  112. Time.m = 0
  113. TriggerClientEvent('chatMessage', source, '', {255,255,255}, 'Time set to morning.')
  114. TriggerEvent('requestSync')
  115. end
  116. end)
  117. RegisterCommand('noon', function(source)
  118. if source == 0 then
  119. print("Use the \"/time\" command instead!")
  120. return
  121. end
  122. if isAllowedToChange(source) then
  123. Time.h = 12
  124. Time.m = 0
  125. TriggerClientEvent('chatMessage', source, '', {255,255,255}, 'Time set to noon.')
  126. TriggerEvent('requestSync')
  127. end
  128. end)
  129. RegisterCommand('evening', function(source)
  130. if source == 0 then
  131. print("Use the \"/time\" command instead!")
  132. return
  133. end
  134. if isAllowedToChange(source) then
  135. Time.h = 18
  136. Time.m = 0
  137. TriggerClientEvent('chatMessage', source, '', {255,255,255}, 'Time set to evening.')
  138. TriggerEvent('requestSync')
  139. end
  140. end)
  141. RegisterCommand('night', function(source)
  142. if source == 0 then
  143. print("Use the \"/time\" command instead!")
  144. return
  145. end
  146. if isAllowedToChange(source) then
  147. Time.h = 23
  148. Time.m = 0
  149. TriggerClientEvent('chatMessage', source, '', {255,255,255}, 'Time set to night.')
  150. TriggerEvent('requestSync')
  151. end
  152. end)
  153.  
  154.  
  155. RegisterCommand('time', function(source, args, rawCommand)
  156. if source == 0 then
  157. if tonumber(args[1]) ~= nil and tonumber(args[2]) ~= nil then
  158. local argh = tonumber(args[1])
  159. local argm = tonumber(args[2])
  160. if argh < 24 then
  161. Time.h = argh
  162. else
  163. Time.h = 0
  164. end
  165. if argm < 60 then
  166. Time.m = argm
  167. else
  168. Time.m = 0
  169. end
  170. -- Time.h = argh
  171. -- Time.m = argm
  172. print("Time has changed to " .. Time.h .. ":" .. Time.m .. ".")
  173. TriggerEvent('requestSync')
  174. else
  175. print("Invalid syntax, correct syntax is: time <hour> <minute> !")
  176. end
  177. elseif source ~= 0 then
  178. if isAllowedToChange(source) then
  179. if tonumber(args[1]) ~= nil and tonumber(args[2]) ~= nil then
  180. local argh = tonumber(args[1])
  181. local argm = tonumber(args[2])
  182. if argh < 24 then
  183. Time.h = argh
  184. else
  185. Time.h = 0
  186. end
  187. if argm < 60 then
  188. Time.m = argm
  189. else
  190. Time.m = 0
  191. end
  192. -- Time.h = argh
  193. -- Time.m = argm
  194. TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^2Time has been updated, new time is: ^0' .. Time.h .. ":" .. Time.m .. "^2!" )
  195. TriggerEvent('requestSync')
  196. else
  197. TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1Invalid syntax. Use ^0/time <hour> <minute> ^1instead!')
  198. end
  199. else
  200. TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1You do not have access to that command.')
  201. print('Access for command /time denied.')
  202. end
  203. end
  204. end)
  205.  
  206. function isAllowedToChange(player)
  207. local allowed = false
  208. for i,id in ipairs(admins) do
  209. for x,pid in ipairs(GetPlayerIdentifiers(player)) do
  210. if pid == id then
  211. allowed = true
  212. end
  213. end
  214. end
  215. return allowed
  216. end
  217.  
  218. Citizen.CreateThread(function()
  219. while true do
  220. Citizen.Wait(2000)
  221. Time.m = Time.m + 1
  222. if Time.m > 59 then
  223. Time.m = 0
  224. Time.h = Time.h + 1
  225. if Time.h > 23 then
  226. Time.h = 0
  227. end
  228. end
  229. end
  230. end)
  231.  
  232. Citizen.CreateThread(function()
  233. while true do
  234. Citizen.Wait(5000)
  235. TriggerClientEvent('updateTime', -1, Time.h, Time.m)
  236. end
  237. end)
  238. Citizen.CreateThread(function()
  239. while true do
  240. Citizen.Wait(300000)
  241. TriggerClientEvent('updateWeather', -1, CurrentWeather)
  242. end
  243. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement