How to check if clicked block is at specific coordinates?

  • Thread starter Deleted member 1700
  • Start date
  • 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 community!

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

Deleted member 1700

Skript Version: 2.2-dev31c
Skript Author: Njol, Mirreski, bensku, TheBentoBox, tim740, Tuke-Nuke, TheLimeGlass, xXAndrew28Xx, Sashie, RoyCurtis, nfell2009, Syst3ms and Snow-Pyon
Minecraft Version: 1.12
---
Full Code:

code_language.skript:
on click:
   if location of clicked block is location 100, 100, 100 in world "world":
       message "You clicked on the block!"
       cancel event

Troubleshooting:

Have you tried searching the docs? Yes
Have you tried searching the forums? Yes
What other methods have you tried to fix it?
I tried to put the location in a variable and different ways of typing it. Without the if the event works on every block. I only want it to work on the block at specific coordinates.
 
try
code_language.skript:
location at 100, 100, 100 of the world "world":
 
try
code_language.skript:
location at 100, 100, 100 of the world "world":
code_language.skript:
on click:
    if location of clicked block is location at 100, 100, 100 of the world "world":
        message "You clicked on the block!"
        cancel event

This still doesn't work. Any ideas?
 
hmm.... odd, this is often silly but sometimes works
try put a hyphen in clicked block
like clicked-block
[doublepost=1523996706,1523996624][/doublepost]or maybe try location of target-block
 
hmm.... odd, this is often silly but sometimes works
try put a hyphen in clicked block
like clicked-block
[doublepost=1523996706,1523996624][/doublepost]or maybe try location of target-block
Also doesn't work. I get the error "Can't compare 'location of clicked-block' with a location". Trying event-block doesn't give me any errors, but also doesn't work.
 
hmm im going to need to test this out.... ill get back to you
 
If all of that doesnt work, you can try using
code_language.skript:
if x-coordinate of event-block is 100:
    if y-coordinate of event-block is 100:
        if z-coordinate of event-block is 100:
            #do something
[doublepost=1523997472,1523997439][/doublepost]Its not the best way, and I think there is a better way for it, but it works :emoji_slight_smile:
 
okay so odd news
I found a block in my world and set the coords to the block
code_language.skript:
on right-click:
    if location of target block is location at 832, 69, -4812 of the world "world":
        send "You clicked on the block!" to player
        cancel event
Did not work
So then, I set it to call back to me the actual coords of the target block and sure enough each coord ends in .5
So i added .5 to each of my location variables
Did this and it worked
code_language.skript:
on right-click:
    if location of target block is location at 832.5, 69.5, -4811.5 of the world "world":
        send "You clicked on the block!" to player
        cancel event
 
okay so odd news
I found a block in my world and set the coords to the block
code_language.skript:
on right-click:
    if location of target block is location at 832, 69, -4812 of the world "world":
        send "You clicked on the block!" to player
        cancel event
Did not work
So then, I set it to call back to me the actual coords of the target block and sure enough each coord ends in .5
So i added .5 to each of my location variables
Did this and it worked
code_language.skript:
on right-click:
    if location of target block is location at 832.5, 69.5, -4811.5 of the world "world":
        send "You clicked on the block!" to player
        cancel event
It works! However, when I make any number negative, it doesn't anymore. I can only get this to work on positive coordinates. Any ideas?
 
i haven't a clue, since it is working for me
Wanna paste your code here and I'll take a look?

code_language.skript:
on click:
    if location of target block is location at -100.5, 100.5, -100.5 of the world "world":
        send "You clicked on the block!" to player
        cancel event
 
oh i know why.... try set your -100.5 to -99.5
This works for normal blocks, but this doesn't detect clicks on doors. Removing the "if" does detect clicks on doors. Any idea why that is? Do I need to do some weird coordinate rounding to get to the center of the actual door?
 
you could right a temp code to check the location of the block.

like
send "%location of target block%" to player
This will give you the details you will need to use
 
  • Like
Reactions: Deleted member 1700
you could right a temp code to check the location of the block.

like
send "%location of target block%" to player
This will give you the details you will need to use
Clicking the door gives "x: 100.5, y: 100.5, z: 100.5", exactly what I set it to.

Edit: I found a dirty way of doing this. Any idea if there's a better way to do this?
code_language.skript:
    if "%location of event-block%" is "x: 100.5, y: 100.5, z: 100.5":
        send "You clicked on the block!" to player
        cancel event
 
You should be able to rewrite this:
code_language.skript:
if "%location of event-block%" is "x: 100.5, y: 100.5, z: 100.5"
as this:
code_language.skript:
if location of event-block is location(100.5, 100.5, 100.5):

The location of a block is stored at the center of the block. For any location value (such as the value you see when looking at a block with the F3 debug menu open), you can get the actual block location as far as Bukkit is concerned by adding 0.5 to each of the coordinate values. For example, for the block at 100, 200, -50, the actual block location (if you were to send yourself "%location of event-block%") would be 100.5, 200.5, -49.5. You can see that if one of the coordinates is negative, you still just add 0.5.
 
Status
Not open for further replies.