[REQUEST] AFK kick, exclude certain players?

Is there a script out there that kicks people after not moving for a certain amount of time, but also allows you to exclude certain players? the reason i want this is because the current AFK kick still kicks me if i am using menyoo to build maps in my server with friends. For some reason when we are using spooner mode and moving around and placing stuff, it does not register us as moving, resulting in us being kicked. If this exists, i would be very thankful if you could help me find it. If not, I’m very unseasoned in writing scripts and code and all that stuff, but if you think you could make it or if something like this is possible that would be great!

Thanks in advance!

Here

Just add a condition to not kick you while you’re in no clip.

Or the best option IMO is to add a column in your user table in your database. (or if you already have an admin or status column, use it)
Fetch the users who have been declared with that column at the server start, store them in an array and make a condition to exclude them from the afk script.

well, i see the ping kick version already has it… but i also need an afk kicker.
im reading what you’re saying but i really don’t understand, i only know how to do super basic things with script.

Okay, maybe try to do it the easiest way.

Do a white-listed steamid array where you declare you and your friends steamids (base64) in there to specify to the script to not kick them.

Add the following code without erasing anything from the previous code.

client.lua

-- rest of the script

local dontkick = { -- declare your steamids below 
    "steam:11000011aaaaaaa",
    "steam:11000011bbbbbbb",
    "steam:11000011ccccccc"
}
local whitelisted = nil -- and not false by default to detect if the script wait delay is not working

-- CODE --

local function checkIfWhitelisted(steamid)
  for _, v in ipairs(dontkick) do -- looping through the dontkick array
    if v == steamid then -- if match
      print("You are now whitelisted")
      return true -- a return will prevent from looping further since you've already got what you wanted
    end
  end -- if the loop ends = no match
  print("Not whitelisted")
  return false
end

RegisterNetEvent('afk:returnSteamID')
AddEventHandler('afk:returnSteamID', function(steamid) -- return steamid client side
  whitelisted = checkIfWhitelisted(steamid)
end)

CreateThread(function()
  TriggerServerEvent("afk:getSteamID")
  if whitelisted == nil then
    Wait(1000) -- important since events are asynchrone, under 1000ms, the script may continue before even getting the steamid
  end
  if not whitelisted then -- same as 'if whitelist == false then'
    while true do
      Wait(1000)
      --rest of the script
    end
  end
end)
-- rest of the script

server.lua

RegisterServerEvent('afk:getSteamID')
AddEventHandler('afk:getSteamID', function() -- source = the current player
  local steamid = GetPlayerIdentifiers(source)[1] -- 1 = the first element in the array which is the steamid
  TriggerClientEvent('afk:returnSteamID', source, steamid) -- return the steamid to the client side
end)
-- rest of the script

You retrieve the steamid by calling the GetPlayerIdentifiers native which return an array with steamid, licence, xbl etc.
Since GetPlayerIdentifiers is a server side native, you’ll need a server event to call the GetPlayerIdentifiers, then a client event to get back the steamid from the server side.
Then you compare the retrieved steamid with the ones in the array, looping row by row.

Since steamids don’t change mid game, you may only need to run the script once when a player connects.
That’s why the verification code I wrote is before the infinite loop in the thread.
It checks whenever to run or not the afk resource for each player who connects.
This prevent the script from running in background for the whitelisted ones, since it’s doesn’t need to check if they’re afk anymore.

TL:DR if someone is whitelisted: the script end for that player immediately, otherwise it will run indefinitely for the other non-whitelisted players.

mm… i tried placing the first code in client.lua, and the second one in server.lua. i made sure to add the base64 steam id’s in client.lua and i did not erase anything. it doesn’t seem to work because it still afk kicks me. im not sure what i could be doing wrong

You need to press F8 in game to see what’s going on and check if they’re any errors in the client console.

If nothing, check that you have correctly started the resource.
If not, do a start afkkick in the server console or just write start afkkick in your server.cfg and restart the server.

You will need to do a restart afkkick in the server console every time you’re making a update to reload the script.

I’ve added a print(steamid) on the client side so you and your friend can get their steamids in base 64.

I’ve also added a print("AFK active") which pop every second to acknowledge that it’s correctly running. You can get rid of it anytime.

Code below for the afk script with an fxmanifest:
afkkick.zip (1.8 KB)

Sorry it took me a while to respond, my internet was down for a few days. But, anyways… For some reason it’s not registering that i’ve put in my own steam id’s… this steam id isn’t anywhere to be found in any of the files, client.lua, fxmanifest.lua, or server.lua.

update: i found that steam ID in my server.cfg, replaced it with my steam ID and i’m still getting AFK kicked.

Found the problem! It needs to be a hex steam ID. you can find your HEX steam ID here: https://vacbanned.com/

Hey! I know it’s been a bit, and you may not see this. Is there any way to implement this with a discord whitelist instead? Something like this:

Hey, I just created a script that does what you’re looking for.

just update qb-afk / client.lua

-- AFK Kick Time Limit (in seconds)
local group = 'user'
local secondsUntilKick = 3600
local QBCore = exports['qb-core']:GetCoreObject()
local prevPos, time = nil, nil

RegisterNetEvent('QBCore:Client:OnPlayerLoaded')
AddEventHandler('QBCore:Client:OnPlayerLoaded', function()
    QBCore.Functions.TriggerCallback('qb-afkkick:server:GetPermissions', function(UserGroup)
        group = UserGroup
    end)
end)

RegisterNetEvent('QBCore:Client:OnPermissionUpdate')
AddEventHandler('QBCore:Client:OnPermissionUpdate', function(UserGroup)
    group = UserGroup
end)

-- Function to check if the player is in an exempt group
function IsExemptGroup(group)
    local exemptGroups = {
        ['admin'] = true,
        ['god'] = true
        -- Add more exempt groups if needed
    }
    return exemptGroups[group] or false
end

-- Code
Citizen.CreateThread(function()
    while true do
        Wait(1000)
        local playerPed = PlayerPedId()
        if LocalPlayer.state['isLoggedIn'] then
            if not IsExemptGroup(group) then -- Check if player is not in exempt group
                currentPos = GetEntityCoords(playerPed, true)
                if prevPos ~= nil then
                    if currentPos == prevPos then
                        if time ~= nil then
                            if time > 0 then
                                if time == 900 or time == 600 or time == 300 or time == 150 or time == 60 then
                                    QBCore.Functions.Notify('You are AFK and will be kicked in ' .. math.ceil(time / 60) .. ' minutes!', 'error', 10000)
                                elseif time == 30 or time == 20 or time == 10 then
                                    QBCore.Functions.Notify('You are AFK and will be kicked in ' .. time .. ' seconds!', 'error', 10000)
                                end
                                time = time - 1
                            else
                                TriggerServerEvent('KickForAFK')
                            end
                        else
                            time = secondsUntilKick
                        end
                    else
                        time = secondsUntilKick
                    end
                end
                prevPos = currentPos
            end
        end
    end
end)