11local QBCore = exports [' qb-core' ]:GetCoreObject ()
22local isLoggedIn = LocalPlayer .state .isLoggedIn
33local checkUser = true
4- local prevPos , time = nil , nil
5- local timeMinutes = {
6- [' 900' ] = ' minutes' ,
7- [' 600' ] = ' minutes' ,
8- [' 300' ] = ' minutes' ,
9- [' 150' ] = ' minutes' ,
10- [' 60' ] = ' minutes' ,
11- [' 30' ] = ' seconds' ,
12- [' 20' ] = ' seconds' ,
13- [' 10' ] = ' seconds' ,
14- }
154
165local function updatePermissionLevel ()
176 QBCore .Functions .TriggerCallback (' qb-afkkick:server:GetPermissions' , function (userGroups )
@@ -34,40 +23,30 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
3423 isLoggedIn = false
3524end )
3625
37- RegisterNetEvent (' QBCore:Client:OnPermissionUpdate' , function ()
38- updatePermissionLevel ()
39- end )
40-
4126CreateThread (function ()
27+ local sleepTimer = 10000
4228 while true do
43- Wait (10000 )
44- local ped = PlayerPedId ()
45- if isLoggedIn == true or Config .AFK .kickInCharMenu == true then
46- if checkUser then
47- local currPos = GetEntityCoords (ped , true )
48- if prevPos then
49- if currPos == prevPos then
50- if time then
51- if time > 0 then
52- local _type = timeMinutes [tostring (time )]
53- if _type == ' minutes' then
54- QBCore .Functions .Notify (Lang :t (' afk.will_kick' ) .. math.ceil (time / 60 ) .. Lang :t (' afk.time_minutes' ), ' error' , 10000 )
55- elseif _type == ' seconds' then
56- QBCore .Functions .Notify (Lang :t (' afk.will_kick' ) .. time .. Lang :t (' afk.time_seconds' ), ' error' , 10000 )
57- end
58- time -= 10
59- else
60- TriggerServerEvent (' KickForAFK' )
61- end
29+ if (isLoggedIn or Config .AFK .kickInCharMenu ) and checkUser then
30+ while GetTimeSinceLastInput (0 ) > sleepTimer do
31+ local kickTimer = Config .AFK .minutesUntilKick * 60 * 1000
32+ local timeLeftSec = (kickTimer - GetTimeSinceLastInput (0 )) / 1000
33+ for _ , warning in pairs (Config .AFK .warnings ) do
34+ if not warning .sent and timeLeftSec < warning .timeSec then
35+ if warning .timeSec >= 60 then
36+ QBCore .Functions .Notify (Lang :t (' afk.will_kick' ) .. math.ceil (warning .timeSec / 60 ) .. Lang :t (' afk.time_minutes' ), ' error' , 15000 )
6237 else
63- time = Config . AFK . secondsUntilKick
38+ QBCore . Functions . Notify ( Lang : t ( ' afk.will_kick ' ) .. warning . timeSec .. Lang : t ( ' afk.time_seconds ' ), ' error ' , 15000 )
6439 end
65- else
66- time = Config .AFK .secondsUntilKick
40+ warning .sent = true
41+ end
42+ if GetTimeSinceLastInput (0 ) > kickTimer then
43+ TriggerServerEvent (' KickForAFK' )
6744 end
6845 end
69- prevPos = currPos
46+ Wait ( 1000 )
7047 end
48+ for _ , warning in pairs (Config .AFK .warnings ) do warning .sent = false end
7149 end
50+ Wait (sleepTimer )
7251 end
7352end )
0 commit comments