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 out 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 a

Discussion in 'Skript' started by Adrihun, Feb 27, 2017.

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

    Adrihun Member

    Joined:
    Feb 1, 2017
    Messages:
    368
    Likes Received:
    6
    a
     
    #1 Adrihun, Feb 27, 2017
    Last edited: Mar 26, 2017
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    234
    Instead of using a periodical to remove 1 from the variable, just do it in the "on damage" event.


    Code (Skript):
    1. loop 10 times:
    2.     wait 1 second
    3.     remove 1 from {qal::%victim%}
    4.     remove 1 from {qal::%attacker%}
    Just add something like that, but do a check so that if the on damage is triggered again, it doesn't continue running that loop and restarts it.
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    234
    It really doesn't lag, I've had 45 people on a server looping all of them more than once a second, and I managed around 19.85 TPS on a non dedicated server. I wouldn't worry about it.
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    234
    You can fix your issue by using the Skript expression: "difference (between|of) %object% and %object%", it basically checks the difference between two values.


    Code (Skript):
    1.  
    2. on damage:
    3.     if victim is a player:
    4.         if attacker is a player:
    5.             set {qal::%victim%} to now
    6.             set {qal::%attacker%} to now
    7.             if {victim::%attacker%} is not set:
    8.                 set {victim::%attacker%} to "%victim%"
    9.                 stop
    10.             else:
    11.                 if {victim::%attacker%} is not "%victim%":
    12.                     set {victim::%attacker%} to "%victim%"
    13.                     stop
    14. on quit:
    15.     if difference between {qal::%player%} and now is less than 10 seconds:
    16.         kill player
    17.        
    18. on command "/spawn":
    19.     if difference between {qal::%player%} and now is less than 10 seconds:
    20.         message "&cYou are currently in combat and can't execute that command."
    21.         cancel event
    22.        
    23. on command "/home":
    24.     if difference between {qal::%player%} and now is less than 10 seconds:
    25.         message "&cYou are currently in combat and can't execute that command."
    26.         cancel event
    27.        
    28. on command "/hub":
    29.     if difference between {qal::%player%} and now is less than 10 seconds:
    30.         message "&cYou are currently in combat and can't execute that command."
    31.         cancel event
    32.        
    33. on command "/lobby":
    34.     if difference between {qal::%player%} and now is less than 10 seconds:
    35.         message "&cYou are currently in combat and can't execute that command."
    36.         cancel event
    37.        
    38. on command "/back":
    39.     if difference between {qal::%player%} and now is less than 10 seconds:
    40.         message "&cYou are currently in combat and can't execute that command."
    41.         cancel event
    42.  
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    234
    Here's a more efficient form of the script:

    Code (Skript):
    1.  
    2. on death:
    3.     clear {qal::%victim%}
    4.     clear {qal::%attacker%} #You may want to remove this line to accommodate for PvP w/ more than 2 players
    5.  
    6. on damage:
    7.     if victim is a player:
    8.         if attacker is a player:
    9.             set {qal::%victim%} to now #This is now a time variable, which will make this script much more efficient
    10.             set {qal::%attacker%} to now #This is also a time var now
    11.             if {victim::%attacker%} is not set:
    12.                 set {victim::%attacker%} to victim #This can just be 'victim' rather than '"%victim%"'
    13.                 stop
    14.             else:
    15.                 if {victim::%attacker%} is not victim:
    16.                     set {victim::%attacker%} to victim
    17.                     stop
    18.  
    19. on quit:
    20.     if difference between now and {qal::%player%} is less than 10 seconds: #Changed since we're using a time var now
    21.         kill player
    22.  
    23. on command "/spawn":
    24.     if difference between now and {qal::%player%} is less than 10 seconds:
    25.         message "&cYou are currently in combat and can't execute that command."
    26.         cancel event
    27.  
    28. on command "/home":
    29.     if difference between now and {qal::%player%} is less than 10 seconds:
    30.         message "&cYou are currently in combat and can't execute that command."
    31.         cancel event
    32.  
    33. on command "/hub":
    34.     if difference between now and {qal::%player%} is less than 10 seconds:
    35.         message "&cYou are currently in combat and can't execute that command."
    36.         cancel event
    37.  
    38. on command "/lobby":
    39.     if difference between now and {qal::%player%} is less than 10 seconds:
    40.         message "&cYou are currently in combat and can't execute that command."
    41.         cancel event
    42.  
    43. on command "/back":
    44.     if difference between now and {qal::%player%} is less than 10 seconds:
    45.         message "&cYou are currently in combat and can't execute that command."
    46.         cancel event
    47.  
    48. on login:
    49.     if difference between now and {qal::%player%} is greater than 10 seconds:
    50.         clear {qal::%player%} #Clears the unnecessary stored value
    51.  
    --- Double Post Merged, Feb 27, 2017, Original Post Date: Feb 27, 2017 ---
    Jinx!
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    234
    you posted like 20 mins ago, don't bump...
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    234

    Yep, remove the "clear {qal::%attacker%}" if you don't want players to get unflagged right after killing someone. That way, that can't kill one player to escape another. But that also means they'll have to wait 10 seconds after killing someone to do anything, so your call.

    I don't think those entity errors will be problem since you'd want the PvP vars to reset after a restart anyway. But if it does cause issues, set the vars to 'uuid of victim' instead, as that will be saved through a restart.
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    234
    Nah, there isn't any way as far as I'm aware.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...