Skript Cooldown

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

    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.

CorpralBlack

New Member
Apr 23, 2020
7
0
1
Script version: 2.6.1
Minecraft version: 1.18.2

Hello there, I can't seem to make this code work:

Code:
on connect:
    set {_n} to 1

on damage of a player:
    if damage cause is lava:
        set {_h} to victim's health
        if {_h} is less than 5:
            if {_n} is more than 0:
                apply fire resistance to the victim
                send "&l&6Second Chance!" to victim
                send "" to victim
                send "&6You have been given a second chance! Quickly! Escape the lava!" to victim
                set {_n} to 0
                wait 5 minutes
                set {_n} to 1

The purpose of this script is to prevent the player from being killed in lava once, after a cooldown of 5 minutes. I cannot seem to make the if statement comparing two variables, this \/
Code:
if {_n} is more than 0:
work. It never seems to be true even if I set {_n} to 1 or higher. This is the one bit of code preventing my script from working.
 
This code is... not well-made. You should consider reading the basics on how and when to use local variables.

Code:
on join:
    set {lastchance::%player%} to now
    remove 5 minutes from {lastchance::%player%}

on damage of a player:
    if damage cause is lava:
        if victim's health is less than 5:
            if difference between now and {lastchance::%player%} is more than 5 minutes:
                set {lastchance::%player%} to now
                apply fire resistance to the victim for 1 minute
                send "&l&6Second Chance!%nl%%nl%&6You have been given a second chance! Quickly! Escape the lava!" to victim
 
Script version: 2.6.1
Minecraft version: 1.18.2

Hello there, I can't seem to make this code work:

Code:
on connect:
    set {_n} to 1

on damage of a player:
    if damage cause is lava:
        set {_h} to victim's health
        if {_h} is less than 5:
            if {_n} is more than 0:
                apply fire resistance to the victim
                send "&l&6Second Chance!" to victim
                send "" to victim
                send "&6You have been given a second chance! Quickly! Escape the lava!" to victim
                set {_n} to 0
                wait 5 minutes
                set {_n} to 1

The purpose of this script is to prevent the player from being killed in lava once, after a cooldown of 5 minutes. I cannot seem to make the if statement comparing two variables, this \/
Code:
if {_n} is more than 0:
work. It never seems to be true even if I set {_n} to 1 or higher. This is the one bit of code preventing my script from working.
the problem is you are using a local variable you have to use a personal variable for each player:
local variables are define like this {_variable} is goin to delete it selft when the event completes on.
global variables are like this {spawn} you can store something in here like a location and teleport players to spawn
personal variables are set like this {variable.%player%} you can make a variable for each player like this.
list are define like this {playerlist::*} you can for example add blocks, players, strings to this variable and you can loop this variable
this is the code fix with a list
Code:
on connect:
    set {second chance::%player%} to 1

on damage of a player:
    if damage cause is lava:
        set {_h} to victim's health
        if {_h} is less than 5:
            if {second chance::%victim%} is more than 0:
                apply fire resistance to the victim
                send "&l&6Second Chance!" to victim
                send "" to victim
                send "&6You have been given a second chance! Quickly! Escape the lava!" to victim
                set {second chance::%victim%} to 0

every 5 minutes:
    loop {second chance::*}:
        if {second chance::%loop-index%} is not equal to 1:
            set {second chance::%loop-index%} to 1
            message "You have 1 second chance" to loop-index
 
the problem is you are using a local variable you have to use a personal variable for each player:
local variables are define like this {_variable} is goin to delete it selft when the event completes on.
global variables are like this {spawn} you can store something in here like a location and teleport players to spawn
personal variables are set like this {variable.%player%} you can make a variable for each player like this.
list are define like this {playerlist::*} you can for example add blocks, players, strings to this variable and you can loop this variable
this is the code fix with a list
Code:
on connect:
    set {second chance::%player%} to 1

on damage of a player:
    if damage cause is lava:
        set {_h} to victim's health
        if {_h} is less than 5:
            if {second chance::%victim%} is more than 0:
                apply fire resistance to the victim
                send "&l&6Second Chance!" to victim
                send "" to victim
                send "&6You have been given a second chance! Quickly! Escape the lava!" to victim
                set {second chance::%victim%} to 0

every 5 minutes:
    loop {second chance::*}:
        if {second chance::%loop-index%} is not equal to 1:
            set {second chance::%loop-index%} to 1
            message "You have 1 second chance" to loop-index

Great explanation, but please don't use cooldown like that.
1. Periodical events aren't good for performance (every ...)
2. A player could have two-second chances within 3 seconds because of the way this is build
3. It's unusual to use spaces in variable names
4. There is no need for the {_h} variable
5. If you only use 0 and 1 it would be easier to use boolean's(false/true) instead of integers
 
Great explanation, but please don't use cooldown like that.
1. Periodical events aren't good for performance (every ...)
2. A player could have two-second chances within 3 seconds because of the way this is build
3. It's unusual to use spaces in variable names
4. There is no need for the {_h} variable
5. If you only use 0 and 1 it would be easier to use boolean's(false/true) instead of integers
thanks
 
This code is... not well-made. You should consider reading the basics on how and when to use local variables.

Code:
on join:
    set {lastchance::%player%} to now
    remove 5 minutes from {lastchance::%player%}

on damage of a player:
    if damage cause is lava:
        if victim's health is less than 5:
            if difference between now and {lastchance::%player%} is more than 5 minutes:
                set {lastchance::%player%} to now
                apply fire resistance to the victim for 1 minute
                send "&l&6Second Chance!%nl%%nl%&6You have been given a second chance! Quickly! Escape the lava!" to victim

I tried pasting this code in, but it still doesn't work. I get the error message that "victim" must be used in damage events, which caused me to change the lines 8 and 9 to 'victim' instead of 'player'. The code runs without errors, but also without the desired effect. If I fall into lava then even if I fall below a certain health threshold, fire resistance is not applied.
 
please debug the victims health, e.g.
Code:
on damage of a player:
    send "1"
    if damage cause is lava:
        send "2"
        if victim's health is less than 5:
            send "3"
 
Status
Not open for further replies.