Skip to content

Commit

Permalink
feat: disable menu on convar
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed May 31, 2021
1 parent 2e76c1e commit e13f716
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 38 deletions.
88 changes: 52 additions & 36 deletions scripts/menu/client/cl_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ CreateThread(function()
isMenuDebug = (GetConvar('TXADMIN_MENU_DEBUG', 'false') == 'true')
end)

-- Since the menu yields/receives keyboard
-- focus we need to store that the menu is already visible
local isMenuVisible
-- Last location stored in a vec3
local lastTp

RegisterKeyMapping('txadmin', 'Open the txAdmin Menu', 'keyboard', '')



local isRDR = not TerraingridActivate and true or false
local dismissKey = isRDR and 0xD9D0E1C0 or 22
local dismissKeyGroup = isRDR and 1 or 0


--- Send data to the NUI frame
---@param action string Action
Expand All @@ -30,6 +31,50 @@ function sendMenuMessage(action, data)
})
end

local function openWarningHandler(author, reason)
sendMenuMessage('setWarnOpen', {
reason = reason,
warnedBy = author
})

CreateThread(function()
local countLimit = 100 --10 seconds
local count = 0
while true do
Wait(100)
if IsControlPressed(dismissKeyGroup, dismissKey) then
count = count +1
if count >= countLimit then
sendMenuMessage('closeWarning')
return
elseif math.fmod(count, 10) == 0 then
sendMenuMessage('pulseWarning')
end
else
count = 0
end
end
end)
end

RegisterNetEvent('txAdminClient:warn', openWarningHandler)


--BETA BETA BETA BETA BETA BETA BETA BETA BETA BETA BETA
if (GetConvar('txEnableMenuBeta', 'false') ~= 'true') then
print('txAdmin beta menu disabled.')
return
end


-- Since the menu yields/receives keyboard
-- focus we need to store that the menu is already visible
local isMenuVisible
-- Last location stored in a vec3
local lastTp

RegisterKeyMapping('txadmin', 'Open the txAdmin Menu', 'keyboard', '')

--- Will update ServerCtx based on GlobalState and will send it to NUI
local function updateServerCtx()
local ServerCtx = GlobalState.txAdminServerCtx
Expand Down Expand Up @@ -545,35 +590,6 @@ RegisterNetEvent('txAdmin:menu:spawnVehicle', function(netID)
end
end)

local isRDR = not TerraingridActivate and true or false
local dismissKey = isRDR and 0xD9D0E1C0 or 22
local dismissKeyGroup = isRDR and 1 or 0

local function openWarningHandler(author, reason)
sendMenuMessage('setWarnOpen', {
reason = reason,
warnedBy = author
})

CreateThread(function()
local countLimit = 100 --10 seconds
local count = 0
while true do
Wait(100)
if IsControlPressed(dismissKeyGroup, dismissKey) then
count = count +1
if count >= countLimit then
sendMenuMessage('closeWarning')
return
elseif math.fmod(count, 10) == 0 then
sendMenuMessage('pulseWarning')
end
else
count = 0
end
end
end)
end

CreateThread(function()
while true do
Expand All @@ -584,4 +600,4 @@ CreateThread(function()
end
end)

RegisterNetEvent('txAdminClient:warn', openWarningHandler)

8 changes: 7 additions & 1 deletion scripts/menu/server/sv_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ end
local apiHost = GetConvar("txAdmin-apiHost", "invalid")
local pipeToken = GetConvar("txAdmin-pipeToken", "invalid")
if apiHost == "invalid" or pipeToken == "invalid" then
logError('API Host or Pipe Token ConVars not found. Do not start this resource if not using txAdmin.')
print('API Host or Pipe Token ConVars not found. Do not start this resource if not using txAdmin.')
return
end

Expand All @@ -14,6 +14,12 @@ if (GetConvar('TXADMIN_MENU_DEBUG', 'false') ~= 'true') then
SetConvar("txAdmin-pipeToken", "removed")
end

--BETA BETA BETA BETA BETA BETA BETA BETA BETA BETA BETA
if (GetConvar('txEnableMenuBeta', 'false') ~= 'true') then
print('txAdmin beta menu disabled.')
return
end


-- Vars
local adminPermissions = {}
Expand Down
2 changes: 1 addition & 1 deletion web/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ <h2>Settings</h2>
<input type="text" class="form-control" id="frmFXServer-commandLine" value="{{it.fxserver.commandLine|undef}}"
placeholder="+set sv_enforceGameBuild 2060" {{it.readOnly|isDisabled}}>
<span class="form-text text-primary">
To enable the Beta In-game, add <code>+set txEnableMenuBeta true</code> above.
To enable the Beta In-game, add <code>+setr txEnableMenuBeta true</code> above.
</span>
<span class="form-text text-muted">
Additional command-line arguments to pass to the FXServer instance. <br>
Expand Down

0 comments on commit e13f716

Please sign in to comment.