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 Metadata value "attacker" in on death:

Discussion in 'Skript' started by TimmieTRM, Jan 17, 2022.

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

    TimmieTRM New Member

    Joined:
    Jan 17, 2022
    Messages:
    5
    Likes Received:
    1
    Skript Version (do not put latest): Skript 2.6
    Skript Author: Bensku
    Minecraft Version: 1.17.1
    ---
    I apologize for the weird lay-out, this is my very first post.


    Description:
    When a player places TNT, my skript proceeds to store whoever placed the TNT's name. If a player dies to this specific TNT, a death message appears in chat with the victim's name, the name of whoever placed the TNT and the victim's cause of death; in this case, TNT.

    I'm doing this to give credit to whoever managed to kill someone with TNT. I want to do the same thing with all the common items you can kill someone with (e.g. lava, gravel, anvil) later on. I need this 'kill register' for future reference.

    The death message should be the following:
    Code (Text):
    1. TimmieTRM was exploded by *TimmieTRM1426's TNT.
    Instead, I'm getting this:
    Code (Text):
    1. TimmieTRM was exploded by <none>'s TNT.
    I'm thinking something is going wrong when storing the metadata value into a variable in the on death of player, but I can't seem to fix this:
    Code (Text):
    1. set {_attacker} to metadata value "attacker" of attacker
    The full code has been included below. Is there anything who knows what the problem is? Thanks in advance. :emoji_grinning:


    Full Code:
    Code (Text):
    1. on place:
    2.     set metadata value "attacker" of event-block to "%player%"
    3.     message "%metadata value "attacker" of event-block% placed %event-block%"
    4.  
    5. on death of player:
    6.     if attacker is set:
    7.        if attacker is TNT:
    8.            set {_attacker} to metadata value "attacker" of attacker
    9.            set {_attacker} to {_attacker} parsed as player
    10.            set death message to "%victim% was exploded by %{_attacker}%'s %attacker%"

    Errors on Reload/Console Errors:
    There are no errors on Reload or in Console.


    Addons using (including versions):
    Skript v2.6, SkQuery v4.1.4, Skellet v1.9.1.1

    Troubleshooting:

    Have you tried searching the docs? Yes. I took a look at on death:, death messages and metadata.
    Have you tried searching the forums? Yes. This is the closest I've gotten: https://forums.skunity.com/threads/get-the-attacker-of-a-tnt.6812/
    What other methods have you tried to fix it? I tried several ways of storing the metadata and using the metadata in the on death: event. Nothing has worked so far.
    --- Double Post Merged, Jan 19, 2022, Original Post Date: Jan 17, 2022 ---
    I still haven't been able to fix this issue I'm currently having. Has anyone found a solution?
    --- Double Post Merged, Jan 26, 2022 ---
    Still nothing..
     
  2. Best Answer:
    Post #2 by Goose, Jan 26, 2022
  3. Goose

    Supporter

    Joined:
    Nov 23, 2019
    Messages:
    429
    Likes Received:
    30
    When you place the TNT, the metadata value of the block is set, but when the TNT is primed, the block is deleted and a primed TNT entity is spawned. This new entity will NOT have the metadata value set. You would have to set the metadata value of the entity when the TNT is primed.

    Try this.
    Code (Text):
    1. on explosion prime:
    2.     set {_a} to metadata value "attacker" of block at location
    3.     set metadata value "attacker" of entity to {_a}
    4.    
    5. on place of tnt:
    6.     set metadata value "attacker" of block to player
    7.    
    8. on death of player:
    9.     attacker is tnt
    10.     set {_a} to metadata value "attacker" of attacker
    11.     set death message to "%victim% was exploded by %{_a}%'s %attacker%"
     
    • Friendly Friendly x 1
  4. TimmieTRM

    TimmieTRM New Member

    Joined:
    Jan 17, 2022
    Messages:
    5
    Likes Received:
    1
    Oh, that's it! Thanks a bunch. I didn't realize the primed TNT would be a "new block", so it indeed never set the metadata value for the primed TNT..

    Now that I have something to work with, is there any way for me to find a list of all "attackers" that you can use with Skript, besides TNT? I'm hoping to cover most of the death messages that usually don't mention an attacker AND a victim (e.g. "TimmieTRM tried to swim in lava" -> the person who killed TimmieTRM with lava doesn't get credit for this kill).

     
  5. Goose

    Supporter

    Joined:
    Nov 23, 2019
    Messages:
    429
    Likes Received:
    30
    You can use the following syntax elements to check why somebody died:
    https://skripthub.net/docs/?id=1144 (Condition)
    https://skripthub.net/docs/?id=2140 (Expression)

    These can be used to avoid setting the attacker metadata value when the player is damaged, assuming the following (or similar) process:
    - Victim is attacked by player, metadata value is set
    - Attacker places lava on victim
    - Victim is damaged by lava, metadata value remains the same because the damage cause is lava
    - Victim dies, attacker gets kill credit
     
    #4 Goose, Jan 27, 2022
    Last edited: Jan 27, 2022
    • Informative Informative x 1
  6. TimmieTRM

    TimmieTRM New Member

    Joined:
    Jan 17, 2022
    Messages:
    5
    Likes Received:
    1
    This'll certainly help with continuing on and hopefully finishing my idea. Thank you for your help! :emoji_grinning:

    Consider this post SOLVED!
     
Thread Status:
Not open for further replies.

Share This Page

Loading...