How do I make it so players can only break a certain block that they placed?

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

Derazzd

Member
Oct 21, 2022
2
0
1
22
on place of hay block:
if player's tool is hay block named "&e&lWheat Gen" with lore "&7-----&8-----" and "&7Produces wheat every 10 seconds" and "&7Upgrade cost: &e500⛃" and "&7-----&8-----":
set {gens::%location of event-block%} to uuid of player
if {gens::%player's uuid%} < 10:
set {Ownblocks::%event-block's location%} to event-player
add 1 to {gens::%player's uuid%}
play sound "block.note_block.pling" at volume 1 at pitch 2 to player
make 10 of poof at event-block
while event-block is hay block:
wait 80 ticks
drop 1 wheat named "&e&lWheat" with lore "&7-----&8-----" and "&eWorth 10⛃" and "&7-----&8-----" above location of event-block
else:
send "" to player
send "&bYou have reached your Gen Cap! &7%{gens::%player's uuid%}%&b/&710" to player
send "" to player
cancel event

on break of hay block:
if {Ownblocks::%event-block's location%} is not event-player:
send "&cSorry, that is not your gen. You cannot break it."
cancel event
else if {Ownblocks::%event-block's location%} is event-player:
set {Ownblocks::%event-block's location%} to false
set {gens::%location of event-block%} to location of event-block
remove 1 from {gens::%player's uuid%}
set event-block to air
play sound "block.note_block.pling" at volume 1 at pitch 1 to player
make 10 of poof above event-block
give player hay block named "&e&lWheat Gen" with lore "&7-----&8-----" and "&7Produces wheat every 10 seconds" and "&7Upgrade cost: &e500⛃" and "&7-----&8-----"



This should be enough of the code, I've tried to use Ownblocks as I found that on another forum post, but it's not working can anyone help?
 
thank you for readable format of code.
upload_2022-10-21_20-55-58.png
 
thank you for readable format of code.
View attachment 7153
POV that dude: No problem!

Codddddddde:
Code:
on place of hay block:
    if player's tool is hay block named "&e&lWheat Gen" with lore "&7-----&8-----" and "&7Produces wheat every 10 seconds" and "&7Upgrade cost: &e500⛃" and "&7-----&8-----":

        set {gens::%location of event-block%} to uuid of player

        if {gens::%player's uuid%} < 10:
            set {Ownblocks::%event-block's location%} to event-player
            add 1 to {gens::%player's uuid%}
            play sound "block.note_block.pling" at volume 1 at pitch 2 to player
            make 10 of poof at event-block
            while event-block is hay block:
                wait 80 ticks
                drop 1 wheat named "&e&lWheat" with lore "&7-----&8-----" and "&eWorth 10⛃" and "&7-----&8-----" above location of event-block
        else:
            send "" to player
            send "&bYou have reached your Gen Cap! &7%{gens::%player's uuid%}%&b/&710" to player
            send "" to player
            cancel event

on break of hay block:
    if {Ownblocks::%event-block's location%} is not event-player:
        send "&cSorry, that is not your gen. You cannot break it."
        cancel event
    else if {Ownblocks::%event-block's location%} is event-player:
        set {Ownblocks::%event-block's location%} to false
        set {gens::%location of event-block%} to location of event-block
        remove 1 from {gens::%player's uuid%}
        set event-block to air
        play sound "block.note_block.pling" at volume 1 at pitch 1 to player
        make 10 of poof above event-block
        give player hay block named "&e&lWheat Gen" with lore "&7-----&8-----" and "&7Produces wheat every 10 seconds" and "&7Upgrade cost: &e500⛃" and "&7-----&8-----"
This should be enough of the code, I've tried to use Ownblocks as I found that on another forum post, but it's not working can anyone help?


Ok after around 1 hour of hard work. (Many ppl have died) I got it working i think
Code:
# Contributors:
#   - Pierrelasse#3737
#   - Lolzy#7652
#   - DeafMole#2930

on load:
    set {-cache::wheatgen} to hay block named "&e&lWheat Gen" with lore "&7-----&8-----%nl%&7Produces wheat every 10 seconds%nl%&7Upgrade cost: &e500⛃%nl%&7-----&8-----"
    set {-cache::wheatdrop} to wheat named "&e&lWheat" with lore "&7-----&8-----%nl%&eWorth 10⛃%nl%&7-----&8-----"


on command:
    if command is "ggen":
        cancel event
        give {-cache::wheatgen} to player


on place of hay block:
    event is not cancelled
    if 1 of player's tool is {-cache::wheatgen}:

        set {_i} to 0
        loop {gens::*}:
            loop-value is player's uuid
            add 1 to {_i}

        if {_i} > 10 -1:
            send "%nl%&bYou reached your Gen-Cap! &7%{_i}%&8/&710%nl%"
            cancel event

        else:
            if {gens::%event-block's location%} is set:
                broadcast "&4%player% is tryin to exploit da system! or sum bug is ther"
                stop
            set {gens::%event-block's location%} to player's uuid

            play sound "block.note_block.pling" at volume 1 at pitch 2 to player
            make 10 of poof at event-block

            send "&aGen placed!"


every 80 tick:
    loop {gens::*}:
        (loop-value parsed as player) is online

        set {_l::*} to loop-index split at ":"
        set {_c::*} to {_l::2} split at ","
        set {_loc} to location({_c::1} parsed as number,{_c::2} parsed as number,{_c::3} parsed as number, world {_l::1})

        set {_b} to block at {_loc}

        if type of {_b} is hay block:
            drop {-cache::wheatdrop} above {_b} without velocity

        else:
            clear {gens::%loop-index%}
            send "[Gen] Removed gen from list since there is no gen!" to console


on leftclick on hay block:
    set {_e} to "%event-block's world%:%event-block's x-coord%,%event-block's y-coord%,%event-block's z-coord%"

    if ({gens::%{_e}%} parsed as player) is not player:
        send "&cSorry, but you cant break gens from others!"
        cancel event
        stop

    if player is not sneaking:
        send "&cPlease sneak to confirm removing the gen!"
        stop

    clear {gens::%event-block's location%}
    set event-block to air
    give {-cache::wheatgen} to player

    send "&aGen destoryed!"
    play sound "block.note_block.pling" at volume 1 at pitch 1 to player
    make 10 of poof above event-block


on block break:
    event-block is hay block
    cancel event
 
POV that dude: No problem!

Codddddddde:
Code:
on place of hay block:
    if player's tool is hay block named "&e&lWheat Gen" with lore "&7-----&8-----" and "&7Produces wheat every 10 seconds" and "&7Upgrade cost: &e500⛃" and "&7-----&8-----":

        set {gens::%location of event-block%} to uuid of player

        if {gens::%player's uuid%} < 10:
            set {Ownblocks::%event-block's location%} to event-player
            add 1 to {gens::%player's uuid%}
            play sound "block.note_block.pling" at volume 1 at pitch 2 to player
            make 10 of poof at event-block
            while event-block is hay block:
                wait 80 ticks
                drop 1 wheat named "&e&lWheat" with lore "&7-----&8-----" and "&eWorth 10⛃" and "&7-----&8-----" above location of event-block
        else:
            send "" to player
            send "&bYou have reached your Gen Cap! &7%{gens::%player's uuid%}%&b/&710" to player
            send "" to player
            cancel event

on break of hay block:
    if {Ownblocks::%event-block's location%} is not event-player:
        send "&cSorry, that is not your gen. You cannot break it."
        cancel event
    else if {Ownblocks::%event-block's location%} is event-player:
        set {Ownblocks::%event-block's location%} to false
        set {gens::%location of event-block%} to location of event-block
        remove 1 from {gens::%player's uuid%}
        set event-block to air
        play sound "block.note_block.pling" at volume 1 at pitch 1 to player
        make 10 of poof above event-block
        give player hay block named "&e&lWheat Gen" with lore "&7-----&8-----" and "&7Produces wheat every 10 seconds" and "&7Upgrade cost: &e500⛃" and "&7-----&8-----"
This should be enough of the code, I've tried to use Ownblocks as I found that on another forum post, but it's not working can anyone help?


Ok after around 1 hour of hard work. (Many ppl have died) I got it working i think
Code:
# Contributors:
#   - Pierrelasse#3737
#   - Lolzy#7652
#   - DeafMole#2930

on load:
    set {-cache::wheatgen} to hay block named "&e&lWheat Gen" with lore "&7-----&8-----%nl%&7Produces wheat every 10 seconds%nl%&7Upgrade cost: &e500⛃%nl%&7-----&8-----"
    set {-cache::wheatdrop} to wheat named "&e&lWheat" with lore "&7-----&8-----%nl%&eWorth 10⛃%nl%&7-----&8-----"


on command:
    if command is "ggen":
        cancel event
        give {-cache::wheatgen} to player


on place of hay block:
    event is not cancelled
    if 1 of player's tool is {-cache::wheatgen}:

        set {_i} to 0
        loop {gens::*}:
            loop-value is player's uuid
            add 1 to {_i}

        if {_i} > 10 -1:
            send "%nl%&bYou reached your Gen-Cap! &7%{_i}%&8/&710%nl%"
            cancel event

        else:
            if {gens::%event-block's location%} is set:
                broadcast "&4%player% is tryin to exploit da system! or sum bug is ther"
                stop
            set {gens::%event-block's location%} to player's uuid

            play sound "block.note_block.pling" at volume 1 at pitch 2 to player
            make 10 of poof at event-block

            send "&aGen placed!"


every 80 tick:
    loop {gens::*}:
        (loop-value parsed as player) is online

        set {_l::*} to loop-index split at ":"
        set {_c::*} to {_l::2} split at ","
        set {_loc} to location({_c::1} parsed as number,{_c::2} parsed as number,{_c::3} parsed as number, world {_l::1})

        set {_b} to block at {_loc}

        if type of {_b} is hay block:
            drop {-cache::wheatdrop} above {_b} without velocity

        else:
            clear {gens::%loop-index%}
            send "[Gen] Removed gen from list since there is no gen!" to console


on leftclick on hay block:
    set {_e} to "%event-block's world%:%event-block's x-coord%,%event-block's y-coord%,%event-block's z-coord%"

    if ({gens::%{_e}%} parsed as player) is not player:
        send "&cSorry, but you cant break gens from others!"
        cancel event
        stop

    if player is not sneaking:
        send "&cPlease sneak to confirm removing the gen!"
        stop

    clear {gens::%event-block's location%}
    set event-block to air
    give {-cache::wheatgen} to player

    send "&aGen destoryed!"
    play sound "block.note_block.pling" at volume 1 at pitch 1 to player
    make 10 of poof above event-block


on block break:
    event-block is hay block
    cancel event
ты понимаешь, что ты поехавший???
 
Status
Not open for further replies.