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 Last person to hit a player before there mode gets changed.

Discussion in 'Skript' started by Binjabin, Jun 18, 2021.

Tags:
Thread Status:
Not open for further replies.
  1. Binjabin

    Binjabin New Member

    Joined:
    Jun 18, 2021
    Messages:
    9
    Likes Received:
    0
    Hi SKUnity

    I was writing a skript to award 100 points to the "killer", and 10 points to everyone still alive, but the issue is the when the player is "killed" in the plugin i am using (Skywars reloaded), they don't actually die in game, just get turned into spectator mode.

    This makes it difficult to award points to the killer, since you can only use "attacker" in death damage or destruction events, not game-mode changes. This means I have to work out the most recent player to hit them when there mode changes, and award the points to them. I have mostly done this, and it works when you directly kill a player, but it doesn't always when the player dies some other way, EG burning.

    Nevertheless, here is what i have so far...

    Skript Version : Skript 2.6
    Skript Author: Bensku
    Minecraft Version: 1.16.5
    ---

    Code (Text):
    1.  
    2. on gamemode change to spectator:
    3.     if player is in "skywars1":
    4.         make console execute command "/scoreboard players add %{x}% Points 100"
    5.     loop all players:
    6.         if gamemode of loop-player is survival:
    7.             if loop-player is in "skywars1":
    8.             make console execute command "/scoreboard players add %loop-player% Points 10"
    9.        
    10.     if player is in "Skywars2":
    11.         make console execute command "/scoreboard players add %{x}% Points 100"
    12.         loop all players:
    13.         if gamemode of loop-player is survival:
    14.                 if loop-player is in "Skywars2":
    15.             make console execute command "/scoreboard players add %loop-player% Points 10"
    16.     if player is in "Skywars3":
    17.     make console execute command "/scoreboard players add %{x}% Points 100"
    18.     loop all players:
    19.         if gamemode of loop-player is survival:
    20.             if loop-player is in "Skywars3":
    21.             make console execute command "/scoreboard players add %loop-player% Points 10"
    22.     if player is in "MainLobby":
    23.         make console execute command "/scoreboard players add %{x}% Points 100"
    24.     loop all players:
    25.         if gamemode of loop-player is survival:
    26.         if loop-player is in "MainLobby":
    27.             make console execute command "/scoreboard players add %loop-player% Points 10"
    28.  
    29.  
    30. on damage of player:
    31.     if attacker is a player:
    32.         if attacker != attacked:
    33.         set {x} to attacker
    34.             make console execute command "/say %{x}% "
    35.  
    There are no errors in the code, However, the issue is that all the players share the same x variable, meaning if someone dies, the person who hit them last won't get the points if someone has been damaged since then. Is there an easy way to make it so that each player has there own x variable? Maybe something like {player's x}?

    Any help appreciated, Thanks.



    Other Useful Info
    Addons using (including versions): None
    Troubleshooting:
    Have you tried searching the docs?
    Yes
    Have you tried searching the forums? Yes
     
  2. Best Answer:
    Post #2 by Minecoll_YT, Jun 18, 2021
  3. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    this might work
    Code (Text):
    1. on quit:
    2.   delete {lasthit::%player%}
    3.   delete {lasthit2::%player%}
    4.  
    5. on damage:
    6.   if victim is not attacker:
    7.     set {lasthit::%victim%} to attacker
    8.     set {lasthit2::%victim%} to now
    9.  
    10. on gamemode switch:
    11.   if {lasthit::%player%} is set:
    12.     if difference between now and {lasthit2::%player%} is less than 10 seconds:
    13.       make console execute command "/scoreboard players add %{lasthit::%player%}% Points 100"
    14.       delete {lasthit::%player%}
    15.       delete {lasthit2::%player%}
     
  4. Binjabin

    Binjabin New Member

    Joined:
    Jun 18, 2021
    Messages:
    9
    Likes Received:
    0
    What are last hit and last hit 2 in this?
     
  5. Minecoll_YT

    Supporter Forums Helper

    Joined:
    Dec 2, 2018
    Messages:
    650
    Likes Received:
    39
    {lasthit::%player%} is set to the name of the attacker
    {lasthit2::%player%} is the time when he got hit
     
  6. Binjabin

    Binjabin New Member

    Joined:
    Jun 18, 2021
    Messages:
    9
    Likes Received:
    0
    Yeah, i used the timing and it worked great thanks.
     
Thread Status:
Not open for further replies.

Share This Page

Loading...