Help on Gen Skript

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


Jun 5, 2021
I have a generator skript that works like a charm, it works like how you want it to work. But there's a problem. The part of the skript that allows the owner to be able to remove the generator (and only the owner who have placed the generator) is kinda broken.

It was working fine when i was testing it in a server, but suddenly when i restarted my server to load some plugins, it stopped working and made all the generators that i placed is said that i wasn't the owner of the generator. (You can see more details when you read the skript)

** Please tell me how i can fix this problem and make it work once again, if it is not possible, please tell me how i can remove this feature so i don't have to struggle so much.



#Register a gen template.
function registerGen(id: integer, discrim: string, item: item, block: item, upgrade: integer, drop: item):
    set {gens::internal::%{_id}%} to {_discrim}
    set {gen::internal::%{_id}%::item} to {_item}
    set {gen::internal::%{_id}%::block} to {_block}
    set {gen::internal::%{_id}%::upgrade} to {_upgrade}
    set {gen::internal::%{_id}%::drop} to {_drop}

#Registers a player's gen, i.e. placed generator.
function placeGen(p: player, block: block, id: integer):
    set {_u} to uuid of {_p}
    add location of {_block} to {gens::player::%{_u}%::*}
    set {_discrim} to size of {gens::player::%{_u}%::*}
    set {_loc} to location of {_block}
    set {gens::all::%{_loc}%} to {_discrim}
    set {gen::player::%{_u}%::%{_discrim}%::id} to {_id}

#Registers the template generators.
on load:
    #registerGen(id, "name_id", (inventory item of block), block type, price to upgrade, (inventory item of drop))

    registerGen(1, "wheat_gen", (hay bale named "&eWheat &fGen &7Tier I" with lore "&7» &fUpgrade: &e&n$2,000" and "&7» &fOutput: &e&n$5"), hay bale, 2000, (wheat named "&eWheat &7Tier I" with lore "&7 &fGenerator Drop" and "&7 &fSell Price: &e&n$5"))

    registerGen(2, "melon_gen", (melon named "&aMelon &fGen &7Tier II" with lore "&7 &fUpgrade: &a&n$5,000" and "&7 &fOutput: &a&n$10"), melon, 5000, (melon slice named "&aMelon &7Tier II" with lore "&7 &fGenerator Drop" and "&7 &fSell Price: &a&n$10"))

    registerGen(3, "pumpkin_gen", (pumpkin named "&6Pumpkin &fGen &7Tier III" with lore "&7 &fUpgrade: &6&n$10,000" and "&7 &fOutput: &6&n$20"), pumpkin, 10000, (pumpkin pie named "&6Pumpkin &7Tier III" with lore "&7 &fGenerator Drop" and "&7 &fSell Price: &6&n$20"))

#Registers a player's gen upon placement.
on place:
    loop {gens::internal::*}:
        if tool = {gen::internal::%loop-index%::item}:
            if ({maxgens::%player's uuid%} ? 50) > size of {gens::player::%player's uuid%::*}:
                placeGen(player, event-block, loop-index parsed as integer)
                send action bar "Server &8» &7You have placed a generator! &6[&e%size of {gens::player::%player's uuid%::*}%&6/&e%({maxgens::%player's uuid%} ? 50)%&6]" to player
                cancel event
                send "Server &8» &cYou have already reached the maximum generators available!"
            exit loop

#Unregisters a player's gen upon destruction.
on left click:
    player is sneaking
    if {gens::all::%location of clicked block%} is set:
        set {_discrim} to {gens::all::%location of clicked block%}
        if {gens::player::%player's uuid%::*} contains location of clicked block:
            drop {gen::internal::%{gen::player::%player's uuid%::%{_discrim}%::id}%::item} at clicked block without velocity
            delete {gen::player::%player's uuid%::%{_discrim}%::id}
            remove location of clicked block from {gens::player::%player's uuid%::*}
            send action bar "Server &8» &7You have destroyed a generator! &6[&e%size of {gens::player::%player's uuid%::*}%&6/&e%({maxgens::%player's uuid%} ? 50)%&6]" to player
            delete {gens::all::%location of clicked block%}
            set clicked block to air
            cancel event
            send action bar "Server &8» &cThat isn't your generator!" to player

#Cancels breaking of gens.
on break:
    if {gens::all::%location of event-block%} is set:
        play sound "" for player
        send action bar "Server &8» &cShift left click to pickup your generator!" to player
        cancel event

#Spawns an item above every generator.
every 2 seconds:
    loop all players:
        loop {gens::player::%loop-player's uuid%::*}:
            drop {gen::internal::%{gen::player::%loop-player's uuid%::%loop-index%::id}%::drop} at block above loop-value-2 without velocity

#Upgrades a generator.
on right click:
    if player is sneaking:
        if {gens::all::%location of clicked block%} is set:
            set {_discrim} to {gens::all::%location of clicked block%}
            if {gens::player::%player's uuid%::*} contains location of clicked block:
                set {_level} to {gen::player::%player's uuid%::%{_discrim}%::id} + 1
                if {gens::internal::%{_level}%} is set:
                    if player's balance >= {gen::internal::%{gen::player::%player's uuid%::%{_discrim}%::id}%::upgrade}:
                        remove {gen::internal::%{gen::player::%player's uuid%::%{_discrim}%::id}%::upgrade} from player's balance
                        set clicked block to {gen::internal::%{_level}%::block}
                        add 1 to {gen::player::%player's uuid%::%{_discrim}%::id}
                        send "Server &8» &7Generator upgrade!"
                        play sound "ui.toast.challenge_complete" for player
                        send "Server &8» &cInsufficient funds!"
                    send "Server &8» &cYou are at max upgrades!"

#Sets a player's max gens.
command /setgens <offline player> <integer>:
    permission: console.setgens
    permission message: Server &8» &cSorry, You don't have permission to use this command!
        send "Server &8» &7You have set &e%arg-1%&e's &7gen limit to &e%arg-2%&7!"
        send "Server &8» &7Your gen limit has been set to &e%arg-2% &7by &e%sender%&7!" to arg-1
        set {maxgens::%arg-1's uuid%} to arg-2
        play sound "block.note_block.pling" at volume 60 to arg-1 and player

set event-block to {_b}
        set {g::l::%location of event-block%} to location of event-block
        set {g::o ::%location of event-block%} to uuid of player