Tempban skript

  • 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!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

KroterPvP

Active Member
Apr 10, 2017
178
7
18
22
Hello, I'm setting up my new skript. The title says it all, I'm having errors with the tempban module. All seems correct. I'm using timespans and the timers are perfectly displayed.

Every second the server checks if there are banned players. To do this, it loops the variable {bans::*}. If the banned player's autounban description equals to "Never", means the player is not going to be unbanned, so it stops and jumps to other loop-value. If there are any loop-value (player) who's autounban description doesn't equal to "Never", it checks if "now" is bigger than "loop-value's time of expiration". If it's true, it should execute a command to unban, and if it's not, it should stop.

It should work, but it doesn't. The player's aren't unbanned. The autounban description part runs well. But the part to check if the player should be unbanned is not running well.

All code is correctly writed, without any console error. Can somebody check the code, and help me?
code_language.skript:
command /tempban [<offlineplayer>] [<text>] [<timespan>]:
    permission: tempban
    permission message: &cYou don't have permission to do this!
    executable by: console and player
    trigger:
        if arg 1 is set:
            if arg 2 is set:
                if arg 3 is set:
                    if {sban.banned.%arg 1%} is true:
                        send "&7This player is already tempbanned"
                    else:
                        if arg 1 has permission "sb.tempban.exempt":
                            send "&7This player can't be tempbanned"
                        else:
                            set {_now} to now
                            set {_timespan} to arg 3
                            add {_timespan} to {_now}
                            set {_remaining} to {_now}
                            set {sban.banned.%arg 1%} to true
                            set {sban.bannedon.%arg 1%} to now
                            set {sban.banreason.%arg 1%} to arg 2
                            set {sban.banexpire.%arg 1%} to "%{_remaining}%"
                            set {sban.bannedby.%arg 1%} to "%sender%"
                            set {sban.banip.%arg 1%} to false
                            add arg 1 to {bans::*}
                            kick arg 1 due to "&7You were &cTempBanned &7from &6ServerName"
                else:
                    send "&7You must use &c/tempban <player> <reason> <timespan>"
            else:
                send "&7You must use &c/tempban <player> <reason> <timespan>"
        else:
            send "&7You must use &c/tempban <player> <reason> <timespan>"
every 1 second:
    execute console command "/updatetempbantimes"
command /updatetempbantimes:
    permission: sban.updatetempbantimes
    permission message: &cYou don't have permission to do this!
    executable by: console and player
    trigger:
        loop {bans::*}:
            if {sban.banned.%loop-value%} is true:
                if {sban.banexpire.%loop-value%} is not "Never":
                    if now is bigger than {sban.banexpire.%loop-value%}:
                        execute console command "/unban %loop-value%"
Thanks,
KroterPvP.
 
Last edited:
It's because your stopping the loop in line 43 & 48. From what you said I think you think it just stops the current loop iteration but it actually stops the entire loop.

So to fix it just do something like this:
code_language.skript:
loop {bans::*}:
    if {sban.banned.%loop-value%} is true:
        if {sban.banexpire.%loop-value%} is not "Never":
            if now is bigger than {sban.banexpire.%loop-value%}:
                execute console command "/unban %loop-value%"
If nothing happens if the condition isn't met, there's no need to have 'else'
 
It's because your stopping the loop in line 43 & 48. From what you said I think you think it just stops the current loop iteration but it actually stops the entire loop.

So to fix it just do something like this:
code_language.skript:
loop {bans::*}:
    if {sban.banned.%loop-value%} is true:
        if {sban.banexpire.%loop-value%} is not "Never":
            if now is bigger than {sban.banexpire.%loop-value%}:
                execute console command "/unban %loop-value%"
If nothing happens if the condition isn't met, there's no need to check 'else'
Oh, that's easyer than what I expected it was...

Thanks, I will try this
[doublepost=1499606077,1499605727][/doublepost]No, It's not running. I don't know why but the unban command is not executed when the condition is reached.
 
Are you saying that line 5 (line 46 in the original) is not working? Did you try testing another command there or simply broadcasting "hi"
 
Are you saying that line 5 (line 46 in the original) is not working? Did you try testing another command there or simply broadcasting "hi"
Yes, I've done it and the only condition that is not executing is
code_language.skript:
if now is bigger than {sban.banexpire.%loop-value%}:
     execute console command "/unban %loop-value%
# Line 43 of my thread description code"
 
You cant compare if now is bigger than something because it looks like this: 7/9/17 9:35 AM. Instead you need to check the difference between now and the original variable you set to now. Idk if that makes sense how i explained it but here's what your code should look like:
code_language.skript:
#in the temban command you need to add this:
set {sban.banlength.%arg-1%} to arg-3

#then replace line 43 with this:
set {_elapsed_time} to difference between now and {sban.banexpire.%loop-value%}
if {_elapsed_time} is greater than {sban.banlength.%loop-value%} :
    execute console command "/unban %loop-value%"
 
You cant compare if now is bigger than something because it looks like this: 7/9/17 9:35 AM. Instead you need to check the difference between now and the original variable you set to now. Idk if that makes sense how i explained it but here's what your code should look like:
code_language.skript:
#in the temban command you need to add this:
set {sban.banlength.%arg-1%} to arg-3

#then replace line 43 with this:
set {_elapsed_time} to difference between now and {sban.banexpire.%loop-value%}
if {_elapsed_time} is greater than {sban.banlength.%loop-value%} :
    execute console command "/unban %loop-value%"
I agree with you. It should work doing that change to the code, but it doesn't.
I don't know why is this doing that. It should work now, and it doesn't...

What should the error be¿?
 
can you said your current updated code
code_language.skript:
command /tempban [<offlineplayer>] [<text>] [<timespan>]:
    permission: sb.tempban
    permission message: &c&lSuperBans &8» &cYou don't have permission to do this!
    executable by: console and player
    trigger:
        if arg 1 is set:
            if arg 2 is set:
                if arg 3 is set:
                    if {sban.banned.%arg 1%} is true:
                        send "&c&lSuperBans &8» &7This player is already tempbanned"
                    else:
                        if arg 1 has permission "sb.tempban.exempt":
                            send "&c&lSuperBans &8» &7This player can't be tempbanned"
                        else:
                            set {_now} to now
                            set {_timespan} to arg 3
                            add {_timespan} to {_now}
                            set {_remaining} to {_now}
                            set {sban.banned.%arg 1%} to true
                            set {sban.bannedon.%arg 1%} to now
                            set {sban.banreason.%arg 1%} to arg 2
                            set {sban.banexpire.%arg 1%} to "%{_remaining}%"
                            set {sban.tempbanlenght.%arg 1%} to arg 3
                            set {sban.bannedby.%arg 1%} to "%sender%"
                            set {sban.banip.%arg 1%} to false
                            add arg 1 to {bans::*}
                            kick arg 1 due to "&7Sadly, you were &cTempBanned &7from &6ServerName&7. Apply on our forums if you want to dispute your ban!%nl%%nl%&7Banned by: &a%{sban.bannedby.%arg 1%}%%nl%&7Banned on: &c%{sban.bannedon.%arg 1%}%%nl%&7Autounban: &c%{sban.banexpire.%arg 1%}%%nl%&7IP Banned: &c%{sban.banip.%arg 1%}%%nl%&7Reason: &c%{sban.banreason.%arg 1%}%%nl%%nl%&eBuy an unban &8» &cwww.yourserver.buycraft.net%nl%&eForums to apply &8» &cwww.yourserver.net"
                            loop all players:
                                if loop-player has permission "sb.tempban.notify":
                                    send "&c&lSuperBans &8» &7I have handled a &a&lNEW BAN&r&7!" to loop-player
                                    send "" to loop-player
                                    send " &7Player banned &8» &e%arg 1%" to loop-player
                                    send " &7Banned by &8» &a%sender%" to loop-player
                                    send " &7Ban reason &8» &7'&a%arg 2%&7'" to loop-player
                                    send " &7Autounban &8» &a%{_remaining}% &7(&a%arg 3%&7)" to loop-player
                            send "&cSuperBans&8: &a%sender% &7banned &e%arg 1% &7('&a%arg 2%&7') &7- (&a%arg 3%&7)" to console
                else:
                    send "&c&lSuperBans &8» &7You must use &c/tempban <player> <reason> <timespan>"
            else:
                send "&c&lSuperBans &8» &7You must use &c/tempban <player> <reason> <timespan>"
        else:
            send "&c&lSuperBans &8» &7You must use &c/tempban <player> <reason> <timespan>"
every 1 second:
    execute console command "/updatetempbantimes"
command /updatetempbantimes:
    permission: sban.updatetempbantimes
    permission message: &c&lSuperBans &8» &cYou don't have permission to do this!
    executable by: console and player
    trigger:
        loop {bans::*}:
            if {sban.banned.%loop-value%} is true:
                if {sban.banexpire.%loop-value%} is not "Never":
                    set {_elapsedtime} to difference between now and {sban.banexpire.%loop-value%}
                    if {_elapsedtime} is greater than {sban.tempbanlenght.%loop-value%}:
                        execute console command "/unban %loop-value%"
 
remove quotes in line 22:
code_language.skript:
set {sban.banexpire.%arg 1%} to {_remaining}

But this variable is not used in the /updatetempbantimes, so it is not causing the error.

(EDIT: I can't remove the quotes, because without them the text is not displayed.
DOUBLE EDIT: Oh, Yes, I can remove it and it's displayed.)

TRIPLE EDIT: Oh, I look silly with many edits! It's fixed removing quotes!
 
Last edited by a moderator:
Status
Not open for further replies.