Solved Get the attacker of a tnt

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

KroterPvP

Active Member
Apr 10, 2017
178
7
18
22
I'm having troubles when getting the attacker in my skript. I will explain it a bit. The script spawns a primed tnt and sometimes the player gets killed by it. The problem is that skript doesn't know who was the person who killed the player (I'm trying to know who placed the tnt storing it in a variable but I can't do it).
code_language.skript:
on rightclick with tnt:
    name of player's tool is "&eTNT &7(Click derecho)":
        clicked block is not air:
            if "%region at player%" contains "lobby":
                stop
            else:
                set {tntof::%player%} to player
                send "%{tntof::%player%}%" to player
                set {_block.loc} to block 1 up event-location
                if block at {_block.loc} is air:
                    remove 1 tnt from player's inventory
                    spawn 1 primed TNT at location of {_block.loc}
                    set fuse time of last spawned primed tnt to 60
                else:
                    send "&7Busca espacio en el suelo para utilizar explosivos"
        else:
            send "&7Mira al suelo para utilizar explosivos"
on damage:
#The problem is that using attacker here will not be 100%
#efficient because It will be refired to the last player who
#hitted victim and not the player who placed the tnt.
    if {tntof::%attacker%} is set:
        #do stuff

- No console errors.
- Skript 2.2 Bensku dev24, SkRayFall, QkQuery, Skellet (I'm using them for other skripts, not for this one).

Thanks
 
Last edited:
I'm having troubles when getting the attacker in my skript. I will explain it a bit. The script spawns a primed tnt and sometimes the player gets killed by it. The problem is that skript doesn't know who was the person who killed the player (I'm trying to know who placed the tnt storing it in a variable but I can't do it).
code_language.skript:
on rightclick with tnt:
    name of player's tool is "&eTNT &7(Click derecho)":
        clicked block is not air:
            if "%region at player%" contains "lobby":
                stop
            else:
                set {tntof::%player%} to player
                send "%{tntof::%player%}%" to player
                set {_block.loc} to block 1 up event-location
                if block at {_block.loc} is air:
                    remove 1 tnt from player's inventory
                    spawn 1 primed TNT at location of {_block.loc}
                    set fuse time of last spawned primed tnt to 60
                else:
                    send "&7Busca espacio en el suelo para utilizar explosivos"
        else:
            send "&7Mira al suelo para utilizar explosivos"
on damage:
#The problem is that using attacker here will not be 100%
#efficient because It will be refired to the last player who
#hitted victim and not the player who placed the tnt.
    if {tntof::%attacker%} is set:
        #do stuff

- No console errors.
- Skript 2.2 Bensku dev24, SkRayFall, QkQuery, Skellet (I'm using them for other skripts, not for this one).

Thanks
I do not know if this will work, but you can try:

code_language.skript:
remove 1 of tnt from player's inventory
spawn 1 primed TNT at location of {_block.loc}
set metadata value "attacker" of last spawned primed tnt to "%player%"
set fuse time of last spawned primed tnt to 60

#something along these lines
on damage:
    set {_attacker} to metadata value "attacker" of attacker
    set {_attacker} to {_attacker} parsed as player
 
I do not know if this will work, but you can try:

code_language.skript:
remove 1 of tnt from player's inventory
spawn 1 primed TNT at location of {_block.loc}
set metadata value "attacker" of last spawned primed tnt to "%player%"
set fuse time of last spawned primed tnt to 60

#something along these lines
on damage:
    set {_attacker} to metadata value "attacker" of attacker
    set {_attacker} to {_attacker} parsed as player
Yep, it's running :emoji_slight_smile:

Thanks
 
Status
Not open for further replies.