Afk Rewards skript latest version

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Kartvya69

Member
Sep 21, 2023
3
0
1
26
Suggested name: Afk Rewards Skript

Skript Version: 2.8.0

What I want: I want a Afk skript that have customisable region enter and exit message with the afk rewards where on afking on that region give the rewards using console commands and i wanted that there should be an actionbar timer of completion in percentage and leaving that region may reset the time or leaving the server too resets the time I wanted because the other skripts doesn't works with latest version

Ideas for commands: There can be commands for like blacklisting a player only for admins command

When I'd like it by: About 30 January 2024 5pm IST [cuz I will release my server on that time]
 
I whipped up a little system that should be dynamic enough to fit your needs. I didn't do mush testing though so there could still be some bugs. Let me know if you have any issues. I made it on Skript 2.8.2
Requirements:
- worldguard (tested on 7.0.9)
- Skbee (tested on 3.2.1)
- skript-gui (for the unban gui, can be removed if you delete last portion of code) (tested on 1.3)

AppleScript:
options:
    prefix: &7[&cAFK&7] &f
    # Name of the afk region
    afk-region: afk
    # Placeholders for enter/exit message:
    # <player>
    # Use false to turn off the message
    region-enter-message: &eWelcome to the afk region <player>
    region-exit-message: false
    # How long it takes to get a reward
    reward-cooldown: 5 minutes
    # Stop afk-banned players from entering the afk zone
    block-banned-users: false
    # Progress mode defines how the afk progress is displayed
    # aciton bar: show how long the player has until the next reward in thier aciton bar
    # boss bar: creates a bossbar which fills up according to how long the player has until the next reward
    progress-mode: action bar
    boss-bar-message: &fNext AFK Reward
    # Placeholders for action bar message:
    # <hours>, <minutes>, <seconds>, <clean time>, <player>
    action-bar-message: &b<clean time> &euntil next reward
    # The line of code that will be run when a player earns their reward
    # Examples:
    #    console command "say hi"
    #    give player apple named "&cTasty"
    #    add 100 to player's balance
    reward-code: console command "say hi"
   

on region enter:
    if event-region is ("{@afk-region}" parsed as region):
        if {afk::bannedUsers::*} contains uuid of event-player:
            if {@block-banned-users} is true:
                cancel event
            send "{@prefix}&cYou are banned from the afk region"
        else:
            set {_session} to random uuid
            set {afk::sessions::%player's uuid%} to {_session}
            if "{@progress-mode}" is "boss bar":
                set {_bar} to new boss bar with id "afk-%player's uuid%" with title "{@boss-bar-message}" with style solid bar with progress 0
                add player to {_bar}
            set {_lastReward} to now
            if "{@region-enter-message}" is not "false":
                set {_msg} to "{@region-enter-message}"
                replace all "<player>" with "%player%" in {_msg}
                send {_msg}
            while {afk::sessions::%player's uuid%} is {_session}:
                if "{@progress-mode}" is "boss bar":
                    set bar progress of {_bar} to (100*((seconds of (time since {_lastReward}))/(seconds of {@reward-cooldown})))
                else if "{@progress-mode}" is "action bar":
                    set {_msg} to "{@action-bar-message}"
                    set {_diff} to difference between {@reward-cooldown} and (time since {_lastReward})
                    replace all "<seconds>" in {_msg} with "%mod(seconds of {_diff}, 60)%"
                    replace all "<minutes>" in {_msg} with "%mod(minutes of {_diff}, 60)%"
                    replace all "<hours>" in {_msg} with "%hours of {_diff}%"
                    replace all "<clean time>" in {_msg} with cleanTime({_diff})
                    replace all "<player>" in {_msg} with "%player%"
                    send action bar {_msg}
                if time since {_lastReward} > {@reward-cooldown}:
                    # more rewards can be given out here
                    {@reward-code}
                    set {_lastReward} to now
                wait 1 second
            if {_bar} is set:
                remove player from {_bar}

local function cleanTime(time: timespan):: text:
    set {_t} to "%mod(seconds of {_time}, 60)%s"
    if minutes of {_time} > 0:
        set {_t} to "%mod(minutes of {_time}, 60)%m, %{_t}%"
    if hours of {_time} > 0:
        set {_t} to "%hours of {_time}%h, %{_t}%"
    replace all ", 0s" with "" in {_t}
    replace all ", 0m" with "" in {_t}
    return {_t}

on region exit:
    if event-region is ("{@afk-region}" parsed as region):
        delete {afk::sessions::%player's uuid%}
        if "{@region-exit-message}" is not "false":
            set {_msg} to "{@region-exit-message}"
            replace all "<player>" with "%player%" in {_msg}
            send {_msg}
on quit:
    delete {afk::sessions::%player's uuid%}

command /afkban <offline player>:
    permission: afk.admin
    trigger:
        if {afk::bannedUsers::*} does not contain arg-1's uuid:
            add arg-1's uuid to {afk::bannedUsers::*}
            send "{@prefix}%arg-1% will no longer recieve afk rewards"
        else:
            send "{@prefix}&c%arg-1% is already banned from recieving afk rewards"

command /afkunban <offline player>:
    permission: afk.admin
    trigger:
        if {afk::bannedUsers::*} contains arg-1's uuid:
            remove arg-1's uuid from {afk::bannedUsers::*}
            send "{@prefix}%arg-1% will now recieve afk rewards"
        else:
            send "{@prefix}&c%arg-1% is already recieving afk rewards"


# Remove everything below this point if you do not want to use skript-gui
command /afkbanlist:
    permission: afk.admin
    trigger:
        openUnbanMenu(player)

local function openUnbanMenu(p: player, page: integer = 0):
    if size of {afk::bannedUsers::*} is 0:
        send "{@prefix}&cThere is no one to unban" to {_p}
    else if size of {afk::bannedUsers::*} <= 54:
        set {_rows} to ceil(size of {afk::bannedUsers::*} / 9)
        create a gui with virtual chest inventory with {_rows} rows named "&8AFK Banned Users":
            loop {afk::bannedUsers::*}:
                set {_player} to offlineplayer(loop-value)
                make next gui slot with skull of {_player} named "&c%{_player}%" with lore "&aClick to unban":
                    remove {_player}'s uuid from {afk::bannedUsers::*}
                    send "{@prefix}You have unbanned %{_player}%" to {_p}
                    if size of {afk::bannedUsers::*} is 0:
                        close {_p}'s inventory
                    else:
                        openUnbanMenu({_p})
    else:
        set {_start} to 1 + 45*{_page}
        set {_stop} to {_start} + 45
        create a gui with virtual chest inventory with 6 rows named "&8AFK Banned Users (%{_page} + 1%/%ceil(size of {afk::bannedUsers::*} / 45)%)":
            loop {afk::bannedUsers::*}:
                if loop-iteration = {_stop}:
                    stop loop
                if loop-iteration >= {_start}:
                    set {_player} to offlineplayer(loop-value)
                    make next gui slot with skull of {_player} named "&c%{_player}%" with lore "&aClick to unban":
                        remove {_player}'s uuid from {afk::bannedUsers::*}
                        send "{@prefix}You have unbanned %{_player}%" to {_p}
                        if size of {afk::bannedUsers::*} < {_start}:
                            openUnbanMenu({_p}, {_page}-1)
                        else:
                            openUnbanMenu({_p}, {_page})
            make gui slot (integers between 45 and 53) with black stained glass pane named ""
            make gui slot 46 with arrow named "&cBack":
                openUnbanMenu({_p}, {_page}-1)
            if (size of {afk::bannedUsers::*} >= {_stop}):
                make gui slot 52 with arrow named "&aNext":
                    openUnbanMenu({_p}, {_page} + 1)
    open last gui to {_p}
 
Last edited:
I tried this but I got 6 errors: In line 112, 120, 67, 58, 56 and 40. For line 40: cant understand this expressions. For line 56: the function clean time does not exist. For line 58: Cant understand this condition/effect. for line 67: Cant understand this event. For line 110: The function openUnbanMenu does not exist. For line 112:Cant understand this event. You have made an awesome skript but there are some issues. I got worldguard skbee and now I also added skript gui. Maybe I have also just put them wrong. worldguard, skbee and skript gui are in plugins folder right? So I dont know that is wrong with it.
 
1711928557023.png
1711928562408.png
1711928566392.png
1711928568855.png
 
Local functions might be part of a newer skript version (this was made for 2.8 while you are using 2.6). You can try removing the word local before the function definitions
 
You seem to be a very smart skripter but I gotta be honest that I dont much of skript. Can you explain it for me easier pls haha