Help with checking there is a clear view of the sky?

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

Akaramine

New Member
Apr 12, 2017
9
0
0
41
I have an object that's used to teleport a player to a saved location (works great!), but I only want it to work if the player has a clear view of the sky.

I tried searching here and couldn't find anything, so I apologize if there is something here already and I missed it.

How do I go about checking if there are any blocks between the player and sky?

Thanks!
 
code_language.skript:
on command /useobject: #or on right click with "object"
  set {clearsky.%player%.altitude} to player's y-coordinate
  loop blocks from the block above the player to the block block %integer of 256 minus {clearsky.%player%.altitude}% above the player:
    if the loop-blocks are equal to air:
    #do stuff
    else:
    #do stuff
Not tested.
 
Thanks! I'll give this a shot as soon as I get a chance
[doublepost=1492033206,1492025364][/doublepost]getting this.

code_language.skript:
Can't understand this loop: 'loop blocks from the block above the player to the block block %integer of 256 minus {clearsky.%player%.altitude}% above the player' (test.sk, line 3: loop blocks from the block above the player to the block block %integer of 256 minus {clearsky.%player%.altitude}% above the player:')
 
loop blocks from the block above the player to the block %integer of 256 minus {clearsky.%player%.altitude}% above the player:
 
same result

Ok I tried it by just using "loops blocks above the player"

it works, but It performs the "else" result for every block that is air. I added a stop for when it isn't air or it peforms that one for every block that isn't air.

Actually i think that will work if i use an if the loop block isn't air, stop. And have it continue only if all blocks are air, otherwise the whole script stops. Not putting it in a "else" statement

I'll paste my example
 
code_language.skript:
on command /useobject: #or on right click with "object"
 loop blocks above the player: 
    if all the loop-blocks are equal to air:
    #do stuff
    else:
    #do stuff

maybe by adding "if all"?
 
this does it! Thanks for getting me on the right track

Code:
on right click:
    set {clearsky.%player%.altitude} to player's y-coordinate
    loop blocks above the player:
        if the loop-blocks are not equal to air:
            send "BLOCKS"
            stop
    send "ALL CLEAR"

I remembered running into this before with loops when creating a blacklist. Same approach worked here as well
 
You don't need the "set {clearsky.%player%.altitude} to player's y-coordinate" line.

Remove it.

code_language.skript:
on right click:
    loop blocks above the player:
        if the loop-blocks are not equal to air:
            send "BLOCKS"
            stop
    send "ALL CLEAR"
 
Status
Not open for further replies.