Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGrobbe committed Oct 18, 2017
1 parent 37fae55 commit 42280b4
Show file tree
Hide file tree
Showing 3 changed files with 239 additions and 0 deletions.
9 changes: 9 additions & 0 deletions vSync/__resource.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'

client_scripts {
'vs_client.lua',
}

server_scripts {
'vs_server.lua',
}
52 changes: 52 additions & 0 deletions vSync/vs_client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
CurrentWeather = 'EXTRASUNNY'
Time = {}
Time.h = 12
Time.m = 0


RegisterNetEvent('updateWeather')
AddEventHandler('updateWeather', function(NewWeather)
CurrentWeather = NewWeather
end)

Citizen.CreateThread(function()
while true do
Citizen.Wait(100) -- Wait 0 seconds to prevent crashing.
ClearWeatherTypePersist()
SetWeatherTypeNowPersist(CurrentWeather)
SetWeatherTypeNow(CurrentWeather)
SetWeatherTypePersist(CurrentWeather)
if CurrentWeather == 'XMAS' then
SetForceVehicleTrails(true)
SetForcePedFootstepsTracks(true)
else
SetForceVehicleTrails(false)
SetForcePedFootstepsTracks(false)
end
end
end)

RegisterNetEvent('updateTime')
AddEventHandler('updateTime', function(hours, minutes)
Time.h = hours
Time.m = minutes
end)

Citizen.CreateThread(function()
while true do
Citizen.Wait(2000)
NetworkOverrideClockTime(Time.h, Time.m, 0)
Time.m = Time.m + 1
if Time.m > 59 then
Time.m = 0
Time.h = Time.h + 1
if Time.h > 23 then
Time.h = 0
end
end
end
end)

AddEventHandler('playerSpawned', function()
TriggerServerEvent('requestSync')
end)
178 changes: 178 additions & 0 deletions vSync/vs_server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
------------------ change this -------------------

admins = {
'steam:110000105959047',
--'license:1234975143578921327',
}

--------------------------------------------------


















-------------------- DON'T CHANGE THIS --------------------
AvailableWeatherTypes = {
'EXTRASUNNY',
'CLEAR',
'NEUTRAL',
'SMOG',
'FOGGY',
'OVERCAST',
'CLOUDS',
'CLEARING',
'RAIN',
'THUNDER',
'SNOW',
'BLIZZARD',
'SNOWLIGHT',
'XMAS',
'HALLOWEEN',
}
CurrentWeather = "EXTRASUNNY"
Time = {}
Time.h = 12
Time.m = 0



RegisterServerEvent('requestSync')
AddEventHandler('requestSync', function()
TriggerClientEvent('updateWeather', -1, CurrentWeather)
TriggerClientEvent('updateTime', -1, Time.h, Time.m)
end)

RegisterCommand('weather', function(source, args, rawCommand)
if source == 0 then
print("You can't use this command from the console!")
return
else
if isAllowedToChange(source) then
local validWeatherType = false
if args[1] == nil then
TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1Invalid syntax.')
else
for i,wtype in ipairs(AvailableWeatherTypes) do
if wtype == string.upper(args[1]) then
validWeatherType = true
end
end
if validWeatherType then
TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^3Weather has been upated.')
CurrentWeather = string.upper(args[1])
TriggerEvent('requestSync')
else
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 ')
end
end
else
TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1You do not have access to that command.')
print('Access for command /weather denied.')
end
end
end, false)


RegisterCommand('morning', function(source)
local ps = source
if isAllowedToChange(ps) then
Time.h = 9
Time.m = 0
TriggerEvent('requestSync')
end
end)
RegisterCommand('noon', function(source)
if isAllowedToChange(ps) then
Time.h = 12
Time.m = 0
TriggerEvent('requestSync')
end
end)
RegisterCommand('evening', function(source)
if isAllowedToChange(ps) then
Time.h = 18
Time.m = 0
TriggerEvent('requestSync')
end
end)
RegisterCommand('night', function(source)
if isAllowedToChange(ps) then
Time.h = 23
Time.m = 0
TriggerEvent('requestSync')
end
end)


RegisterCommand('time', function(source, args, rawCommand)
if source == 0 then
print("You can't use this command from the console!")
return
elseif source ~= 0 then
if isAllowedToChange(source) then
if tonumber(args[1]) ~= nil and tonumber(args[2]) ~= nil then
Time.h = tonumber(args[1])
Time.m = tonumber(args[2])
TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^2Time has been updated.')
TriggerEvent('requestSync')
else
TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1Invalid syntax.')
end
else
TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1You do not have access to that command.')
print('Access for command /time denied.')
end
end
end)

function isAllowedToChange(player)
local allowed = false
for i,id in ipairs(admins) do
for x,pid in ipairs(GetPlayerIdentifiers(player)) do
if pid == id then
allowed = true
end
end
end
return allowed
end

Citizen.CreateThread(function()
while true do
Citizen.Wait(2000)
Time.m = Time.m + 1
if Time.m > 59 then
Time.m = 0
Time.h = Time.h + 1
if Time.h > 23 then
Time.h = 0
end
end
end
end)

Citizen.CreateThread(function()
while true do
Citizen.Wait(5000)
TriggerClientEvent('updateTime', -1, Time.h, Time.m)
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(300000)
TriggerClientEvent('updateWeather', -1, CurrentWeather)
end
end)

0 comments on commit 42280b4

Please sign in to comment.