Solved Metadata value "attacker" in on death:

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

TimmieTRM

New Member
Jan 17, 2022
5
1
3
19
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:
TimmieTRM was exploded by *TimmieTRM1426's TNT.

Instead, I'm getting this:
Code:
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:
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:
on place:
    set metadata value "attacker" of event-block to "%player%"
    message "%metadata value "attacker" of event-block% placed %event-block%"
 
on death of player:
    if attacker is set:
       if attacker is TNT:
           set {_attacker} to metadata value "attacker" of attacker
           set {_attacker} to {_attacker} parsed as player
           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.
[doublepost=1642617176,1642434397][/doublepost]I still haven't been able to fix this issue I'm currently having. Has anyone found a solution?
[doublepost=1643207236][/doublepost]Still nothing..
 
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:
on explosion prime:
    set {_a} to metadata value "attacker" of block at location
    set metadata value "attacker" of entity to {_a}
    
on place of tnt:
    set metadata value "attacker" of block to player
    
on death of player:
    attacker is tnt
    set {_a} to metadata value "attacker" of attacker
    set death message to "%victim% was exploded by %{_a}%'s %attacker%"
 
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.

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

 
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).
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
 
Last edited:
This'll certainly help with continuing on and hopefully finishing my idea. Thank you for your help! :emoji_grinning:

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