1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT??:

    You can always check our our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Potion effects

Discussion in 'Skript' started by Blobbyguy, Jul 11, 2017.

Thread Status:
Not open for further replies.
  1. Blobbyguy

    Blobbyguy Active Member

    Joined:
    Feb 2, 2017
    Messages:
    25
    Likes Received:
    0
    I need a way to apply a potion effect while a player is wearing/holding an item.
    The issue I am having is the effect in skript stacks the time so if a player has 1 second left on their potion, and then you apply potion effect for 1 second. It actually applies for two seconds. This means if the player wears the item for a long time, this leftover time builds up.

    Essentially what I'm looking for is a way to "Update" the time left on the potion every second. E.g.
    Set duration of potion effect on player to 1 second.

    I tried using the /effect command but it seems very inefficient to me to be using it every second on however many players are wearing an item.
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,680
    Likes Received:
    115
    Can you give us your code please
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,680
    Likes Received:
    115
    There is no code to give? The total code right now is
    Every 1 second:
    Player is wearing helmet
    Apply potion effect for 2 second

    But it's just stacking up instead of applying for 2 second
    (Total potion time = remaining time + 2 second)
    I want it to be total potion time = 2 second
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,680
    Likes Received:
    115
    make it apply the effect every 2 seconds
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,680
    Likes Received:
    115
    It's not exact though, that's my issue. In doing that it either still stacks up the slightest bit every 2 seconds or the potion effect wears off for a millisecond causing a blinking effect.
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,680
    Likes Received:
    115
    this would be 100000000000000x easier with an on armor equip event. something like this should work:
    Code (Skript):
    1. every second:
    2.     loop all players:
    3.         if loop-player is wearing a helmet:
    4.             if {wearing_helmet::%loop-player%} is false:
    5.                 set {wearing_helment::%loop-player%} to true
    6.                 apply swiftness to loop-player for 9999 days
    7.         else:
    8.             if {wearing_helmet::%loop-player%} is true:
    9.                 set {wearing_helmet::%loop-player%} to false
    10.                 remove swiftness from the loop-player
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,680
    Likes Received:
    115
    The problem with on armor equip events is there's so many events to cover. There's armor breaking, unequiping, equiping, and there's other commands I have that modify the users armour.
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    1,680
    Likes Received:
    115
    You could use the packet event that is sent whenever someone's armour/held item changes, but that would only work if someone could see that player. Alternatively, if you use the set slot packet (in the armor slots) and armor equip event both combined should cover any possibilities, or something like
    Code (Skript):
    1. on armor equip:
    2.   if event-item is iron chesplate:
    3.     apply speed to player for 9999 days
    4.     while player's chesplate is iron chestplate:
    5.       wait 1 tick
    6.     remove speed from player
     
    • Like Like x 1
Thread Status:
Not open for further replies.
Loading...