tetrichobos

make me a script that teleports users to a essentials warp when they are afk or standing still for a certain amount of time

Kodari AI
KodariDec 31 at 3:13 am 2,723 (v2)

I’ll create an AFK warper script that teleports idle players to an Essentials warp.

AFKWarper
Automatically detects when players are standing still or AFK and teleports them to a designated Essentials warp after a configurable time period. Tracks player positions and movement, with customizable delay times and warp destinations. Includes player notifications and permission-based exemptions for staff members.

Installation Instructions:

  1. Place the file in plugins/Skript/scripts/

  2. Reload the script with /sk reload afk-warper

  3. Create the Essentials warp with /setwarp afk (or whatever name you want)

Configuration (edit the options at the top):

  • afk-time: 300 - Seconds before teleport (default 5 minutes)

  • warp-name: afk - Name of your Essentials warp

  • check-interval: 5 - How often to check positions (seconds)

  • warning-time: 30 - Countdown warning before teleport (seconds)

Permissions:

  • afkwarper.exempt - Players with this permission won’t be teleported

  • afkwarper.admin - Access to /afkwarper command

Commands:

  • /afkwarper - View settings

  • /afkwarper toggle - Enable/disable the system

  • /afkwarper reload - Reset all timers

  • /afkwarper check - See current player timers

The script tracks player positions every 5 seconds and teleports them if they haven’t moved more than 0.1 blocks in any direction!

tetrichobos

this doesnt work youre bad at making scripts

Kodari AI
KodariDec 31 at 3:18 am 3,453 (v2)

I can see the issues. Let me fix this script:

Problems identified:

  • Permission check stops the entire loop instead of skipping that player

  • Movement detection is too broad and conflicts with the timer

  • Warp command execution may fail depending on server setup

Fixed:

  • Changed stop to continue so exempt players are skipped instead of breaking the loop

  • Changed on any movement to on walk to avoid conflicts

  • Changed make console execute command to execute console command

  • Added check for {afk-warper-enabled} in the timer loop

  • Fixed ternary operator syntax

To use:

  1. /sk reload afk-warper

  2. Make sure you have a warp called “afk” set up (or change the warp-name in options)

  3. Test by standing still for 5 minutes

Kodari can make mistakes. Review important code before using.
Files
afk-warper.sk
Code
1 103
afk-warper.sk
options:
    afk-time: 300
    warp-name: afk
    check-interval: 5
    prefix: &6[AFK-Warper]&r
    warning-time: 30
    exempt-permission: afkwarper.exempt

on script load:
    set {afk-warper-enabled} to true
    send "{@prefix} &aAFK Warper loaded! Players idle for {@afk-time} seconds will be warped to '{@warp-name}'" to console

on join:
    set {afk-position::%player%} to location of player
    set {afk-timer::%player%} to 0
    set {afk-warned::%player%} to false

on quit:
    delete {afk-position::%player%}
    delete {afk-timer::%player%}
    delete {afk-warned::%player%}

every {@check-interval} seconds:
    if {afk-warper-enabled} is true:
        loop all players:
            if loop-player has permission "{@exempt-permission}":
                continue
            
            set {_current-loc} to location of loop-player
            set {_last-loc} to {afk-position::%loop-player%}
            
            if {_last-loc} is set:
                set {_x-diff} to absolute value of (x-coordinate of {_current-loc} - x-coordinate of {_last-loc})
                set {_y-diff} to absolute value of (y-coordinate of {_current-loc} - y-coordinate of {_last-loc})
                set {_z-diff} to absolute value of (z-coordinate of {_current-loc} - z-coordinate of {_last-loc})
                
                if {_x-diff} < 0.1:
                    if {_y-diff} < 0.1:
                        if {_z-diff} < 0.1:
                            add {@check-interval} to {afk-timer::%loop-player%}
                            
                            set {_time-remaining} to {@afk-time} - {afk-timer::%loop-player%}
                            
                            if {_time-remaining} <= {@warning-time}:
                                if {afk-warned::%loop-player%} is false:
                                    send "{@prefix} &eYou will be teleported to the AFK area in &c%{_time-remaining}% &eseconds!" to loop-player
                                    set {afk-warned::%loop-player%} to true
                            
                            if {afk-timer::%loop-player%} >= {@afk-time}:
                                execute console command "/warp {@warp-name} %loop-player%"
                                send "{@prefix} &cYou have been teleported to the AFK area due to inactivity!" to loop-player
                                set {afk-timer::%loop-player%} to 0
                                set {afk-warned::%loop-player%} to false
                        else:
                            set {afk-timer::%loop-player%} to 0
                            set {afk-warned::%loop-player%} to false
                    else:
                        set {afk-timer::%loop-player%} to 0
                        set {afk-warned::%loop-player%} to false
                else:
                    set {afk-timer::%loop-player%} to 0
                    set {afk-warned::%loop-player%} to false
            
            set {afk-position::%loop-player%} to location of loop-player

on walk:
    if {afk-timer::%player%} > 0:
        set {afk-timer::%player%} to 0
        set {afk-warned::%player%} to false

command /afkwarper [<text>]:
    permission: afkwarper.admin
    trigger:
        if arg-1 is not set:
            send "{@prefix} &7=== AFK Warper Settings ==="
            send "&7AFK Time: &e{@afk-time} seconds"
            send "&7Warp Name: &e{@warp-name}"
            send "&7Check Interval: &e{@check-interval} seconds"
            send "&7Warning Time: &e{@warning-time} seconds"
            send "&7Status: %{afk-warper-enabled} is true ? ""&aEnabled"" : ""&cDisabled""%"
            send "&7Commands: &e/afkwarper <toggle|reload|check>"
        else if arg-1 is "toggle":
            if {afk-warper-enabled} is true:
                set {afk-warper-enabled} to false
            else:
                set {afk-warper-enabled} to true
            send "{@prefix} AFK Warper is now %{afk-warper-enabled} is true ? ""&aenabled"" : ""&cdisabled""%&r!" to player
        else if arg-1 is "reload":
            loop all players:
                delete {afk-position::%loop-player%}
                delete {afk-timer::%loop-player%}
                delete {afk-warned::%loop-player%}
                set {afk-position::%loop-player%} to location of loop-player
                set {afk-timer::%loop-player%} to 0
                set {afk-warned::%loop-player%} to false
            send "{@prefix} &aReloaded all AFK timers!" to player
        else if arg-1 is "check":
            send "{@prefix} &7Current AFK Timers:" to player
            loop all players:
                if {afk-timer::%loop-player%} is set:
                    send "&7- &e%loop-player%&7: &c%{afk-timer::%loop-player%}%&7/{@afk-time} seconds" to player
        else:
            send "{@prefix} &cUsage: /afkwarper <toggle|reload|check>" to player