Solved Is there a way to make this code more efficient?

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

KoenMaster05

New Member
Jun 5, 2023
7
2
3
19
Hi everyone, I am very new to coding.
I made a skript for fortune to work on all blocks and so that they go in the player's inventory. The skript is working fine, but I was wondering If I can make the code more efficent, more compact.

I added the skript in a .txt file below
thanks!
 

Attachments

  • fortune&autopickup.txt
    5.5 KB · Views: 115
That's what I had first, but I wrote this skript to make it automatically turn into 8 cobblestone. The skript works just fine, I was just wondering if the code could be more compact.
 
That's what I had first, but I wrote this skript to make it automatically turn into 8 cobblestone. The skript works just fine, I was just wondering if the code could be more compact.
You can put all your multiplies into list like as set {list::%item%} to 5#multiplier
then:
Hi everyone, I am very new to coding.
I made a skript for fortune to work on all blocks and so that they go in the player's inventory. The skript is working fine, but I was wondering If I can make the code more efficent, more compact.

I added the skript in a .txt file below
thanks!
You can optimize/replace like that:

Code:
on load:
    set {-extendableDrop::stripped oak log} to 4 of oak log
    # ... all your's replacements

on mine:
    gamemode of player is survival
    if player's tool is enchanted with fortune
        set {_fortuneLevel} to level of fortune on player's tool + 1
        set {_fortuneMultiplier} to random integer between 1 and {_l}
    else:
        set {_fortuneMultiplier} to 1
    {-extendableDrop::%type of event-block%} is set
    clear drop
    set {_droppedItem} to {-extendableDrop::%type of event-block%}
    set {_droppedItem} to (item amount of {_droppedItem})*{_fortuneMultiplier} of {_droppedItem}
    if player have space for {_droppedItem}:
        give {_droppedItem} to player
    else:
        drop {_droppedItem} at event-block
 
  • Like
Reactions: KoenMaster05
You can put all your multiplies into list like as set {list::%item%} to 5#multiplier
then:

You can optimize/replace like that:

Code:
on load:
    set {-extendableDrop::stripped oak log} to 4 of oak log
    # ... all your's replacements

on mine:
    gamemode of player is survival
    if player's tool is enchanted with fortune
        set {_fortuneLevel} to level of fortune on player's tool + 1
        set {_fortuneMultiplier} to random integer between 1 and {_l}
    else:
        set {_fortuneMultiplier} to 1
    {-extendableDrop::%type of event-block%} is set
    clear drop
    set {_droppedItem} to {-extendableDrop::%type of event-block%}
    set {_droppedItem} to (item amount of {_droppedItem})*{_fortuneMultiplier} of {_droppedItem}
    if player have space for {_droppedItem}:
        give {_droppedItem} to player
    else:
        drop {_droppedItem} at event-block
Sorry for the late response, Do I need SkQuery or something for this to work? Because currently, it can't tell if type of event-block is in the extendableDrop options.

{-extendableDrop::%type of event-block%} is set
^
It can't understand that part