someone explain me what im doing wrong

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

TheCraft

Member
Apr 20, 2019
22
0
1
20
so bassicly i wanted to make a skript of gens that if u sneak break them it goes to ur inventory and if the gen has the exact name it works and makes things spawn on it every 5 secounds and u can turn it on and off anyways anyone can help me fix this? The code is pretty long just saying
Code:
options:
    time: 5
    itembar: |
    prefix: &7[&e&lCoil&7]&f&l -
    items: 2
variables:
    {generator} = true
    {mcd} = true

command /gen [<option>] [<gentype>]:
    trigger:
        if player has permission "generator.admin":
            if arg-1 is "give":
              if arg-2 is "coal":
                give player 1 coal block named "&8&lCoal Generator " with lore "{@prefix} &6- &bSneak and mine to pickup"
              else:
                send "{@prefix} Add a gen type"
              if arg-2 is "iron":   
                give player 1 iron block named "&7&lIron Generator" with lore "{@prefix} &6- &bSneak and mine to pickup"
              else:
                send "{@prefix} Add a gen type"
              if arg-2 is "pumpkin":
                give player 1 pumpkin named "&6&lPumpkin Generator" with lore "{@prefix} &6- &bSneak and mine to pickup"
              else:
                send "{@prefix} Add a gen type"
              if arg-2 is "melon":
                give player 1 melon named "&9&Melon Generator" with lore "{@prefix} &6- &bSneak and mine to pickup"
              else:
                send "{@prefix} Add a gen type"
              if arg-2 is "wheat":
                give player 1 hay named "&c&l Wheat Generator" with lore "{@prefix} &6- &bSneak and mine to pickup"
              else:
                send "{@prefix} Add a gen type"
              if arg-2 is "diamond":
                give player 1 diamond block named "&b&lDiamond Generator" with lore "{@prefix} &6- &bSneak and mine to pickup"
              else:
                send "{@prefix} Add a gen type"
              if arg-2 is "emerald":
                give player 1 emerald block named "&a&lEmerald Generator" with lore "{@prefix} &6- &bSneak and mine to pickup"
              else:
                send "{@prefix} Add a gen type"
            if arg 1 is "on":
                set {generator} to true
                send "{@prefix} &7&lgenerator is on now"
            if arg 1 is "off":
                set {generator} to false
                send "{@prefix} &7&lgenerator is off now"
            if arg-1 is "bar":
                set {mcd} to false
                send "{@prefix} &7&lbar mod on"
            if arg-1 is "time":
                set {mcd} to true
                send "{@prefix} &7&time mod on"
            if arg-1 is not set
            send "{@prefix} &6- &c/gen [<option>] [<gentype>]"
            if arg-2 is not set
            send "{@prefix} &6- &cPlease select a valid gen type."
on break of Coal block:
    if {generator.%Block%} is true:
        if player has permission "generator.admin":
            remove location of event-block from {Coalgen.loc::*}
            set {generator.%Block%} to false
            delete holo object "%location of block%"
            clear {pp%Block%::*}
            clear {cc%Block%::*}
on break of Iron block:
    if {generator.%Block%} is true:
        if player has permission "generator.admin":
            remove location of event-block from {Irongen.loc::*}
            set {generator.%Block%} to false
            delete holo object "%location of block%"
            clear {pp%Block%::*}
            clear {cc%Block%::*}
on break of Pumpkin block:
    if {generator.%Block%} is true:
        if player has permission "generator.admin":
            remove location of event-block from {Pumpkingen.loc::*}
            set {generator.%Block%} to false
            delete holo object "%location of block%"
            clear {pp%Block%::*}
            clear {cc%Block%::*}
on break of Melon block:
    if {generator.%Block%} is true:
        if player has permission "generator.admin":
            remove location of event-block from {Melongen.loc::*}
            set {generator.%Block%} to false
            delete holo object "%location of block%"
            clear {pp%Block%::*}
            clear {cc%Block%::*}
on break of Redstone block:
    if {generator.%Block%} is true:
        if player has permission "generator.admin":
            remove location of event-block from {redstonegen.loc::*}
            set {generator.%Block%} to false
            delete holo object "%location of block%"
            clear {pp%Block%::*}
            clear {cc%Block%::*}
on break of Diamond block:
    if {generator.%Block%} is true:
        if player has permission "generator.admin":
            remove location of event-block from {diamondgen.loc::*}
            set {generator.%Block%} to false
            delete holo object "%location of block%"
            clear {pp%Block%::*}
            clear {cc%Block%::*}
on break of Emerald block:
    if {generator.%Block%} is true:
        if player has permission "generator.admin":
            remove location of event-block from {emeraldgen.loc::*}
            set {generator.%Block%} to false
            delete holo object "%location of block%"
            clear {pp%Block%::*}
            clear {cc%Block%::*}
on break of coal block:
  if %player% is sneaking
    set {_loc} to location of block
    set block at {_loc} to air
    give player 1 coal block named "&b&lCoal &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup"
on break of melon block:
  if %player% is sneaking
    set {_loc} to location of block
    set block at {_loc} to air
    give player 1 melon named "&b&lMelon &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup"
on break of pumpkin block:
  if %player% is sneaking
    set {_loc} to location of block
    set block at {_loc} to air
    give player 1 pumpkin named "&b&lPumpkin &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup"
on break of iron block:
  if %player% is sneaking
    set {_loc} to location of block
    set block at {_loc} to air
    give player 1 coal block named "&b&lIron &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup"
on break of diamond block:
  if %player% is sneaking
    set {_loc} to location of block
    set block at {_loc} to air
    give player 1 diamond block named "&b&lDiamond &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup"
on break of emerald block:
  if %player% is sneaking
    set {_loc} to location of block
    set block at {_loc} to air
    give player 1 emerald block named "&b&lEmerald &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup"
on break of hay:
  if %player5 is sneaking
    set {_loc} to location of block
    set block at {_loc} to air
    give %player% 1 hay named "&b&lWheat &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup"
on place of hay block:   
    if player's tool is hay named "&b&lWheat &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup":
        set {wheatgen.loc::*} location of block
        spawn diamond above {diamondgen.loc::*}
        set {generator.%Block%} to true
        set {gen.%Block%} to {@time}       
        loop {@time} times:
on place of pumpkin:   
    if player's tool is diamond block named "&b&lDiamond &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup":
        set {pumpkingen.loc::*} location of block
        spawn pumpkin above {pumpkingen.loc::*}
        set {generator.%Block%} to true
        set {gen.%Block%} to {@time}       
        loop {@time} times:
on place of melon:   
    if player's tool is melon named "&b&lMelon &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup":
        set {wheatgen.loc::*} location of block
        spawn melon above {diamondgen.loc::*}
        set {generator.%Block%} to true
        set {gen.%Block%} to {@time}       
        loop {@time} times:
on place of coal block:   
    if player's tool is coal block named "&b&lCoal &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup":
        set {coalgen.loc::*} location of block
        spawn coal above {coalgen.loc::*}
        set {generator.%Block%} to true
        set {gen.%Block%} to {@time}       
        loop {@time} times:
on place of iron block:   
    if player's tool is iron block named "&b&lIron &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup":
        set {irongen.loc::*} location of block
        spawn iron above {irongen.loc::*}
        set {generator.%Block%} to true
        set {gen.%Block%} to {@time}       
        loop {@time} times:
on place of diamond block:   
    if player's tool is diamond block named "&b&lDiamond &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup":
        set {diamondgen.loc::*} location of block
        spawn diamond above {diamondgen.loc::*}
        set {generator.%Block%} to true
        set {gen.%Block%} to {@time}       
        loop {@time} times:
on place of emerald block:   
    if player's tool is emerald block named "&b&lEmerald &bGenerator " with lore "{@prefix} &6- &bSneak and mine to pickup":
        set {emeraldgen.loc::*} location of block
        spawn emerald above {emeraldgen.loc::*}
        set {generator.%Block%} to true
        set {gen.%Block%} to {@time}       
        loop {@time} times:
thanks for any help
 
Well maybe u can first use format? Errors? Whats not working?

also a pumpkin is not a diamond block

Code:
on place of pumpkin: 
    if player's tool is diamond block named "&b&lDiamond &bGenerator
 
Well maybe u can first use format? Errors? Whats not working?

also a pumpkin is not a diamond block

Code:
on place of pumpkin:
    if player's tool is diamond block named "&b&lDiamond &bGenerator
thanks i didnt see the miss typing
btw is 72 errors so if u want i can send i just need to find a way to send it without copying it all and im pretty new to skript so thats why i have no idea what im doing im trying to use docs and learn from the skunity community
 
thanks i didnt see the miss typing
btw is 72 errors so if u want i can send

nvm looked at the code and u didn't even finnished the code this requires someone to take time to make it for u so u should post it in the request section.

Can u also explain in more dept what its supposed to do?

Wenn placed does it need to go on every ... seconds or go on for a set time and stop.
What do u want to happen wenn the server restarts stop all generators make them continue?

pls be more descriptive
 
nvm looked at the code and u didn't even finnished the code this requires someone to take time to make it for u so u should post it in the request section.

Can u also explain in more dept what its supposed to do?

Wenn placed does it need to go on every ... seconds or go on for a set time and stop.
What do u want to happen wenn the server restarts stop all generators make them continue?

pls be more descriptive


a gens skript that is bassicly when u shift break the gen it gives it to ur inventory with the exact name so u can replace it and it drops on the head of the gen the type of the gen is like diamond gen drops diamonds every 5 secounds i dont want it to glitch out when i restart server i want it to keep working after the server restarts its just that i am new to skripting and i dont know all of those things i am learning from skunity and community so i thought i finished the code thats why i came here would be pleasure if someone fixes this code and sends it so i can understand my errors and what did i forget to do

btw the command dosent even exists
even after i reloaded it
[doublepost=1583335550,1583335474][/doublepost]oh and how to do that u cant break it without shifting
 
a gens skript that is bassicly when u shift break the gen it gives it to ur inventory with the exact name so u can replace it and it drops on the head of the gen the type of the gen is like diamond gen drops diamonds every 5 secounds i dont want it to glitch out when i restart server i want it to keep working after the server restarts its just that i am new to skripting and i dont know all of those things i am learning from skunity and community so i thought i finished the code thats why i came here would be pleasure if someone fixes this code and sends it so i can understand my errors and what did i forget to do

btw the command dosent even exists
even after i reloaded it
[doublepost=1583335550,1583335474][/doublepost]oh and how to do that u cant break it without shifting
Are generators per player or global so if u do /off all the generators are off from a specific player or like all server wide
 

Sry for the long wait but as u can see below here it took some while hope u happy and have no errors bc of versions if u do pls reply

i ussed alot of comments to explain it to u

Code:
#WARNING!!!!

#This Script has a known bug:
# If a generator has been placed and then someone moves it with a piston it gets deleted(if it was on or gets turned on) + the owner has no way to get his generator back.
# U can enable the code right below here as temperarly fix if u don't mind disableing pistons. I don't have time to make a propper fix rn:

# On piston extend:
#     cancel event
#
# On piston retract:
#     cancel event

#End Temp fix

options:
    #Prefix
    prefix: &7[&e&lCoil&7]&f&l -
    #lore of the generator item to be placed
    lore: &7[&e&lCoil&7]&f&l - &6- &bSneak and mine to pickup
    #name suffix of the generator
    namesuffix: Generator

#function to manage spawning items
function genitem(uuid: text,loc: location):
    #check if the player didnt turned his generators off
    if {genoff::%{_uuid}%} is set:
        stop
    #check if the generator still exists
    if {generators::%{_uuid}%::%{_loc}%} is set:
        #get the type of generator
        set {_type} to {generators::%{_uuid}%::%{_loc}%}
        # Check if the block at the location is still valid
        if block at {_loc} is {gentypes::%{_type}%}:
            #get the item of the right type
            set {_item} to {gentypes::%{_type}%::item}
            #spawn the item
            drop {_item} above {_loc} without velocity
            #make shure time is set and can't be <none>
            set {_time} to 1
            #get the propper interval of the right type
            set {_time} to {gentypes::%{_type}%::interval}
            #CHECK for atleast 1 tick to prefent a server crash (bc then this will spam without a delay)
            if {_time} < 1:
                set {_time} to 1
            #loop time amount times
            loop {_time} times:
                #check if the generator needs to stop bc of a script reload
                if {GEN.ON} is not set:
                    stop
                #check if the player turned his generators off
                if {genoff::%{_uuid}%} is set:
                    stop
                #wait 1 tick * {_time}
                wait 1 tick
            #start this function again after {_time} so it keeps repeating the spawn process
            genitem({_uuid}, {_loc})
            #stop the function so it doesnt go to the delete lines
            stop
        #if the block isn't there anymore and this data still beeing set is invalid data and should be deleted
        delete {generators::%{_uuid}%::%{_loc}%}
        delete {generators::%{_uuid}%::%{_loc}%::loc}

on script load:
    #stop all the generators
    delete {GEN.ON}
    #reset all the types
    loop {gentypes::*}:
        delete {gentypes::%loop-index%::*}
    delete {gentypes::*}

    #creating type coal
    set {gentypes::coal} to coal block
    set {gentypes::coal::item} to coal
    #interval in ticks 20 ticks = 1 second
    set {gentypes::coal::interval} to 100 #in ticks 20 ticks = 1 second
    set {gentypes::coal::name} to "&8&lCoal {@namesuffix}"

    #creating type iron
    set {gentypes::iron} to iron block
    set {gentypes::iron::item} to iron ingot
    #interval in ticks 20 ticks = 1 second
    set {gentypes::iron::interval} to 80
    set {gentypes::iron::name} to "&7&lIron {@namesuffix}"

    #security messure waiting to make shure all generators have been stopped by now
    wait 1 second

    #Enable variable so generators are allowed to start again
    set {GEN.ON} to true

    #loop all uuids
    loop indices of {generators::*}:
        #loop all locations of a uuid
        loop {generators::%loop-value%::*}:
            #get formatted location of a generator of a uuid
            set {_l} to {generators::%loop-value-1%::%loop-index%::loc}
            #start generator
            genitem(loop-value-1, {_l})

#main command
command /gen [<text>] [<text>]:
    trigger:
        #premission check
        if player has permission "generator.admin":
            if arg-1 is "give":
                #check if the type exists
                if {gentypes::%arg 2%::name} is set:
                    #give the requested type
                    give player {gentypes::%arg 2%} named {gentypes::%arg 2%::name} with lore {gentypes::%arg 2%::lore}
                    stop
                send "{@prefix} &6- &cPlease select a valid gen type."
                stop
            if arg 1 is "on":
                #check if its off so u can't turn it on double
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &7&lgenerator is on now"
                    set {_uuid} to uuid of player
                    #allow generators to start for this player
                    delete {genoff::%uuid of player%}
                    #loop all locations of player
                    loop {generators::%{_uuid}%::*}:
                        #get formatted location of a generator of player
                        set {_l} to {generators::%{_uuid}%::%loop-index%::loc}
                        #start generator
                        genitem({_uuid}, {_l})
                else:
                    send "{@prefix} &7&lgenerator is already on"
                stop
            if arg 1 is "off":
                #check if the generators of the player aren't already off
                if {genoff::%uuid of player%} is not set:
                    send "{@prefix} &7&lgenerator is off now"
                    #turn generators off
                    set {genoff::%uuid of player%} to true
                else:
                    send "{@prefix} &7&lgenerator is already off"
                stop
            send "{@prefix} &6- &c/gen [<option>] [<gentype>]"

#debug command to delete all data if some manage to get stuck WARNING this is all data so all generators placed currently are lost.
command /DEBUGGENRESET:
    trigger:
        loop indices of {generators::*}:
            loop {generators::%loop-value%::*}:
                delete {generators::%loop-value-1%::%loop-index%::*}
            delete {generators::%loop-value%::*}
        delete {generators::*}
        delete {genoff::*}

#break event
on break:
    #check if the current block is a generator and if this player is the owner
    if {generators::%uuid of player%::%location of event-block%} is set:
        #check if the player is sneaking
        if player is sneaking:
            send "{@prefix} &7&lgenerator removed!"
            #get type of the broken generator
            set {_type} to {generators::%uuid of player%::%location of event-block%}
            #delete data of generator
            delete {generators::%uuid of player%::%location of event-block%}
            delete {generators::%uuid of player%::%location of event-block%::loc}
            send "{@prefix} &7&lGenerator Recieved!" to player
            #give back generator
            give player {gentypes::%{_type}%} named {gentypes::%{_type}%::name} with lore {gentypes::%{_type}%::lore}
            stop
        #cancels block break if the player is not sneaking
        cancel event
    #check if the block is a generator but if the player is not the owner
    loop indices of {generators::*}:
        if {generators::%loop-value%::%location of event-block%} is set:
            #cancel block break bc the player is not the owner
            cancel event
            #can stop the loop bc the event already has been canceled
            stop

#place event
On place:
    #get all the current types of generators
    loop {gentypes::*}:
        #check if the tool of the player is a know block that could be a generator
        if player's tool is loop-value:
            #check if the name of tool of the player is equal to how a generator is supposed to be called
            if name of player's tool is {gentypes::%loop-index%::name}:
                #check if there is any old corrupted data for this location
                if {generators::%uuid of player%::%location of event-block%} is set:
                    #delete corrupted data
                    delete {generators::%uuid of player%::%location of event-block%}
                    delete {generators::%uuid of player%::%location of event-block%::loc}
                #Create the data for the new generator
                set {generators::%uuid of player%::%location of event-block%} to loop-index
                set {generators::%uuid of player%::%location of event-block%::loc} to location of event-block
                send "{@prefix} &7&lGenerator Created!" to player
                #Check if this player has its generators off
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &7&lU currently have generators off. /gen on" to player
                else:
                    #start the new created generator
                    genitem(uuid of player, location of event-block)
            stop
 
Sry for the long wait but as u can see below here it took some while hope u happy and have no errors bc of versions if u do pls reply

i ussed alot of comments to explain it to u

Code:
#WARNING!!!!

#This Script has a known bug:
# If a generator has been placed and then someone moves it with a piston it gets deleted(if it was on or gets turned on) + the owner has no way to get his generator back.
# U can enable the code right below here as temperarly fix if u don't mind disableing pistons. I don't have time to make a propper fix rn:

# On piston extend:
#     cancel event
#
# On piston retract:
#     cancel event

#End Temp fix

options:
    #Prefix
    prefix: &7[&e&lCoil&7]&f&l -
    #lore of the generator item to be placed
    lore: &7[&e&lCoil&7]&f&l - &6- &bSneak and mine to pickup
    #name suffix of the generator
    namesuffix: Generator

#function to manage spawning items
function genitem(uuid: text,loc: location):
    #check if the player didnt turned his generators off
    if {genoff::%{_uuid}%} is set:
        stop
    #check if the generator still exists
    if {generators::%{_uuid}%::%{_loc}%} is set:
        #get the type of generator
        set {_type} to {generators::%{_uuid}%::%{_loc}%}
        # Check if the block at the location is still valid
        if block at {_loc} is {gentypes::%{_type}%}:
            #get the item of the right type
            set {_item} to {gentypes::%{_type}%::item}
            #spawn the item
            drop {_item} above {_loc} without velocity
            #make shure time is set and can't be <none>
            set {_time} to 1
            #get the propper interval of the right type
            set {_time} to {gentypes::%{_type}%::interval}
            #CHECK for atleast 1 tick to prefent a server crash (bc then this will spam without a delay)
            if {_time} < 1:
                set {_time} to 1
            #loop time amount times
            loop {_time} times:
                #check if the generator needs to stop bc of a script reload
                if {GEN.ON} is not set:
                    stop
                #check if the player turned his generators off
                if {genoff::%{_uuid}%} is set:
                    stop
                #wait 1 tick * {_time}
                wait 1 tick
            #start this function again after {_time} so it keeps repeating the spawn process
            genitem({_uuid}, {_loc})
            #stop the function so it doesnt go to the delete lines
            stop
        #if the block isn't there anymore and this data still beeing set is invalid data and should be deleted
        delete {generators::%{_uuid}%::%{_loc}%}
        delete {generators::%{_uuid}%::%{_loc}%::loc}

on script load:
    #stop all the generators
    delete {GEN.ON}
    #reset all the types
    loop {gentypes::*}:
        delete {gentypes::%loop-index%::*}
    delete {gentypes::*}

    #creating type coal
    set {gentypes::coal} to coal block
    set {gentypes::coal::item} to coal
    #interval in ticks 20 ticks = 1 second
    set {gentypes::coal::interval} to 100 #in ticks 20 ticks = 1 second
    set {gentypes::coal::name} to "&8&lCoal {@namesuffix}"

    #creating type iron
    set {gentypes::iron} to iron block
    set {gentypes::iron::item} to iron ingot
    #interval in ticks 20 ticks = 1 second
    set {gentypes::iron::interval} to 80
    set {gentypes::iron::name} to "&7&lIron {@namesuffix}"

    #security messure waiting to make shure all generators have been stopped by now
    wait 1 second

    #Enable variable so generators are allowed to start again
    set {GEN.ON} to true

    #loop all uuids
    loop indices of {generators::*}:
        #loop all locations of a uuid
        loop {generators::%loop-value%::*}:
            #get formatted location of a generator of a uuid
            set {_l} to {generators::%loop-value-1%::%loop-index%::loc}
            #start generator
            genitem(loop-value-1, {_l})

#main command
command /gen [<text>] [<text>]:
    trigger:
        #premission check
        if player has permission "generator.admin":
            if arg-1 is "give":
                #check if the type exists
                if {gentypes::%arg 2%::name} is set:
                    #give the requested type
                    give player {gentypes::%arg 2%} named {gentypes::%arg 2%::name} with lore {gentypes::%arg 2%::lore}
                    stop
                send "{@prefix} &6- &cPlease select a valid gen type."
                stop
            if arg 1 is "on":
                #check if its off so u can't turn it on double
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &7&lgenerator is on now"
                    set {_uuid} to uuid of player
                    #allow generators to start for this player
                    delete {genoff::%uuid of player%}
                    #loop all locations of player
                    loop {generators::%{_uuid}%::*}:
                        #get formatted location of a generator of player
                        set {_l} to {generators::%{_uuid}%::%loop-index%::loc}
                        #start generator
                        genitem({_uuid}, {_l})
                else:
                    send "{@prefix} &7&lgenerator is already on"
                stop
            if arg 1 is "off":
                #check if the generators of the player aren't already off
                if {genoff::%uuid of player%} is not set:
                    send "{@prefix} &7&lgenerator is off now"
                    #turn generators off
                    set {genoff::%uuid of player%} to true
                else:
                    send "{@prefix} &7&lgenerator is already off"
                stop
            send "{@prefix} &6- &c/gen [<option>] [<gentype>]"

#debug command to delete all data if some manage to get stuck WARNING this is all data so all generators placed currently are lost.
command /DEBUGGENRESET:
    trigger:
        loop indices of {generators::*}:
            loop {generators::%loop-value%::*}:
                delete {generators::%loop-value-1%::%loop-index%::*}
            delete {generators::%loop-value%::*}
        delete {generators::*}
        delete {genoff::*}

#break event
on break:
    #check if the current block is a generator and if this player is the owner
    if {generators::%uuid of player%::%location of event-block%} is set:
        #check if the player is sneaking
        if player is sneaking:
            send "{@prefix} &7&lgenerator removed!"
            #get type of the broken generator
            set {_type} to {generators::%uuid of player%::%location of event-block%}
            #delete data of generator
            delete {generators::%uuid of player%::%location of event-block%}
            delete {generators::%uuid of player%::%location of event-block%::loc}
            send "{@prefix} &7&lGenerator Recieved!" to player
            #give back generator
            give player {gentypes::%{_type}%} named {gentypes::%{_type}%::name} with lore {gentypes::%{_type}%::lore}
            stop
        #cancels block break if the player is not sneaking
        cancel event
    #check if the block is a generator but if the player is not the owner
    loop indices of {generators::*}:
        if {generators::%loop-value%::%location of event-block%} is set:
            #cancel block break bc the player is not the owner
            cancel event
            #can stop the loop bc the event already has been canceled
            stop

#place event
On place:
    #get all the current types of generators
    loop {gentypes::*}:
        #check if the tool of the player is a know block that could be a generator
        if player's tool is loop-value:
            #check if the name of tool of the player is equal to how a generator is supposed to be called
            if name of player's tool is {gentypes::%loop-index%::name}:
                #check if there is any old corrupted data for this location
                if {generators::%uuid of player%::%location of event-block%} is set:
                    #delete corrupted data
                    delete {generators::%uuid of player%::%location of event-block%}
                    delete {generators::%uuid of player%::%location of event-block%::loc}
                #Create the data for the new generator
                set {generators::%uuid of player%::%location of event-block%} to loop-index
                set {generators::%uuid of player%::%location of event-block%::loc} to location of event-block
                send "{@prefix} &7&lGenerator Created!" to player
                #Check if this player has its generators off
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &7&lU currently have generators off. /gen on" to player
                else:
                    #start the new created generator
                    genitem(uuid of player, location of event-block)
            stop
Thankes i will try it!
[doublepost=1583396235,1583394816][/doublepost]
Sry for the long wait but as u can see below here it took some while hope u happy and have no errors bc of versions if u do pls reply

i ussed alot of comments to explain it to u

Code:
#WARNING!!!!

#This Script has a known bug:
# If a generator has been placed and then someone moves it with a piston it gets deleted(if it was on or gets turned on) + the owner has no way to get his generator back.
# U can enable the code right below here as temperarly fix if u don't mind disableing pistons. I don't have time to make a propper fix rn:

# On piston extend:
#     cancel event
#
# On piston retract:
#     cancel event

#End Temp fix

options:
    #Prefix
    prefix: &7[&e&lCoil&7]&f&l -
    #lore of the generator item to be placed
    lore: &7[&e&lCoil&7]&f&l - &6- &bSneak and mine to pickup
    #name suffix of the generator
    namesuffix: Generator

#function to manage spawning items
function genitem(uuid: text,loc: location):
    #check if the player didnt turned his generators off
    if {genoff::%{_uuid}%} is set:
        stop
    #check if the generator still exists
    if {generators::%{_uuid}%::%{_loc}%} is set:
        #get the type of generator
        set {_type} to {generators::%{_uuid}%::%{_loc}%}
        # Check if the block at the location is still valid
        if block at {_loc} is {gentypes::%{_type}%}:
            #get the item of the right type
            set {_item} to {gentypes::%{_type}%::item}
            #spawn the item
            drop {_item} above {_loc} without velocity
            #make shure time is set and can't be <none>
            set {_time} to 1
            #get the propper interval of the right type
            set {_time} to {gentypes::%{_type}%::interval}
            #CHECK for atleast 1 tick to prefent a server crash (bc then this will spam without a delay)
            if {_time} < 1:
                set {_time} to 1
            #loop time amount times
            loop {_time} times:
                #check if the generator needs to stop bc of a script reload
                if {GEN.ON} is not set:
                    stop
                #check if the player turned his generators off
                if {genoff::%{_uuid}%} is set:
                    stop
                #wait 1 tick * {_time}
                wait 1 tick
            #start this function again after {_time} so it keeps repeating the spawn process
            genitem({_uuid}, {_loc})
            #stop the function so it doesnt go to the delete lines
            stop
        #if the block isn't there anymore and this data still beeing set is invalid data and should be deleted
        delete {generators::%{_uuid}%::%{_loc}%}
        delete {generators::%{_uuid}%::%{_loc}%::loc}

on script load:
    #stop all the generators
    delete {GEN.ON}
    #reset all the types
    loop {gentypes::*}:
        delete {gentypes::%loop-index%::*}
    delete {gentypes::*}

    #creating type coal
    set {gentypes::coal} to coal block
    set {gentypes::coal::item} to coal
    #interval in ticks 20 ticks = 1 second
    set {gentypes::coal::interval} to 100 #in ticks 20 ticks = 1 second
    set {gentypes::coal::name} to "&8&lCoal {@namesuffix}"

    #creating type iron
    set {gentypes::iron} to iron block
    set {gentypes::iron::item} to iron ingot
    #interval in ticks 20 ticks = 1 second
    set {gentypes::iron::interval} to 80
    set {gentypes::iron::name} to "&7&lIron {@namesuffix}"

    #security messure waiting to make shure all generators have been stopped by now
    wait 1 second

    #Enable variable so generators are allowed to start again
    set {GEN.ON} to true

    #loop all uuids
    loop indices of {generators::*}:
        #loop all locations of a uuid
        loop {generators::%loop-value%::*}:
            #get formatted location of a generator of a uuid
            set {_l} to {generators::%loop-value-1%::%loop-index%::loc}
            #start generator
            genitem(loop-value-1, {_l})

#main command
command /gen [<text>] [<text>]:
    trigger:
        #premission check
        if player has permission "generator.admin":
            if arg-1 is "give":
                #check if the type exists
                if {gentypes::%arg 2%::name} is set:
                    #give the requested type
                    give player {gentypes::%arg 2%} named {gentypes::%arg 2%::name} with lore {gentypes::%arg 2%::lore}
                    stop
                send "{@prefix} &6- &cPlease select a valid gen type."
                stop
            if arg 1 is "on":
                #check if its off so u can't turn it on double
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &7&lgenerator is on now"
                    set {_uuid} to uuid of player
                    #allow generators to start for this player
                    delete {genoff::%uuid of player%}
                    #loop all locations of player
                    loop {generators::%{_uuid}%::*}:
                        #get formatted location of a generator of player
                        set {_l} to {generators::%{_uuid}%::%loop-index%::loc}
                        #start generator
                        genitem({_uuid}, {_l})
                else:
                    send "{@prefix} &7&lgenerator is already on"
                stop
            if arg 1 is "off":
                #check if the generators of the player aren't already off
                if {genoff::%uuid of player%} is not set:
                    send "{@prefix} &7&lgenerator is off now"
                    #turn generators off
                    set {genoff::%uuid of player%} to true
                else:
                    send "{@prefix} &7&lgenerator is already off"
                stop
            send "{@prefix} &6- &c/gen [<option>] [<gentype>]"

#debug command to delete all data if some manage to get stuck WARNING this is all data so all generators placed currently are lost.
command /DEBUGGENRESET:
    trigger:
        loop indices of {generators::*}:
            loop {generators::%loop-value%::*}:
                delete {generators::%loop-value-1%::%loop-index%::*}
            delete {generators::%loop-value%::*}
        delete {generators::*}
        delete {genoff::*}

#break event
on break:
    #check if the current block is a generator and if this player is the owner
    if {generators::%uuid of player%::%location of event-block%} is set:
        #check if the player is sneaking
        if player is sneaking:
            send "{@prefix} &7&lgenerator removed!"
            #get type of the broken generator
            set {_type} to {generators::%uuid of player%::%location of event-block%}
            #delete data of generator
            delete {generators::%uuid of player%::%location of event-block%}
            delete {generators::%uuid of player%::%location of event-block%::loc}
            send "{@prefix} &7&lGenerator Recieved!" to player
            #give back generator
            give player {gentypes::%{_type}%} named {gentypes::%{_type}%::name} with lore {gentypes::%{_type}%::lore}
            stop
        #cancels block break if the player is not sneaking
        cancel event
    #check if the block is a generator but if the player is not the owner
    loop indices of {generators::*}:
        if {generators::%loop-value%::%location of event-block%} is set:
            #cancel block break bc the player is not the owner
            cancel event
            #can stop the loop bc the event already has been canceled
            stop

#place event
On place:
    #get all the current types of generators
    loop {gentypes::*}:
        #check if the tool of the player is a know block that could be a generator
        if player's tool is loop-value:
            #check if the name of tool of the player is equal to how a generator is supposed to be called
            if name of player's tool is {gentypes::%loop-index%::name}:
                #check if there is any old corrupted data for this location
                if {generators::%uuid of player%::%location of event-block%} is set:
                    #delete corrupted data
                    delete {generators::%uuid of player%::%location of event-block%}
                    delete {generators::%uuid of player%::%location of event-block%::loc}
                #Create the data for the new generator
                set {generators::%uuid of player%::%location of event-block%} to loop-index
                set {generators::%uuid of player%::%location of event-block%::loc} to location of event-block
                send "{@prefix} &7&lGenerator Created!" to player
                #Check if this player has its generators off
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &7&lU currently have generators off. /gen on" to player
                else:
                    #start the new created generator
                    genitem(uuid of player, location of event-block)
            stop
works perfect ima read it all btw how to make it upgradable and that the console can give the gens to a player i mean i want to make a shop that they but it from so th e console uses to cmd to give it to them
 
Thankes i will try it!
[doublepost=1583396235,1583394816][/doublepost]
works perfect ima read it all btw how to make it upgradable and that the console can give the gens to a player i mean i want to make a shop that they but it from so th e console uses to cmd to give it to them

Upgradable depends what specs do u want to change?

Why trough console? if i may ask?
 
Through console because the player wont have the generator.admin perm node so he wont find out and abuse it and idk any other way to do it anyways upgradable i meant that when u shift right click it upgrades it to the next level of the gen like from wheat to pumpkin i put new gens by the order at the script u sended me u can check it out
Code:
#WARNING!!!!
 
#This Script has a known bug:
# If a generator has been placed and then someone moves it with a piston it gets deleted(if it was on or gets turned on) + the owner has no way to get his generator back.
# U can enable the code right below here as temperarly fix if u don't mind disableing pistons. I don't have time to make a propper fix rn:
 
# On piston extend:
#     cancel event
#
# On piston retract:
#     cancel event
 
#End Temp fix
 
options:
    #Prefix
    prefix: &7[&e&lCoil&7]&f&l -
    #lore of the generator item to be placed
    lore: &7[&e&lCoil&7]&f&l - &6- &bSneak and mine to pickup
    #name suffix of the generator
    namesuffix: Generator
 
#function to manage spawning items
function genitem(uuid: text,loc: location):
    #check if the player didnt turned his generators off
    if {genoff::%{_uuid}%} is set:
        stop
    #check if the generator still exists
    if {generators::%{_uuid}%::%{_loc}%} is set:
        #get the type of generator
        set {_type} to {generators::%{_uuid}%::%{_loc}%}
        # Check if the block at the location is still valid
        if block at {_loc} is {gentypes::%{_type}%}:
            #get the item of the right type
            set {_item} to {gentypes::%{_type}%::item}
            #spawn the item
            drop {_item} above {_loc} without velocity
            #make shure time is set and can't be <none>
            set {_time} to 1
            #get the propper interval of the right type
            set {_time} to {gentypes::%{_type}%::interval}
            #CHECK for atleast 1 tick to prefent a server crash (bc then this will spam without a delay)
            if {_time} < 1:
                set {_time} to 1
            #loop time amount times
            loop {_time} times:
                #check if the generator needs to stop bc of a script reload
                if {GEN.ON} is not set:
                    stop
                #check if the player turned his generators off
                if {genoff::%{_uuid}%} is set:
                    stop
                #wait 1 tick * {_time}
                wait 1 tick
            #start this function again after {_time} so it keeps repeating the spawn process
            genitem({_uuid}, {_loc})
            #stop the function so it doesnt go to the delete lines
            stop
        #if the block isn't there anymore and this data still beeing set is invalid data and should be deleted
        delete {generators::%{_uuid}%::%{_loc}%}
        delete {generators::%{_uuid}%::%{_loc}%::loc}
 
on script load:
    #stop all the generators
    delete {GEN.ON}
    #reset all the types
    loop {gentypes::*}:
        delete {gentypes::%loop-index%::*}
    delete {gentypes::*}
 
   #creating type wheat  - Level 1
    set {gentypes::wheat} to hay block
    set {gentypes::wheat::item} to coal
    #interval in ticks 20 ticks = 1 second
    set {gentypes::wheat::interval} to 200 #in ticks 20 ticks = 1 second
    set {gentypes::wheat::name} to "&bWheat {@namesuffix}"
 
   #creating type pumpkin - Level 2
    set {gentypes::pumpkin} to pumpkin
    set {gentypes::pumpkin::item} to pumpkin
    #interval in ticks 20 ticks = 1 second
    set {gentypes::pumpkin::interval} to 200
    set {gentypes::pumpkin::name} to "&bPumpkin {@namesuffix}"

#creating type melon - Level 3
    set {gentypes::melon} to melon
    set {gentypes::melon::item} to melon
    #interval in ticks 20 ticks = 1 second
    set {gentypes::melon::interval} to 200
    set {gentypes::melon::name} to "&bMelon {@namesuffix}"
 
#creating type coal - Level 4
    set {gentypes::coal} to coal block
    set {gentypes::coal::item} to coal
    #interval in ticks 20 ticks = 1 second
    set {gentypes::coal::interval} to 200
    set {gentypes::coal::name} to "&bCoal {@namesuffix}"

#creating type iron - Level 5
    set {gentypes::iron} to iron block
    set {gentypes::iron::item} to iron ingot
    #interval in ticks 20 ticks = 1 second
    set {gentypes::iron::interval} to 200
    set {gentypes::iron::name} to "&bIron {@namesuffix}"

#creating type diamond - Level 6
    set {gentypes::diamond} to diamond block
    set {gentypes::diamond::item} to diamond
    #interval in ticks 20 ticks = 1 second
    set {gentypes::diamond::interval} to 200
    set {gentypes::diamond::name} to "&bDiamond {@namesuffix}"

#creating type emerald - Level 7
    set {gentypes::emerald} to emerald block
    set {gentypes::emerald::item} to emerald
    #interval in ticks 20 ticks = 1 second
    set {gentypes::emerald::interval} to 200
    set {gentypes::emerald::name} to "&bEmerald {@namesuffix}"

#creating type redmush - Level 7
    set {gentypes::redmush} to red mushroom block
    set {gentypes::redmush::item} to red mushroom
    #interval in ticks 20 ticks = 1 second
    set {gentypes::redmush::interval} to 200
    set {gentypes::redmush::name} to "&bMushroom {@namesuffix}"

    #security measure waiting to make sure all generators have been stopped by now
    wait 1 second
 
    #Enable variable so generators are allowed to start again
    set {GEN.ON} to true
 
    #loop all uuids
    loop indices of {generators::*}:
        #loop all locations of a uuid
        loop {generators::%loop-value%::*}:
            #get formatted location of a generator of a uuid
            set {_l} to {generators::%loop-value-1%::%loop-index%::loc}
            #start generator
            genitem(loop-value-1, {_l})
 
#main command
command /gen [<text>] [<text>]:
    trigger:
        #premission check
        if player has permission "generator.admin":
            if arg-1 is "give":
                #check if the type exists
                if {gentypes::%arg 2%::name} is set:
                    #give the requested type
                    give player {gentypes::%arg 2%} named {gentypes::%arg 2%::name} with lore {gentypes::%arg 2%::lore}
                    stop
                send "{@prefix} &6- &cPlease select a valid gen type."
                stop
            if arg 1 is "on":
                #check if its off so u can't turn it on double
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &bGenerator is on now"
                    set {_uuid} to uuid of player
                    #allow generators to start for this player
                    delete {genoff::%uuid of player%}
                    #loop all locations of player
                    loop {generators::%{_uuid}%::*}:
                        #get formatted location of a generator of player
                        set {_l} to {generators::%{_uuid}%::%loop-index%::loc}
                        #start generator
                        genitem({_uuid}, {_l})
                else:
                    send "{@prefix} &bgenerator is already on"
                stop
            if arg 1 is "off":
                #check if the generators of the player aren't already off
                if {genoff::%uuid of player%} is not set:
                    send "{@prefix} &bGenerator is off now"
                    #turn generators off
                    set {genoff::%uuid of player%} to true
                else:
                    send "{@prefix} &bgenerator is already off"
                stop
            send "{@prefix} &6- &c/gen [<option>] [<gentype>]"
 
#debug command to delete all data if some manage to get stuck WARNING this is all data so all generators placed currently are lost.
command /DEBUGGENRESET:
    trigger:
        loop indices of {generators::*}:
            loop {generators::%loop-value%::*}:
                delete {generators::%loop-value-1%::%loop-index%::*}
            delete {generators::%loop-value%::*}
        delete {generators::*}
        delete {genoff::*}
 
#break event
on break:
    #check if the current block is a generator and if this player is the owner
    if {generators::%uuid of player%::%location of event-block%} is set:
        #check if the player is sneaking
        if player is sneaking:
            send "{@prefix} &bGenerator collected!"
            #get type of the broken generator
            set {_type} to {generators::%uuid of player%::%location of event-block%}
            #delete data of generator
            delete {generators::%uuid of player%::%location of event-block%}
            delete {generators::%uuid of player%::%location of event-block%::loc}
            #give back generator
            give player {gentypes::%{_type}%} named {gentypes::%{_type}%::name} with lore {gentypes::%{_type}%::lore}
            stop
        #cancels block break if the player is not sneaking
        cancel event
    #check if the block is a generator but if the player is not the owner
    loop indices of {generators::*}:
        if {generators::%loop-value%::%location of event-block%} is set:
            #cancel block break bc the player is not the owner
            cancel event
            #can stop the loop bc the event already has been canceled
            stop
 
#place event
On place:
    #get all the current types of generators
    loop {gentypes::*}:
        #check if the tool of the player is a know block that could be a generator
        if player's tool is loop-value:
            #check if the name of tool of the player is equal to how a generator is supposed to be called
            if name of player's tool is {gentypes::%loop-index%::name}:
                #check if there is any old corrupted data for this location
                if {generators::%uuid of player%::%location of event-block%} is set:
                    #delete corrupted data
                    delete {generators::%uuid of player%::%location of event-block%}
                    delete {generators::%uuid of player%::%location of event-block%::loc}
                #Create the data for the new generator
                set {generators::%uuid of player%::%location of event-block%} to loop-index
                set {generators::%uuid of player%::%location of event-block%::loc} to location of event-block
                send "{@prefix} &bGenerator Placed!" to player
                #Check if this player has its generators off
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &bU currently have generators off. /gen on" to player
                else:
                    #start the new created generator
                    genitem(uuid of player, location of event-block)
            stop
[doublepost=1583414022,1583413917][/doublepost]
Through console because the player wont have the generator.admin perm node so he wont find out and abuse it and idk any other way to do it anyways upgradable i meant that when u shift right click it upgrades it to the next level of the gen like from wheat to pumpkin i put new gens by the order at the script u sended me u can check it out
Code:
#WARNING!!!!
 
#This Script has a known bug:
# If a generator has been placed and then someone moves it with a piston it gets deleted(if it was on or gets turned on) + the owner has no way to get his generator back.
# U can enable the code right below here as temperarly fix if u don't mind disableing pistons. I don't have time to make a propper fix rn:
 
# On piston extend:
#     cancel event
#
# On piston retract:
#     cancel event
 
#End Temp fix
 
options:
    #Prefix
    prefix: &7[&e&lCoil&7]&f&l -
    #lore of the generator item to be placed
    lore: &7[&e&lCoil&7]&f&l - &6- &bSneak and mine to pickup
    #name suffix of the generator
    namesuffix: Generator
 
#function to manage spawning items
function genitem(uuid: text,loc: location):
    #check if the player didnt turned his generators off
    if {genoff::%{_uuid}%} is set:
        stop
    #check if the generator still exists
    if {generators::%{_uuid}%::%{_loc}%} is set:
        #get the type of generator
        set {_type} to {generators::%{_uuid}%::%{_loc}%}
        # Check if the block at the location is still valid
        if block at {_loc} is {gentypes::%{_type}%}:
            #get the item of the right type
            set {_item} to {gentypes::%{_type}%::item}
            #spawn the item
            drop {_item} above {_loc} without velocity
            #make shure time is set and can't be <none>
            set {_time} to 1
            #get the propper interval of the right type
            set {_time} to {gentypes::%{_type}%::interval}
            #CHECK for atleast 1 tick to prefent a server crash (bc then this will spam without a delay)
            if {_time} < 1:
                set {_time} to 1
            #loop time amount times
            loop {_time} times:
                #check if the generator needs to stop bc of a script reload
                if {GEN.ON} is not set:
                    stop
                #check if the player turned his generators off
                if {genoff::%{_uuid}%} is set:
                    stop
                #wait 1 tick * {_time}
                wait 1 tick
            #start this function again after {_time} so it keeps repeating the spawn process
            genitem({_uuid}, {_loc})
            #stop the function so it doesnt go to the delete lines
            stop
        #if the block isn't there anymore and this data still beeing set is invalid data and should be deleted
        delete {generators::%{_uuid}%::%{_loc}%}
        delete {generators::%{_uuid}%::%{_loc}%::loc}
 
on script load:
    #stop all the generators
    delete {GEN.ON}
    #reset all the types
    loop {gentypes::*}:
        delete {gentypes::%loop-index%::*}
    delete {gentypes::*}
 
   #creating type wheat  - Level 1
    set {gentypes::wheat} to hay block
    set {gentypes::wheat::item} to coal
    #interval in ticks 20 ticks = 1 second
    set {gentypes::wheat::interval} to 200 #in ticks 20 ticks = 1 second
    set {gentypes::wheat::name} to "&bWheat {@namesuffix}"
 
   #creating type pumpkin - Level 2
    set {gentypes::pumpkin} to pumpkin
    set {gentypes::pumpkin::item} to pumpkin
    #interval in ticks 20 ticks = 1 second
    set {gentypes::pumpkin::interval} to 200
    set {gentypes::pumpkin::name} to "&bPumpkin {@namesuffix}"

#creating type melon - Level 3
    set {gentypes::melon} to melon
    set {gentypes::melon::item} to melon
    #interval in ticks 20 ticks = 1 second
    set {gentypes::melon::interval} to 200
    set {gentypes::melon::name} to "&bMelon {@namesuffix}"
 
#creating type coal - Level 4
    set {gentypes::coal} to coal block
    set {gentypes::coal::item} to coal
    #interval in ticks 20 ticks = 1 second
    set {gentypes::coal::interval} to 200
    set {gentypes::coal::name} to "&bCoal {@namesuffix}"

#creating type iron - Level 5
    set {gentypes::iron} to iron block
    set {gentypes::iron::item} to iron ingot
    #interval in ticks 20 ticks = 1 second
    set {gentypes::iron::interval} to 200
    set {gentypes::iron::name} to "&bIron {@namesuffix}"

#creating type diamond - Level 6
    set {gentypes::diamond} to diamond block
    set {gentypes::diamond::item} to diamond
    #interval in ticks 20 ticks = 1 second
    set {gentypes::diamond::interval} to 200
    set {gentypes::diamond::name} to "&bDiamond {@namesuffix}"

#creating type emerald - Level 7
    set {gentypes::emerald} to emerald block
    set {gentypes::emerald::item} to emerald
    #interval in ticks 20 ticks = 1 second
    set {gentypes::emerald::interval} to 200
    set {gentypes::emerald::name} to "&bEmerald {@namesuffix}"

#creating type redmush - Level 7
    set {gentypes::redmush} to red mushroom block
    set {gentypes::redmush::item} to red mushroom
    #interval in ticks 20 ticks = 1 second
    set {gentypes::redmush::interval} to 200
    set {gentypes::redmush::name} to "&bMushroom {@namesuffix}"

    #security measure waiting to make sure all generators have been stopped by now
    wait 1 second
 
    #Enable variable so generators are allowed to start again
    set {GEN.ON} to true
 
    #loop all uuids
    loop indices of {generators::*}:
        #loop all locations of a uuid
        loop {generators::%loop-value%::*}:
            #get formatted location of a generator of a uuid
            set {_l} to {generators::%loop-value-1%::%loop-index%::loc}
            #start generator
            genitem(loop-value-1, {_l})
 
#main command
command /gen [<text>] [<text>]:
    trigger:
        #premission check
        if player has permission "generator.admin":
            if arg-1 is "give":
                #check if the type exists
                if {gentypes::%arg 2%::name} is set:
                    #give the requested type
                    give player {gentypes::%arg 2%} named {gentypes::%arg 2%::name} with lore {gentypes::%arg 2%::lore}
                    stop
                send "{@prefix} &6- &cPlease select a valid gen type."
                stop
            if arg 1 is "on":
                #check if its off so u can't turn it on double
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &bGenerator is on now"
                    set {_uuid} to uuid of player
                    #allow generators to start for this player
                    delete {genoff::%uuid of player%}
                    #loop all locations of player
                    loop {generators::%{_uuid}%::*}:
                        #get formatted location of a generator of player
                        set {_l} to {generators::%{_uuid}%::%loop-index%::loc}
                        #start generator
                        genitem({_uuid}, {_l})
                else:
                    send "{@prefix} &bgenerator is already on"
                stop
            if arg 1 is "off":
                #check if the generators of the player aren't already off
                if {genoff::%uuid of player%} is not set:
                    send "{@prefix} &bGenerator is off now"
                    #turn generators off
                    set {genoff::%uuid of player%} to true
                else:
                    send "{@prefix} &bgenerator is already off"
                stop
            send "{@prefix} &6- &c/gen [<option>] [<gentype>]"
 
#debug command to delete all data if some manage to get stuck WARNING this is all data so all generators placed currently are lost.
command /DEBUGGENRESET:
    trigger:
        loop indices of {generators::*}:
            loop {generators::%loop-value%::*}:
                delete {generators::%loop-value-1%::%loop-index%::*}
            delete {generators::%loop-value%::*}
        delete {generators::*}
        delete {genoff::*}
 
#break event
on break:
    #check if the current block is a generator and if this player is the owner
    if {generators::%uuid of player%::%location of event-block%} is set:
        #check if the player is sneaking
        if player is sneaking:
            send "{@prefix} &bGenerator collected!"
            #get type of the broken generator
            set {_type} to {generators::%uuid of player%::%location of event-block%}
            #delete data of generator
            delete {generators::%uuid of player%::%location of event-block%}
            delete {generators::%uuid of player%::%location of event-block%::loc}
            #give back generator
            give player {gentypes::%{_type}%} named {gentypes::%{_type}%::name} with lore {gentypes::%{_type}%::lore}
            stop
        #cancels block break if the player is not sneaking
        cancel event
    #check if the block is a generator but if the player is not the owner
    loop indices of {generators::*}:
        if {generators::%loop-value%::%location of event-block%} is set:
            #cancel block break bc the player is not the owner
            cancel event
            #can stop the loop bc the event already has been canceled
            stop
 
#place event
On place:
    #get all the current types of generators
    loop {gentypes::*}:
        #check if the tool of the player is a know block that could be a generator
        if player's tool is loop-value:
            #check if the name of tool of the player is equal to how a generator is supposed to be called
            if name of player's tool is {gentypes::%loop-index%::name}:
                #check if there is any old corrupted data for this location
                if {generators::%uuid of player%::%location of event-block%} is set:
                    #delete corrupted data
                    delete {generators::%uuid of player%::%location of event-block%}
                    delete {generators::%uuid of player%::%location of event-block%::loc}
                #Create the data for the new generator
                set {generators::%uuid of player%::%location of event-block%} to loop-index
                set {generators::%uuid of player%::%location of event-block%::loc} to location of event-block
                send "{@prefix} &bGenerator Placed!" to player
                #Check if this player has its generators off
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &bU currently have generators off. /gen on" to player
                else:
                    #start the new created generator
                    genitem(uuid of player, location of event-block)
            stop
Btw i found a bug when u place the gen it instantly spawns the item i mean that can be abused ppl can break and place it ton of times to make it for faster
 
Through console because the player wont have the generator.admin perm node so he wont find out and abuse it and idk any other way to do it anyways upgradable i meant that when u shift right click it upgrades it to the next level of the gen like from wheat to pumpkin i put new gens by the order at the script u sended me u can check it out
Code:
#WARNING!!!!
 
#This Script has a known bug:
# If a generator has been placed and then someone moves it with a piston it gets deleted(if it was on or gets turned on) + the owner has no way to get his generator back.
# U can enable the code right below here as temperarly fix if u don't mind disableing pistons. I don't have time to make a propper fix rn:
 
# On piston extend:
#     cancel event
#
# On piston retract:
#     cancel event
 
#End Temp fix
 
options:
    #Prefix
    prefix: &7[&e&lCoil&7]&f&l -
    #lore of the generator item to be placed
    lore: &7[&e&lCoil&7]&f&l - &6- &bSneak and mine to pickup
    #name suffix of the generator
    namesuffix: Generator
 
#function to manage spawning items
function genitem(uuid: text,loc: location):
    #check if the player didnt turned his generators off
    if {genoff::%{_uuid}%} is set:
        stop
    #check if the generator still exists
    if {generators::%{_uuid}%::%{_loc}%} is set:
        #get the type of generator
        set {_type} to {generators::%{_uuid}%::%{_loc}%}
        # Check if the block at the location is still valid
        if block at {_loc} is {gentypes::%{_type}%}:
            #get the item of the right type
            set {_item} to {gentypes::%{_type}%::item}
            #spawn the item
            drop {_item} above {_loc} without velocity
            #make shure time is set and can't be <none>
            set {_time} to 1
            #get the propper interval of the right type
            set {_time} to {gentypes::%{_type}%::interval}
            #CHECK for atleast 1 tick to prefent a server crash (bc then this will spam without a delay)
            if {_time} < 1:
                set {_time} to 1
            #loop time amount times
            loop {_time} times:
                #check if the generator needs to stop bc of a script reload
                if {GEN.ON} is not set:
                    stop
                #check if the player turned his generators off
                if {genoff::%{_uuid}%} is set:
                    stop
                #wait 1 tick * {_time}
                wait 1 tick
            #start this function again after {_time} so it keeps repeating the spawn process
            genitem({_uuid}, {_loc})
            #stop the function so it doesnt go to the delete lines
            stop
        #if the block isn't there anymore and this data still beeing set is invalid data and should be deleted
        delete {generators::%{_uuid}%::%{_loc}%}
        delete {generators::%{_uuid}%::%{_loc}%::loc}
 
on script load:
    #stop all the generators
    delete {GEN.ON}
    #reset all the types
    loop {gentypes::*}:
        delete {gentypes::%loop-index%::*}
    delete {gentypes::*}
 
   #creating type wheat  - Level 1
    set {gentypes::wheat} to hay block
    set {gentypes::wheat::item} to coal
    #interval in ticks 20 ticks = 1 second
    set {gentypes::wheat::interval} to 200 #in ticks 20 ticks = 1 second
    set {gentypes::wheat::name} to "&bWheat {@namesuffix}"
 
   #creating type pumpkin - Level 2
    set {gentypes::pumpkin} to pumpkin
    set {gentypes::pumpkin::item} to pumpkin
    #interval in ticks 20 ticks = 1 second
    set {gentypes::pumpkin::interval} to 200
    set {gentypes::pumpkin::name} to "&bPumpkin {@namesuffix}"

#creating type melon - Level 3
    set {gentypes::melon} to melon
    set {gentypes::melon::item} to melon
    #interval in ticks 20 ticks = 1 second
    set {gentypes::melon::interval} to 200
    set {gentypes::melon::name} to "&bMelon {@namesuffix}"
 
#creating type coal - Level 4
    set {gentypes::coal} to coal block
    set {gentypes::coal::item} to coal
    #interval in ticks 20 ticks = 1 second
    set {gentypes::coal::interval} to 200
    set {gentypes::coal::name} to "&bCoal {@namesuffix}"

#creating type iron - Level 5
    set {gentypes::iron} to iron block
    set {gentypes::iron::item} to iron ingot
    #interval in ticks 20 ticks = 1 second
    set {gentypes::iron::interval} to 200
    set {gentypes::iron::name} to "&bIron {@namesuffix}"

#creating type diamond - Level 6
    set {gentypes::diamond} to diamond block
    set {gentypes::diamond::item} to diamond
    #interval in ticks 20 ticks = 1 second
    set {gentypes::diamond::interval} to 200
    set {gentypes::diamond::name} to "&bDiamond {@namesuffix}"

#creating type emerald - Level 7
    set {gentypes::emerald} to emerald block
    set {gentypes::emerald::item} to emerald
    #interval in ticks 20 ticks = 1 second
    set {gentypes::emerald::interval} to 200
    set {gentypes::emerald::name} to "&bEmerald {@namesuffix}"

#creating type redmush - Level 7
    set {gentypes::redmush} to red mushroom block
    set {gentypes::redmush::item} to red mushroom
    #interval in ticks 20 ticks = 1 second
    set {gentypes::redmush::interval} to 200
    set {gentypes::redmush::name} to "&bMushroom {@namesuffix}"

    #security measure waiting to make sure all generators have been stopped by now
    wait 1 second
 
    #Enable variable so generators are allowed to start again
    set {GEN.ON} to true
 
    #loop all uuids
    loop indices of {generators::*}:
        #loop all locations of a uuid
        loop {generators::%loop-value%::*}:
            #get formatted location of a generator of a uuid
            set {_l} to {generators::%loop-value-1%::%loop-index%::loc}
            #start generator
            genitem(loop-value-1, {_l})
 
#main command
command /gen [<text>] [<text>]:
    trigger:
        #premission check
        if player has permission "generator.admin":
            if arg-1 is "give":
                #check if the type exists
                if {gentypes::%arg 2%::name} is set:
                    #give the requested type
                    give player {gentypes::%arg 2%} named {gentypes::%arg 2%::name} with lore {gentypes::%arg 2%::lore}
                    stop
                send "{@prefix} &6- &cPlease select a valid gen type."
                stop
            if arg 1 is "on":
                #check if its off so u can't turn it on double
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &bGenerator is on now"
                    set {_uuid} to uuid of player
                    #allow generators to start for this player
                    delete {genoff::%uuid of player%}
                    #loop all locations of player
                    loop {generators::%{_uuid}%::*}:
                        #get formatted location of a generator of player
                        set {_l} to {generators::%{_uuid}%::%loop-index%::loc}
                        #start generator
                        genitem({_uuid}, {_l})
                else:
                    send "{@prefix} &bgenerator is already on"
                stop
            if arg 1 is "off":
                #check if the generators of the player aren't already off
                if {genoff::%uuid of player%} is not set:
                    send "{@prefix} &bGenerator is off now"
                    #turn generators off
                    set {genoff::%uuid of player%} to true
                else:
                    send "{@prefix} &bgenerator is already off"
                stop
            send "{@prefix} &6- &c/gen [<option>] [<gentype>]"
 
#debug command to delete all data if some manage to get stuck WARNING this is all data so all generators placed currently are lost.
command /DEBUGGENRESET:
    trigger:
        loop indices of {generators::*}:
            loop {generators::%loop-value%::*}:
                delete {generators::%loop-value-1%::%loop-index%::*}
            delete {generators::%loop-value%::*}
        delete {generators::*}
        delete {genoff::*}
 
#break event
on break:
    #check if the current block is a generator and if this player is the owner
    if {generators::%uuid of player%::%location of event-block%} is set:
        #check if the player is sneaking
        if player is sneaking:
            send "{@prefix} &bGenerator collected!"
            #get type of the broken generator
            set {_type} to {generators::%uuid of player%::%location of event-block%}
            #delete data of generator
            delete {generators::%uuid of player%::%location of event-block%}
            delete {generators::%uuid of player%::%location of event-block%::loc}
            #give back generator
            give player {gentypes::%{_type}%} named {gentypes::%{_type}%::name} with lore {gentypes::%{_type}%::lore}
            stop
        #cancels block break if the player is not sneaking
        cancel event
    #check if the block is a generator but if the player is not the owner
    loop indices of {generators::*}:
        if {generators::%loop-value%::%location of event-block%} is set:
            #cancel block break bc the player is not the owner
            cancel event
            #can stop the loop bc the event already has been canceled
            stop
 
#place event
On place:
    #get all the current types of generators
    loop {gentypes::*}:
        #check if the tool of the player is a know block that could be a generator
        if player's tool is loop-value:
            #check if the name of tool of the player is equal to how a generator is supposed to be called
            if name of player's tool is {gentypes::%loop-index%::name}:
                #check if there is any old corrupted data for this location
                if {generators::%uuid of player%::%location of event-block%} is set:
                    #delete corrupted data
                    delete {generators::%uuid of player%::%location of event-block%}
                    delete {generators::%uuid of player%::%location of event-block%::loc}
                #Create the data for the new generator
                set {generators::%uuid of player%::%location of event-block%} to loop-index
                set {generators::%uuid of player%::%location of event-block%::loc} to location of event-block
                send "{@prefix} &bGenerator Placed!" to player
                #Check if this player has its generators off
                if {genoff::%uuid of player%} is set:
                    send "{@prefix} &bU currently have generators off. /gen on" to player
                else:
                    #start the new created generator
                    genitem(uuid of player, location of event-block)
            stop
[doublepost=1583414022,1583413917][/doublepost]
Btw i found a bug when u place the gen it instantly spawns the item i mean that can be abused ppl can break and place it ton of times to make it for faster

Okay bug will be easy fix but how do they buy the generator then?
 
Status
Not open for further replies.