-
Notifications
You must be signed in to change notification settings - Fork 51
Add Universal Menu Hooks #5
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,4 @@ | ||
| resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937' | ||
|
|
||
| client_scripts { | ||
| 'vs_client.lua', | ||
| } | ||
|
|
||
| server_scripts { | ||
| 'vs_server.lua', | ||
| } | ||
| client_script 'vs_client.lua' | ||
| server_script 'vs_server.lua' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,3 +91,122 @@ RegisterNetEvent('vSync:notify') | |
| AddEventHandler('vSync:notify', function(message, blink) | ||
| ShowNotification(message, blink) | ||
| end) | ||
|
|
||
| --[[ UNIVERSAL MENU HOOKING STUFF ]]-- | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add a link to where people can get/find info about this universal menu? I don't mind a link there just so people know what it's for 😉 |
||
| local weatherTypes = { | ||
| 'EXTRASUNNY', | ||
| 'CLEAR', | ||
| 'NEUTRAL', | ||
| 'SMOG', | ||
| 'FOGGY', | ||
| 'OVERCAST', | ||
| 'CLOUDS', | ||
| 'CLEARING', | ||
| 'RAIN', | ||
| 'THUNDER', | ||
| 'SNOW', | ||
| 'BLIZZARD', | ||
| 'SNOWLIGHT', | ||
| 'XMAS', | ||
| 'HALLOWEEN', | ||
| } | ||
| local itemBlackout, itemFreezeWeather, itemFreezeTime | ||
|
|
||
| AddEventHandler('menu:setup', function() | ||
| TriggerServerEvent('vSync:canAddMenuItems') | ||
| end) | ||
|
|
||
| RegisterNetEvent('vSync:canAddMenuItems') | ||
| AddEventHandler('vSync:canAddMenuItems', function() | ||
| TriggerEvent('menu:registerModuleMenu', 'vSync', function(id) | ||
| -- Time | ||
| TriggerEvent('menu:addModuleSubMenu', id, "Time", function(id) | ||
| -- Change Time | ||
| TriggerEvent('menu:addModuleSubMenu', id, "Change Time", function(id) | ||
| TriggerEvent('menu:addModuleItem', id, "Morning", nil, false, function(id) TriggerEvent('vSync:time', {9, 0}) end) | ||
| TriggerEvent('menu:addModuleItem', id, "Noon", nil, false, function(id) TriggerEvent('vSync:time', {12, 0}) end) | ||
| TriggerEvent('menu:addModuleItem', id, "Evening", nil, false, function(id) TriggerEvent('vSync:time', {18, 0}) end) | ||
| TriggerEvent('menu:addModuleItem', id, "Night", nil, false, function(id) TriggerEvent('vSync:time', {23, 0}) end) | ||
| end, false) | ||
|
|
||
| -- Freeze Time | ||
| TriggerEvent('menu:addModuleItem', id, "Freeze Time", false, function(id) | ||
| itemFreezeTime = id | ||
| end, function(id) | ||
| TriggerEvent('vSync:freezeTime') | ||
| end) | ||
| end, false) | ||
|
|
||
| -- Weather | ||
| TriggerEvent('menu:addModuleSubMenu', id, "Weather", function(id) | ||
| -- Change Weather | ||
| TriggerEvent('menu:addModuleSubMenu', id, "Change Weather", function(id) | ||
| for _, weatherType in ipairs(weatherTypes) do | ||
| TriggerEvent('menu:addModuleItem', id, weatherType, nil, false, function(id) | ||
| TriggerEvent('vSync:weather', {weatherType}) | ||
| end) | ||
| end | ||
| end, false) | ||
|
|
||
| -- Dynamic Weather | ||
| TriggerEvent('menu:addModuleItem', id, "Dynamic Weather", true, function(id) | ||
| itemFreezeWeather = id | ||
| end, function(id) | ||
| TriggerEvent('vSync:freezeWeather') | ||
| end) | ||
| end, false) | ||
|
|
||
| -- Blackout | ||
| TriggerEvent('menu:addModuleItem', id, "Blackout", false, function(id) | ||
| itemBlackout = id | ||
| end, function(id) | ||
| TriggerEvent('vSync:blackout') | ||
| end) | ||
| end, false) | ||
| end) | ||
|
|
||
| RegisterNetEvent('vSync:time') | ||
| AddEventHandler('vSync:time', function(args) | ||
| TriggerServerEvent('vSync:time', args) | ||
| end) | ||
|
|
||
| RegisterNetEvent('vSync:freezeTime') | ||
| AddEventHandler('vSync:freezeTime', function() | ||
| TriggerServerEvent('vSync:freezeTime') | ||
| end) | ||
|
|
||
| RegisterNetEvent('vSync:itemFreezeTimeSync') | ||
| AddEventHandler('vSync:itemFreezeTimeSync', function(state) | ||
| if itemFreezeTime then | ||
| TriggerEvent('menu:setOnOffState', itemFreezeTime, state) | ||
| end | ||
| end) | ||
|
|
||
| RegisterNetEvent('vSync:weather') | ||
| AddEventHandler('vSync:weather', function(args) | ||
| TriggerServerEvent('vSync:weather', args) | ||
| end) | ||
|
|
||
| RegisterNetEvent('vSync:freezeWeather') | ||
| AddEventHandler('vSync:freezeWeather', function() | ||
| TriggerServerEvent('vSync:freezeWeather') | ||
| end) | ||
|
|
||
| RegisterNetEvent('vSync:itemFreezeWeatherSync') | ||
| AddEventHandler('vSync:itemFreezeWeatherSync', function(state) | ||
| if itemFreezeWeather then | ||
| TriggerEvent('menu:setOnOffState', itemFreezeWeather, state) | ||
| end | ||
| end) | ||
|
|
||
| RegisterNetEvent('vSync:blackout') | ||
| AddEventHandler('vSync:blackout', function() | ||
| TriggerServerEvent('vSync:blackout') | ||
| end) | ||
|
|
||
| RegisterNetEvent('vSync:itemBlackoutSync') | ||
| AddEventHandler('vSync:itemBlackoutSync', function(state) | ||
| if itemBlackout then | ||
| TriggerEvent('menu:setOnOffState', itemBlackout, state) | ||
| end | ||
| end) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,11 @@ function isAllowedToChange(player) | |
| end | ||
|
|
||
| RegisterCommand('freezetime', function(source, args) | ||
| TriggerClientEvent('vSync:freezeTime', source) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you add a unnecessary client event here? Why not just have a function that you call from both the registerCommand, as well as the new event which will check permissions and update time options accordingly? that saves an unnecessary call to the client and back to the server. |
||
| end) | ||
|
|
||
| RegisterServerEvent('vSync:freezeTime') | ||
| AddEventHandler('vSync:freezeTime', function() | ||
| if source ~= 0 then | ||
| if isAllowedToChange(source) then | ||
| freezeTime = not freezeTime | ||
|
|
@@ -71,6 +76,7 @@ RegisterCommand('freezetime', function(source, args) | |
| else | ||
| TriggerClientEvent('vSync:notify', source, 'Time is ~y~no longer frozen~s~.') | ||
| end | ||
| TriggerClientEvent('vSync:itemFreezeTimeSync', -1, freezeTime) | ||
| else | ||
| TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1You are not allowed to use this command.') | ||
| end | ||
|
|
@@ -81,10 +87,16 @@ RegisterCommand('freezetime', function(source, args) | |
| else | ||
| print("Time is no longer frozen.") | ||
| end | ||
| TriggerClientEvent('vSync:itemFreezeTimeSync', -1, freezeTime) | ||
| end | ||
| end) | ||
|
|
||
| RegisterCommand('freezeweather', function(source, args) | ||
| RegisterCommand('freezeweather', function(source) | ||
| TriggerClientEvent('vSync:freezeWeather', source) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, seems like an unnecessary client event to me, unless I'm missing something obvious here. |
||
| end) | ||
|
|
||
| RegisterServerEvent('vSync:freezeWeather') | ||
| AddEventHandler('vSync:freezeWeather', function() | ||
| if source ~= 0 then | ||
| if isAllowedToChange(source) then | ||
| DynamicWeather = not DynamicWeather | ||
|
|
@@ -93,6 +105,7 @@ RegisterCommand('freezeweather', function(source, args) | |
| else | ||
| TriggerClientEvent('vSync:notify', source, 'Dynamic weather changes are now ~b~enabled~s~.') | ||
| end | ||
| TriggerClientEvent('vSync:itemFreezeWeatherSync', -1, DynamicWeather) | ||
| else | ||
| TriggerClientEvent('chatMessage', source, '', {255,255,255}, '^8Error: ^1You are not allowed to use this command.') | ||
| end | ||
|
|
@@ -103,10 +116,16 @@ RegisterCommand('freezeweather', function(source, args) | |
| else | ||
| print("Weather is no longer frozen.") | ||
| end | ||
| TriggerClientEvent('vSync:itemFreezeWeatherSync', -1, DynamicWeather) | ||
| end | ||
| end) | ||
|
|
||
| RegisterCommand('weather', function(source, args) | ||
| TriggerClientEvent('vSync:weather', source, args) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| end, false) | ||
|
|
||
| RegisterServerEvent('vSync:weather') | ||
| AddEventHandler('vSync:weather', function(args) | ||
| if source == 0 then | ||
| local validWeatherType = false | ||
| if args[1] == nil then | ||
|
|
@@ -152,16 +171,22 @@ RegisterCommand('weather', function(source, args) | |
| print('Access for command /weather denied.') | ||
| end | ||
| end | ||
| end, false) | ||
| end) | ||
|
|
||
| RegisterCommand('blackout', function(source) | ||
| TriggerClientEvent('vSync:blackout', source) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And also here |
||
| end) | ||
|
|
||
| RegisterServerEvent('vSync:blackout') | ||
| AddEventHandler('vSync:blackout', function() | ||
| if source == 0 then | ||
| blackout = not blackout | ||
| if blackout then | ||
| print("Blackout is now enabled.") | ||
| else | ||
| print("Blackout is now disabled.") | ||
| end | ||
| TriggerClientEvent('vSync:itemBlackoutSync', -1, blackout) | ||
| else | ||
| if isAllowedToChange(source) then | ||
| blackout = not blackout | ||
|
|
@@ -171,6 +196,7 @@ RegisterCommand('blackout', function(source) | |
| TriggerClientEvent('vSync:notify', source, 'Blackout is now ~r~disabled~s~.') | ||
| end | ||
| TriggerEvent('vSync:requestSync') | ||
| TriggerClientEvent('vSync:itemBlackoutSync', -1, blackout) | ||
| end | ||
| end | ||
| end) | ||
|
|
@@ -233,6 +259,11 @@ function ShiftToHour(hour) | |
| end | ||
|
|
||
| RegisterCommand('time', function(source, args, rawCommand) | ||
| TriggerClientEvent('vSync:time', source, args) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here as well |
||
| end) | ||
|
|
||
| RegisterServerEvent('vSync:time') | ||
| AddEventHandler('vSync:time', function(args) | ||
| if source == 0 then | ||
| if tonumber(args[1]) ~= nil and tonumber(args[2]) ~= nil then | ||
| local argh = tonumber(args[1]) | ||
|
|
@@ -359,3 +390,9 @@ function NextWeatherStage() | |
| end | ||
| end | ||
|
|
||
| RegisterServerEvent('vSync:canAddMenuItems') | ||
| AddEventHandler('vSync:canAddMenuItems', function() | ||
| if isAllowedToChange(source) then | ||
| TriggerClientEvent('vSync:canAddMenuItems', source) | ||
| end | ||
| end) | ||
Uh oh!
There was an error while loading. Please reload this page.