#looping blocks around a beacon to check if its in the radius then set variable to true

1 messages · Page 1 of 1 (latest)

fossil crag
#

i tried to check so if a beacon placed playerscan only place defense around the beacon he own but it seems not working

#

thats for the defense part

on place:
    if event-block is a cracked stone bricks:
        if {togglebricks::%event-player's uuid%} is true:
            set int tag "custom;Health" of nbt compound of event-block to 250
            set string tag "custom;OwnerD" of nbt compound of event-block to "%uuid of event-player%"
            send action bar "{@prefix} &8›&f You have placed a defense brick!" to event-player
        else:
            if {togglebricks::%event-player's uuid%} is false:
                send action bar "{@prefix} &8›&f You can only place defense near your beacon! (RANGE 20 BLOCKS)"
                cancel event
#

beacon system

#

on place:
    if event-block is a beacon:
        if {beacon::%event-player's uuid%} is not set:
            set {beacon::%event-player's uuid%} to location of event-block
            play sound "block.note_block.pling" at volume 1 at pitch 2 to event-player
            send action bar "{@prefix} &8›&f You have placed a beacon successfully!"
            set {_loc} to event-block's location
            loop all blocks in radius 4 around {_loc}:
                if distance between loop-block and {_loc} is less than 4:
                    set {togglebricks::%event-player's uuid%} to true
        else:
            cancel event
            send action bar "{@prefix} &8›&f You already placed a beacon!" to event-player 
            play sound "entity.villager.no" at volume 1 at pitch 1 to event-player
        
fossil crag
#

@sly pewter

#

no one is helping idk why

#

but anyways

#

so i tried debugging everything

#

fixed code little

#

i checked that theres no problem with the looping or beacon system

#

its just the bricks when i place

#

so its set to true i can place and everything

#

and i still can place even if im out of range

#

and i debugged the variable is true even if its out of the range

sly pewter
#

Ok but none of the code you posted shows the problem of a players togglebrick being set to false when out of range

fossil crag
#
on place:
    if event-block is a beacon:
        if {beacon::%event-player's uuid%} is not set:
            set {beacon::%event-player's uuid%} to location of event-block
            play sound "block.note_block.pling" at volume 1 at pitch 2 to event-player
            send action bar "{@prefix} &8›&f You have placed a beacon successfully!"
            set {_loc} to event-block's location
            loop all blocks in radius 4 around {_loc}:
                if distance between loop-block and {_loc} is less than 4:
                    set loop-block to stone
                    set {togglebricks::%loop-player's uuid%} to true
                    broadcast "%{togglebricks::%loop-player's uuid%}%"
                else:
                    if distance between loop-block and {_loc} is higher than 4:
                        set {togglebricks::%loop-player's uuid%} to false
                        broadcast "%{togglebricks::%loop-player's uuid%}%"

sly pewter
#

....

#

loop-player is your problem

fossil crag
#

oh

sly pewter
#

also

#

Why do you have 2 if statements for the same thing?
You have
if distance between loop-block and {_loc} is less than 4:
then you have the else:
But right after the else, you have
if distance between loop-block and {_loc} is higher than 4:

The 2nd is useless, because if its going to the else then its either = or higher than 4

fossil crag
#

i got another problem

#

nvm i didnt solve it lol

sly pewter
#

What?

fossil crag
#

okay so

#

i tried doing that every 1 second it checks if player is in the radius then it sets to true but it wasnt working it was setting true and false repeating lol

#

i think i need to check if the defense bricks gets placed in the radius of the beacon then it works and if not it would cancel the event

#

it would work better because this is just setting when the beacon gets placed

#

so it wont work

sly pewter
#

Looping all players every tick to make sure theyre within radius of a beacon is a no no from me

fossil crag
#

im just gonna do that it checks everytime i place the defense bricks if its in the radius then everything goes fine

#

but how would i check if theres a beacon in the radius?

#
on place:
    if event-block is a cracked stone bricks:
        set int tag "custom;Health" of nbt compound of event-block to 250
        set string tag "custom;OwnerD" of nbt compound of event-block to %uuid of event-player%
        send action bar "{@prefix} &8›&f You have placed a defense brick!" to event-player
        set {_loc} to event-block's location
        loop all blocks in radius 4 around {_loc}:
            if distance between loop-block and {_loc} is less than 4:
                set {togglebricks::%event-player's uuid%} to true
                broadcast "%{togglebricks::%event-player's uuid%}%"
            else:
                set {togglebricks::%event-player's uuid%} to false
                broadcast "%{togglebricks::%event-player's uuid%}%"
sly pewter
#

why not save the location of the players beacon to var? and check that

fossil crag
sly pewter
#

Then just use that

fossil crag
#

i dont understand what you mean by check that

#

you mean checking the radius

#

of the var?

sly pewter
#

Use that location of the stone brick thats being placed, and get the distance from it to the beacon

fossil crag
#

so instead of looping?

#

i would do

set {_loc1} to event-block's location # defense
set {_loc2} to {beacon::%player's uuid% # beacon
if distance between {_loc2} anad {_loc1} is less than 4:
    # rest of the code
sly pewter
#

yup

north drift
#

i would make that a guard clause, if distance ... > 4: cancel event send "too far" to player stop #code here

fossil crag
#

also smurfy how would i check if the block above a gen is a hopper then it would spawn on top of the hopper?

#
every 8 seconds:
    loop all players:
        loop all blocks in radius 15 around loop-player:
            # COAL
            if {placedrgens::Coal::%loop-player's uuid%::*} contains loop-block's location:
                set {_l} to block above loop-value-2
                drop 1 of {drops::NOTE1} 1 meters above {_l} without velocity
                chance of 0.4%:
                    drop 1 of {drops::gem} 1 meters above {_l} without velocity
                    stop         
#

like checking if theres a hopper on top of the location then spawn above the location

#

@sly pewter

#

plus it worked the beacon and defense

north drift
#

noooo

#

thats really inefficient

#

just use like on join: while player is online: wait 8 seconds: loop {placedrgens::Coal::%loop-player's uuid%::*}: #drop

fossil crag
#

okay

fossil crag
#

@sly pewter heyy

north drift
#

just check the block above the loop-value

#

assuming the value is the location

fossil crag
#

okay