Solved How to check the block under the block i hit

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

LeyTrack

New Member
Apr 8, 2021
5
1
3
29
Hello everyone!
Well, I am starting to use script and I am having a hard time getting the result I want.
I am trying that when hitting an arrow in a bell, depending on the type of block that has underneath the bell, execute a command

I have achieved a similar result with the following code

Code:
on projectile hit:
    shooter is a player:
        if projectile is an arrow:
            loop blocks in radius 3 of projectile:
                loop-block is bell:
                    if block 2 under loop-block is bedrock:
                        delete projectile
                        make shooter say "hello"

Skrip version: 2.5.3
Minecraft version: 1.16.5

But how can I make it run only when the arrow hits the bell? because currently it runs whenever the arrow falls within 3 blocks of a bell
it doesn't matter if I hit it or not
and if I reduce the radius of the loop to less than 2, it doesn't always detect hits, I don't know why

I've tried looking for solutions in the forum but can't find anything to help me

I hope you understand what I mean, English is not my native language
Greetings to all and thanks
 
Use below
Code:
on projectile hit:
    shooter is a player:
        if projectile is an arrow:
            loop blocks in radius 3 of projectile:
                loop-block is bell:
                    if block 2 below loop-block is bedrock:
                        delete projectile
                        make shooter say "hello"
If it doesnt work use block 2 meters below loop-block
 
Use below
Code:
on projectile hit:
    shooter is a player:
        if projectile is an arrow:
            loop blocks in radius 3 of projectile:
                loop-block is bell:
                    if block 2 below loop-block is bedrock:
                        delete projectile
                        make shooter say "hello"
If it doesnt work use block 2 meters below loop-block

It works the same way, my goal is to make it run only when I hit the bell.
This way it runs even when I hit the blocks next to it
your two answers have exactly the same result

what I think is missing is to check when the arrow hits a "bell" block
something like "if projectile hit a bell"
but I don't know how to get the block it hits

Still thanks for your answer!
 
Code:
on projectile hit:
  shooter is player:
    projectile is arrow:
      block at location of projectile is bell:
        #code
 
Code:
on projectile hit:
  shooter is player:
    projectile is arrow:
      block at location of projectile is bell:
        #code
Hmm for some reason it only works 1 out of 100 times, as if it did not detect that it is hitting a bell
I had already tried this before and that is why I ended up asking in the forum

I have also tried many other blocks with the same result, it is not because it is a bell
 
do you use any addons? try disabling some of them or installing other ones (they might have messed up block id's or syntaxes)
try using event-block (it may work)
[doublepost=1617973470,1617973380][/doublepost]Block getHitBlock()
Gets the block that was hit, if it was a block that was hit.
i found this on the forums maybe try skript mirror?
 
skript-reflect and event.getHitBlock() it works like a marvel! thanks a lot!

Code:
on projectile hit:
    projectile is arrow:
        shooter is player:
            if event.getHitBlock() is bell:
                make shooter say "hit"
 
Last edited:
  • Like
Reactions: PatoFrango
Status
Not open for further replies.