Solved Set block to face the player

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

CKR367

Member
Feb 1, 2017
64
2
0
Why is this code not working? I am trying to set the block as a chest, and make it face the player.

code_language.skript:
set block at location of {_chest} to chest horizontally facing the player

I keep getting this error.
[18:53:32 ERROR]: a block can't be set to 'chest to horizontally face the player' because the latter is not an item type
 
Make use of THE player facing expression so you can See which way THE player is looking north east South west then you can use this together with metadata
 
Example please?
code_language.skript:
On place of chest:
   Cancel event
   Set {_dir} To direction of player
   If "%{_dir}%" is "north":
      Set block at event-location To chest:1

I didn't add all THE directions And THE metadata :1 might be already correct with THE north direction but i don't know THE directions together with THE metadata so that you need To test for your self
 
code_language.skript:
On place of chest:
   Cancel event
   Set {_dir} To direction of player
   If "%{_dir}%" is "north":
      Set block at event-location To chest:1

I didn't add all THE directions And THE metadata :1 might be already correct with THE north direction but i don't know THE directions together with THE metadata so that you need To test for your self

It is not understanding when I set a variable to the players direction. Here is my full code of what I am trying to accomplish:

code_language.skript:
command /startitems:
    executable by: players
    trigger:
        if player is op:
            message "&aDropping starting items..."
            spawn falling block of oak plank at block 150 blocks above location (-49, 65, 676)
            set {_chest} to last spawned entity
            loop 30 times:
                launch "BALL" firework at location of {_chest} timed 0 coloured yellow
                loop firework rockets in radius 1 of {_chest}:
                    add "{LifeTime:1}" to nbt of loop-entity
                wait 0.2 seconds
            launch "BALL_LARGE" firework at location of {_chest} timed 0 coloured yellow
            loop firework rockets in radius 1 of {_chest}:
                add "{LifeTime:2}" to nbt of loop-entity
            set block at location of {_chest} to chest
            set {_chestinv} to block at location of {_chest}
            set slot 10 of {_chestinv} to compass named "&b&lMiner's Compass"
            stop trigger
        else:
            message "&cYou do not have permission to do this."
            stop trigger
It is a command the spawns a falling chest with items in it, and when it hits the ground, I want it to face the player.
 
I made some functions that allow you to set a block facing a player. There are ways in Skript todo this, but I gave up finding them and made some functions. Here are some useful stuff that sets the block to face the player

code_language.skript:
function getOppositeDirection(d: direction) :: direction:
    set {_s} to "%{_d}%"
    loop {_s} split at "and":
        if {_direction} is not set:
            set {_direction} to "%numbers in loop-value%" parsed as number
            set {_final} to loop-value
        else if "%the numbers in loop-value%" parsed as number > {_direction}:
            set {_direction} to "%numbers in loop-value%" parsed as number
            set {_final} to loop-value
    if {_final} contains "north":
        return north
    else if {_final} contains "east":
        return east
    else if {_final} contains "south":
        return south
    else if {_final} contains "west":
        return west
function getDirectionalBlock(i: item, d: direction) :: item:
    set {_block::north} to 1
    set {_block::south} to 3
    set {_block::west} to 4
    set {_block::east} to 5
    return "%{_i}%:%{_block::%{_d}%}%" parsed as item
command /chest:
    trigger:
        set {_direction} to direction from target block to player
        set {_opposite} to getOppositeDirection({_direction})
        set {_block} to getDirectionalBlock(chest, {_opposite})
        set target block to {_block}
Basically when you run the command /chest it will set the target block to a chest facing you.

Needs Skellett and SkQuery
 
Ya, No it can't...

If it didn't, why would I put Skellett as a required? The less addons the better.

Yeah, I can't... jk, I can:
code_language.skript:
function numbersIn(string: string) :: number:
    set {_return} to ""
    loop {_string} split by "":
        set {_num} to loop-value parsed as num
        if {_num} is set:
            "%{_num}%" = "%loop-value%"
            set {_return} to "%{_return}%%{_num}%"
    return {_return} parsed as num
   
   
function getOppositeDirection(direction: direction) :: direction:
    loop split "%{_direction}%" by "and":
        if {_dir} is not set:
            set {_dir} to numbersIn(loop-value)
            set {_final} to loop-value
        else if numbersIn(loop-value) > {_dir}:
            set {_dir} to numbersIn(loop-value)
            set {_final} to loop-value
    if {_final} contains "north":
        return north
    else if {_final} contains "east":
        return east
    else if {_final} contains "south":
        return south
    else if {_final} contains "west":
        return west
       
function getDirectionalBlock(i: item, d: direction) :: item:
    set {_block::north} to 1
    set {_block::south} to 3
    set {_block::west} to 4
    set {_block::east} to 5
    return "%{_i}%:%{_block::%{_d}%}%" parsed as item
   
command /chest:
    trigger:
        set {_direction} to direction from target block to player
        set {_opposite} to getOppositeDirection({_direction})
        set {_block} to getDirectionalBlock(chest, {_opposite})
        set target block to {_block}
 
Yeah, I can't... jk, I can:
code_language.skript:
function numbersIn(string: string) :: number:
    set {_return} to ""
    loop {_string} split by "":
        set {_num} to loop-value parsed as num
        if {_num} is set:
            "%{_num}%" = "%loop-value%"
            set {_return} to "%{_return}%%{_num}%"
    return {_return} parsed as num
  
  
function getOppositeDirection(direction: direction) :: direction:
    loop split "%{_direction}%" by "and":
        if {_dir} is not set:
            set {_dir} to numbersIn(loop-value)
            set {_final} to loop-value
        else if numbersIn(loop-value) > {_dir}:
            set {_dir} to numbersIn(loop-value)
            set {_final} to loop-value
    if {_final} contains "north":
        return north
    else if {_final} contains "east":
        return east
    else if {_final} contains "south":
        return south
    else if {_final} contains "west":
        return west
      
function getDirectionalBlock(i: item, d: direction) :: item:
    set {_block::north} to 1
    set {_block::south} to 3
    set {_block::west} to 4
    set {_block::east} to 5
    return "%{_i}%:%{_block::%{_d}%}%" parsed as item
  
command /chest:
    trigger:
        set {_direction} to direction from target block to player
        set {_opposite} to getOppositeDirection({_direction})
        set {_block} to getDirectionalBlock(chest, {_opposite})
        set target block to {_block}
That's twice as long and not needed.
 
Status
Not open for further replies.