Solved Last person to hit a player before there mode gets changed.

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

Binjabin

New Member
Jun 18, 2021
9
0
1
22
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:
on gamemode change to spectator:
    if player is in "skywars1":
        make console execute command "/scoreboard players add %{x}% Points 100"
    loop all players:
        if gamemode of loop-player is survival:
            if loop-player is in "skywars1":
            make console execute command "/scoreboard players add %loop-player% Points 10"
        
    if player is in "Skywars2":
        make console execute command "/scoreboard players add %{x}% Points 100"
        loop all players:
        if gamemode of loop-player is survival:
                if loop-player is in "Skywars2":
            make console execute command "/scoreboard players add %loop-player% Points 10"
    if player is in "Skywars3":
    make console execute command "/scoreboard players add %{x}% Points 100"
    loop all players:
        if gamemode of loop-player is survival:
            if loop-player is in "Skywars3":
            make console execute command "/scoreboard players add %loop-player% Points 10"
    if player is in "MainLobby":
        make console execute command "/scoreboard players add %{x}% Points 100"
    loop all players:
        if gamemode of loop-player is survival:
        if loop-player is in "MainLobby":
            make console execute command "/scoreboard players add %loop-player% Points 10"


on damage of player:
    if attacker is a player:
        if attacker != attacked:
        set {x} to attacker
            make console execute command "/say %{x}% "

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
 
this might work
Code:
on quit:
  delete {lasthit::%player%}
  delete {lasthit2::%player%}

on damage:
  if victim is not attacker:
    set {lasthit::%victim%} to attacker
    set {lasthit2::%victim%} to now

on gamemode switch:
  if {lasthit::%player%} is set:
    if difference between now and {lasthit2::%player%} is less than 10 seconds:
      make console execute command "/scoreboard players add %{lasthit::%player%}% Points 100"
      delete {lasthit::%player%}
      delete {lasthit2::%player%}
 
this might work
Code:
on quit:
  delete {lasthit::%player%}
  delete {lasthit2::%player%}

on damage:
  if victim is not attacker:
    set {lasthit::%victim%} to attacker
    set {lasthit2::%victim%} to now

on gamemode switch:
  if {lasthit::%player%} is set:
    if difference between now and {lasthit2::%player%} is less than 10 seconds:
      make console execute command "/scoreboard players add %{lasthit::%player%}% Points 100"
      delete {lasthit::%player%}
      delete {lasthit2::%player%}
What are last hit and last hit 2 in this?
 
Status
Not open for further replies.