1
1
local QBCore = exports [' qb-core' ]:GetCoreObject ()
2
2
local isLoggedIn = LocalPlayer .state .isLoggedIn
3
3
local 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
- }
15
4
16
5
local function updatePermissionLevel ()
17
6
QBCore .Functions .TriggerCallback (' qb-afkkick:server:GetPermissions' , function (userGroups )
@@ -34,40 +23,30 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
34
23
isLoggedIn = false
35
24
end )
36
25
37
- RegisterNetEvent (' QBCore:Client:OnPermissionUpdate' , function ()
38
- updatePermissionLevel ()
39
- end )
40
-
41
26
CreateThread (function ()
27
+ local sleepTimer = 10000
42
28
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 )
62
37
else
63
- time = Config . AFK . secondsUntilKick
38
+ QBCore . Functions . Notify ( Lang : t ( ' afk.will_kick ' ) .. warning . timeSec .. Lang : t ( ' afk.time_seconds ' ), ' error ' , 15000 )
64
39
end
65
- else
66
- time = Config .AFK .secondsUntilKick
40
+ warning .sent = true
41
+ end
42
+ if GetTimeSinceLastInput (0 ) > kickTimer then
43
+ TriggerServerEvent (' KickForAFK' )
67
44
end
68
45
end
69
- prevPos = currPos
46
+ Wait ( 1000 )
70
47
end
48
+ for _ , warning in pairs (Config .AFK .warnings ) do warning .sent = false end
71
49
end
50
+ Wait (sleepTimer )
72
51
end
73
52
end )
0 commit comments