Minigame Timer

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

iStopcontact

Member
Feb 18, 2017
113
2
18
23
Hey guys, I am working on my own minigame for my server network.
Now its almost done I only need a timer that the game automaticly ends after an amount of time.
How can i do that and display the remaining play time in a scorebord as variable
 
When your mini-game starts do

code_language.skript:
set {timer} to 300
300 is basically an integer in seconds, so your mini-game would last 5 minutes.


Then for countdown >

code_language.skript:
every 1 second:
    if {timer} isn't 0:
        subtract 1 from {timer}
    else:
        send "Game has stopped!"
        # Code Here

or

code_language.skript:
# Mini-Game Code Above
while {timerenable} is true:
    subtract 1 from {timer}
    if {timer} is 0:
        set {timerenable} to false

and for scoreboard

Require skRayFall
code_language.skript:
set name of sidebar of player to "&cMini-Games"
set score "&aTime: &c%{_timer}%s&a LEFT." in sidebar of player to 1
 
Last edited by a moderator:
When your mini-game starts do

code_language.skript:
set {timer} to 300
300 is basically an integer in seconds, so your mini-game would last 5 minutes.


Then for countdown >

code_language.skript:
every 1 second:
    if {timer} isn't 0:
        subtract 1 from {timer}
    else:
        send "Game has stopped!"
        # Code Here

or

code_language.skript:
# Mini-Game Code Above
while {timerenable} is true:
    subtract 1 from {timer}
    if {timer} is 0:
        set {timerenable} to false

and for scoreboard

Require skRayFall
code_language.skript:
set name of sidebar of player to "&cMini-Games"
set score "&aTime: &c%{_timer}%s&a LEFT." in sidebar of player to 1
Thanks, but is it maybe possible to display the time in minutes and seconds?
 
this should work
code_language.skript:
every 1 second:
    loop all players:
        if {Ingame.%loop-player%} is true:
            wipe loop-player's sidebar
            set name of sidebar of loop-player to "Example"
            set score "%difference between {_Timer} and 10 minutes%" in sidebar of loop-player to 1

        if difference between {_Timer} and now is more than 10 minutes:
            # end code
    
# Minigame code above
set {_Timer} to now
 
Recently I created this, you can use it if want:
code_language.skript:
function cDown(am: number):
    if {_am} is 180:
        set {time} to "03:00"
        set {_w} to 1
    else if {_am} is 120:
        set {time} to "02:00"
        set {_w} to 1
    else if {_am} is 60:
        set {time} to "01:00"
        set {_w} to 1
    else if {_am} is 30:
        set {time} to "00:30"
        set {_w} to 31
    else if {_am} is 10:
        set {time} to "00:10"
        set {_w} to 51
    wait 1 second
    loop {_am}-1 times:
        if {_am}-loop-number is greater than 120:
            if {_w} is greater than 50:
                set {time} to "02:0%60-{_w}%"
            else:
                set {time} to "02:%60-{_w}%"
        else if {_am}-loop-number is 120:
            set {time} to "02:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 60:
            if {_w} is greater than 50:
                set {time} to "01:0%60-{_w}%"
            else:
                set {time} to "01:%60-{_w}%"
        else if {_am}-loop-number is 60:
            set {time} to "01:00"
            set {_w} to 0
        else:
            if {_w} is greater than 50:
                set {time} to "00:0%60-{_w}%"
            else:
                set {time} to "00:%60-{_w}%"
        add 1 to {_w}
        wait 1 second
 
Recently I created this, you can use it if want:
code_language.skript:
function cDown(am: number):
    if {_am} is 180:
        set {time} to "03:00"
        set {_w} to 1
    else if {_am} is 120:
        set {time} to "02:00"
        set {_w} to 1
    else if {_am} is 60:
        set {time} to "01:00"
        set {_w} to 1
    else if {_am} is 30:
        set {time} to "00:30"
        set {_w} to 31
    else if {_am} is 10:
        set {time} to "00:10"
        set {_w} to 51
    wait 1 second
    loop {_am}-1 times:
        if {_am}-loop-number is greater than 120:
            if {_w} is greater than 50:
                set {time} to "02:0%60-{_w}%"
            else:
                set {time} to "02:%60-{_w}%"
        else if {_am}-loop-number is 120:
            set {time} to "02:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 60:
            if {_w} is greater than 50:
                set {time} to "01:0%60-{_w}%"
            else:
                set {time} to "01:%60-{_w}%"
        else if {_am}-loop-number is 60:
            set {time} to "01:00"
            set {_w} to 0
        else:
            if {_w} is greater than 50:
                set {time} to "00:0%60-{_w}%"
            else:
                set {time} to "00:%60-{_w}%"
        add 1 to {_w}
        wait 1 second
How do you like set the {_am} when calling a function? And how do you call it?
[doublepost=1497394203,1497388274][/doublepost]
code_language.skript:
function countDown(am: number):
    if {_am} is 30:
        set {time} to "00:30"
        set {_w} to 31
    else if {_am} is 10:
        set {time} to "00:10"
        set {_w} to 51
    wait 1 second
    loop {_am}-1 times:
        if {_w} is greater than 50:
            set {time} to "00:0%60-{_w}%"
        else:
            set {time} to "00:%60-{_w}%"
        add 1 to {_w}
        wait 1 second
if {time} is "00:15":
    broadcast "Something"
So I've made something like this and it doesn't work, like it doesn't reduce the time at all, it just keeps on 00:30. Can I get help for this please? Maybe @TheIronMinerLv
 
@dudle First of all your minigame probably will have some kind of "stop" state, so you should create that function will stop in case of game stop... I'll give you an example:

code_language.skript:
command /startg:
    trigger:
        broadcast "The game is going to start in 30 seconds"
        countDown(30)
        #next lines is if you want some action after this countdown
        wait 30 seconds
        {game.status} is not "stop"    #check if game is still running
        broadcast "The game is ended with a tie!"

#It depends on your game, here I created a command which will stop the countdown

command /stopg:
    trigger:
        set {game.status} to "stop"
        broadcast "The game has been stopped!"

function countDown(am: number):
    if {_am} is 30:
        set {time} to "00:30"
        set {_w} to 31
    else if {_am} is 10:
        set {time} to "00:10"
        set {_w} to 51
    wait 1 second
    loop {_am}-1 times:
        if {game.status} is "stop":
            stop
        if {_w} is greater than 50:
            set {time} to "00:0%60-{_w}%"
        else:
            set {time} to "00:%60-{_w}%"
        if {time} is "00:15":
            broadcast "Something"
        add 1 to {_w}
        wait 1 second
 
@dudle First of all your minigame probably will have some kind of "stop" state, so you should create that function will stop in case of game stop... I'll give you an example:

code_language.skript:
command /startg:
    trigger:
        broadcast "The game is going to start in 30 seconds"
        countDown(30)
        #next lines is if you want some action after this countdown
        wait 30 seconds
        {game.status} is not "stop"    #check if game is still running
        broadcast "The game is ended with a tie!"

#It depends on your game, here I created a command which will stop the countdown

command /stopg:
    trigger:
        set {game.status} to "stop"
        broadcast "The game has been stopped!"

function countDown(am: number):
    if {_am} is 30:
        set {time} to "00:30"
        set {_w} to 31
    else if {_am} is 10:
        set {time} to "00:10"
        set {_w} to 51
    wait 1 second
    loop {_am}-1 times:
        if {game.status} is "stop":
            stop
        if {_w} is greater than 50:
            set {time} to "00:0%60-{_w}%"
        else:
            set {time} to "00:%60-{_w}%"
        if {time} is "00:15":
            broadcast "Something"
        add 1 to {_w}
        wait 1 second
Yeah I have that, but I also want to have multiple game statutes, and different countdowns, so for example pre-game would be like 10 sec, game 3 mins, end would be 10 sec. Do I need to use different functions for each state, or just one? How, can you help me, please?
 
Yeah I have that, but I also want to have multiple game statutes, and different countdowns, so for example pre-game would be like 10 sec, game 3 mins, end would be 10 sec. Do I need to use different functions for each state, or just one? How, can you help me, please?
You can use multiple functions, it will be easier for you.
[doublepost=1497516320,1497441940][/doublepost]Here you go:
code_language.skript:
function countdownGame(am: number):
    if {_am} is 900:
        set {time} to "15:00"
        set {_w} to 1
    else if {_am} is 840:
        set {time} to "14:00"
        set {_w} to 1
    else if {_am} is 780:
        set {time} to "13:00"
        set {_w} to 1
    else if {_am} is 720:
        set {time} to "12:00"
        set {_w} to 1
    else if {_am} is 660:
        set {time} to "11:00"
        set {_w} to 1
    else if {_am} is 600:
        set {time} to "10:00"
        set {_w} to 1
    else if {_am} is 540:
        set {time} to "09:00"
        set {_w} to 1
    else if {_am} is 480:
        set {time} to "08:00"
        set {_w} to 1
    else if {_am} is 420:
        set {time} to "07:00"
        set {_w} to 1
    else if {_am} is 360:
        set {time} to "06:00"
        set {_w} to 1
    else if {_am} is 300:
        set {time} to "05:00"
        set {_w} to 1
    else if {_am} is 240:
        set {time} to "04:00"
        set {_w} to 1
    else if {_am} is 180:
        set {time} to "03:00"
        set {_w} to 1
    else if {_am} is 120:
        set {time} to "02:00"
        set {_w} to 1
    else if {_am} is 60:
        set {time} to "01:00"
        set {_w} to 1
    else if {_am} is 30:
        set {time} to "00:30"
        set {_w} to 31
    else if {_am} is 10:
        set {time} to "00:10"
        set {_w} to 51
    wait 1 second
    loop {_am}-1 times:
        if {_am}-loop-number is greater than 900:
            if {_w} is greater than 50:
                set {time} to "15:0%60-{_w}%"
            else:
                set {time} to "15:%60-{_w}%"
        else if {_am} is 900:
            set {time} to "15:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 840:
            if {_w} is greater than 50:
                set {time} to "14:0%60-{_w}%"
            else:
                set {time} to "14:%60-{_w}%"
        else if {_am} is 840:
            set {time} to "14:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 780:
            if {_w} is greater than 50:
                set {time} to "13:0%60-{_w}%"
            else:
                set {time} to "13:%60-{_w}%"
        else if {_am} is 780:
            set {time} to "13:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 720:
            if {_w} is greater than 50:
                set {time} to "12:0%60-{_w}%"
            else:
                set {time} to "12:%60-{_w}%"
        else if {_am} is 720:
            set {time} to "12:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 660:
            if {_w} is greater than 50:
                set {time} to "11:0%60-{_w}%"
            else:
                set {time} to "11:%60-{_w}%"
        else if {_am} is 660:
            set {time} to "11:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 600:
            if {_w} is greater than 50:
                set {time} to "10:0%60-{_w}%"
            else:
                set {time} to "10:%60-{_w}%"
        else if {_am} is 600:
            set {time} to "10:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 540:
            if {_w} is greater than 50:
                set {time} to "09:0%60-{_w}%"
            else:
                set {time} to "09:%60-{_w}%"
        else if {_am} is 540:
            set {time} to "09:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 480:
            if {_w} is greater than 50:
                set {time} to "08:0%60-{_w}%"
            else:
                set {time} to "08:%60-{_w}%"
        else if {_am} is 480:
            set {time} to "08:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 420:
            if {_w} is greater than 50:
                set {time} to "07:0%60-{_w}%"
            else:
                set {time} to "07:%60-{_w}%"
        else if {_am} is 420:
            set {time} to "07:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 360:
            if {_w} is greater than 50:
                set {time} to "06:0%60-{_w}%"
            else:
                set {time} to "06:%60-{_w}%"
        else if {_am} is 360:
            set {time} to "06:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 300:
            if {_w} is greater than 50:
                set {time} to "05:0%60-{_w}%"
            else:
                set {time} to "05:%60-{_w}%"
        else if {_am} is 300:
            set {time} to "05:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 240:
            if {_w} is greater than 50:
                set {time} to "04:0%60-{_w}%"
            else:
                set {time} to "04:%60-{_w}%"
        else if {_am} is 240:
            set {time} to "04:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 180:
            if {_w} is greater than 50:
                set {time} to "03:0%60-{_w}%"
            else:
                set {time} to "03:%60-{_w}%"
        else if {_am} is 180:
            set {time} to "03:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 120:
            if {_w} is greater than 50:
                set {time} to "02:0%60-{_w}%"
            else:
                set {time} to "02:%60-{_w}%"
        else if {_am} is 120:
            set {time} to "02:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 60:
            if {_w} is greater than 50:
                set {time} to "01:0%60-{_w}%"
            else:
                set {time} to "01:%60-{_w}%"
        else if {_am}-loop-number is 60:
            set {time} to "01:00"
            set {_w} to 0
        else:
            if {_w} is greater than 50:
                set {time} to "00:0%60-{_w}%"
            else:
                set {time} to "00:%60-{_w}%"
        add 1 to {_w}
        wait 1 second
        if {time} is "00:01":
            wait 1 second
            broadcast "&c&lOVER"
            stop
 
  • Like
Reactions: meteriodenboy1
You can use multiple functions, it will be easier for you.
[doublepost=1497516320,1497441940][/doublepost]Here you go:
code_language.skript:
function countdownGame(am: number):
    if {_am} is 900:
        set {time} to "15:00"
        set {_w} to 1
    else if {_am} is 840:
        set {time} to "14:00"
        set {_w} to 1
    else if {_am} is 780:
        set {time} to "13:00"
        set {_w} to 1
    else if {_am} is 720:
        set {time} to "12:00"
        set {_w} to 1
    else if {_am} is 660:
        set {time} to "11:00"
        set {_w} to 1
    else if {_am} is 600:
        set {time} to "10:00"
        set {_w} to 1
    else if {_am} is 540:
        set {time} to "09:00"
        set {_w} to 1
    else if {_am} is 480:
        set {time} to "08:00"
        set {_w} to 1
    else if {_am} is 420:
        set {time} to "07:00"
        set {_w} to 1
    else if {_am} is 360:
        set {time} to "06:00"
        set {_w} to 1
    else if {_am} is 300:
        set {time} to "05:00"
        set {_w} to 1
    else if {_am} is 240:
        set {time} to "04:00"
        set {_w} to 1
    else if {_am} is 180:
        set {time} to "03:00"
        set {_w} to 1
    else if {_am} is 120:
        set {time} to "02:00"
        set {_w} to 1
    else if {_am} is 60:
        set {time} to "01:00"
        set {_w} to 1
    else if {_am} is 30:
        set {time} to "00:30"
        set {_w} to 31
    else if {_am} is 10:
        set {time} to "00:10"
        set {_w} to 51
    wait 1 second
    loop {_am}-1 times:
        if {_am}-loop-number is greater than 900:
            if {_w} is greater than 50:
                set {time} to "15:0%60-{_w}%"
            else:
                set {time} to "15:%60-{_w}%"
        else if {_am} is 900:
            set {time} to "15:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 840:
            if {_w} is greater than 50:
                set {time} to "14:0%60-{_w}%"
            else:
                set {time} to "14:%60-{_w}%"
        else if {_am} is 840:
            set {time} to "14:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 780:
            if {_w} is greater than 50:
                set {time} to "13:0%60-{_w}%"
            else:
                set {time} to "13:%60-{_w}%"
        else if {_am} is 780:
            set {time} to "13:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 720:
            if {_w} is greater than 50:
                set {time} to "12:0%60-{_w}%"
            else:
                set {time} to "12:%60-{_w}%"
        else if {_am} is 720:
            set {time} to "12:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 660:
            if {_w} is greater than 50:
                set {time} to "11:0%60-{_w}%"
            else:
                set {time} to "11:%60-{_w}%"
        else if {_am} is 660:
            set {time} to "11:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 600:
            if {_w} is greater than 50:
                set {time} to "10:0%60-{_w}%"
            else:
                set {time} to "10:%60-{_w}%"
        else if {_am} is 600:
            set {time} to "10:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 540:
            if {_w} is greater than 50:
                set {time} to "09:0%60-{_w}%"
            else:
                set {time} to "09:%60-{_w}%"
        else if {_am} is 540:
            set {time} to "09:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 480:
            if {_w} is greater than 50:
                set {time} to "08:0%60-{_w}%"
            else:
                set {time} to "08:%60-{_w}%"
        else if {_am} is 480:
            set {time} to "08:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 420:
            if {_w} is greater than 50:
                set {time} to "07:0%60-{_w}%"
            else:
                set {time} to "07:%60-{_w}%"
        else if {_am} is 420:
            set {time} to "07:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 360:
            if {_w} is greater than 50:
                set {time} to "06:0%60-{_w}%"
            else:
                set {time} to "06:%60-{_w}%"
        else if {_am} is 360:
            set {time} to "06:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 300:
            if {_w} is greater than 50:
                set {time} to "05:0%60-{_w}%"
            else:
                set {time} to "05:%60-{_w}%"
        else if {_am} is 300:
            set {time} to "05:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 240:
            if {_w} is greater than 50:
                set {time} to "04:0%60-{_w}%"
            else:
                set {time} to "04:%60-{_w}%"
        else if {_am} is 240:
            set {time} to "04:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 180:
            if {_w} is greater than 50:
                set {time} to "03:0%60-{_w}%"
            else:
                set {time} to "03:%60-{_w}%"
        else if {_am} is 180:
            set {time} to "03:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 120:
            if {_w} is greater than 50:
                set {time} to "02:0%60-{_w}%"
            else:
                set {time} to "02:%60-{_w}%"
        else if {_am} is 120:
            set {time} to "02:00"
            set {_w} to 0
        else if {_am}-loop-number is greater than 60:
            if {_w} is greater than 50:
                set {time} to "01:0%60-{_w}%"
            else:
                set {time} to "01:%60-{_w}%"
        else if {_am}-loop-number is 60:
            set {time} to "01:00"
            set {_w} to 0
        else:
            if {_w} is greater than 50:
                set {time} to "00:0%60-{_w}%"
            else:
                set {time} to "00:%60-{_w}%"
        add 1 to {_w}
        wait 1 second
        if {time} is "00:01":
            wait 1 second
            broadcast "&c&lOVER"
            stop
It continuously spams "15:00" ;-;
 
Status
Not open for further replies.