Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated AFK #457

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 17 additions & 38 deletions client/afk.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
local QBCore = exports['qb-core']:GetCoreObject()
local isLoggedIn = LocalPlayer.state.isLoggedIn
local checkUser = true
local prevPos, time = nil, nil
local timeMinutes = {
['900'] = 'minutes',
['600'] = 'minutes',
['300'] = 'minutes',
['150'] = 'minutes',
['60'] = 'minutes',
['30'] = 'seconds',
['20'] = 'seconds',
['10'] = 'seconds',
}

local function updatePermissionLevel()
QBCore.Functions.TriggerCallback('qb-afkkick:server:GetPermissions', function(userGroups)
Expand All @@ -34,40 +23,30 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
isLoggedIn = false
end)

RegisterNetEvent('QBCore:Client:OnPermissionUpdate', function()
updatePermissionLevel()
end)

CreateThread(function()
local sleepTimer = 10000
while true do
Wait(10000)
local ped = PlayerPedId()
if isLoggedIn == true or Config.AFK.kickInCharMenu == true then
if checkUser then
local currPos = GetEntityCoords(ped, true)
if prevPos then
if currPos == prevPos then
if time then
if time > 0 then
local _type = timeMinutes[tostring(time)]
if _type == 'minutes' then
QBCore.Functions.Notify(Lang:t('afk.will_kick') .. math.ceil(time / 60) .. Lang:t('afk.time_minutes'), 'error', 10000)
elseif _type == 'seconds' then
QBCore.Functions.Notify(Lang:t('afk.will_kick') .. time .. Lang:t('afk.time_seconds'), 'error', 10000)
end
time -= 10
else
TriggerServerEvent('KickForAFK')
end
if (isLoggedIn or Config.AFK.kickInCharMenu) and checkUser then
while GetTimeSinceLastInput(0) > sleepTimer do
local kickTimer = Config.AFK.minutesUntilKick * 60 * 1000
local timeLeftSec = (kickTimer - GetTimeSinceLastInput(0)) / 1000
for _, warning in pairs(Config.AFK.warnings) do
if not warning.sent and timeLeftSec < warning.timeSec then
if warning.timeSec >= 60 then
QBCore.Functions.Notify(Lang:t('afk.will_kick') .. math.ceil(warning.timeSec / 60) .. Lang:t('afk.time_minutes'), 'error', 15000)
else
time = Config.AFK.secondsUntilKick
QBCore.Functions.Notify(Lang:t('afk.will_kick') .. warning.timeSec .. Lang:t('afk.time_seconds'), 'error', 15000)
end
else
time = Config.AFK.secondsUntilKick
warning.sent = true
end
if GetTimeSinceLastInput(0) > kickTimer then
TriggerServerEvent('KickForAFK')
end
end
prevPos = currPos
Wait(1000)
end
for _, warning in pairs(Config.AFK.warnings) do warning.sent = false end
end
Wait(sleepTimer)
end
end)
10 changes: 8 additions & 2 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ Config.AFK = {
['admin'] = true,
['god'] = true
},
secondsUntilKick = 1000000, -- AFK Kick Time Limit (in seconds)
kickInCharMenu = false -- Set to true if you want to kick players for being AFK even when they are in the character menu.
warnings = {
{timeSec = 300, sent = false}, -- Will send a warning at 300 seconds (5 minutes) remaining on afk timer
{timeSec = 120, sent = false},
{timeSec = 60, sent = false},
{timeSec = 30, sent = false},
},
minutesUntilKick = 120, -- AFK Kick Time Limit (in minutes)
kickInCharMenu = false -- Set to true if you want to kick players for being AFK even when they are in the character menu.
}

Config.HandsUp = {
Expand Down
Loading