1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script Easy skript to Auto Compress materials! (With Full Explaination) 1.0.1

Auto Compresser

  1. JakeTheChad
    Supported Minecraft Versions:
    • 1.16, 1.17, 1.18
    This easy to edit code will make compressing a lot easier, especially for new servers!

    Want to check the code and understand how it works to get better at coding?
    Information about the code can be found as an example of the Floor function in the SkriptHub Docs!

    Further info can be found below:

    Periodical Event:

    The code Checks every 1 second, this can be changed but to avoid too much lag i just set it to 1 second.
    upload_2022-4-11_4-28-1.png


    Loop:

    So every 1 second we will loop all players:
    upload_2022-4-11_4-11-28.png



    But looping all the players is a waste of performance, why not just loop all the players that actually have the material we want to compress? Good idea!


    Contains:

    upload_2022-4-11_4-12-30.png
    So we are looping all the players whose inventory contain atleast 64 of oak wood which is the average minimum amount for a compressed oak wood!


    Amount of Items:

    After this, we need to check how much wood there is in the loop-player's inventory, so we set a local variable to the total amount of oak wood in the loop-player's inventory, {_n} stands for number but you can put whatever you want!
    upload_2022-4-11_4-14-48.png


    Arithmetic:

    now we divide the total amount of oak wood the player has / 64
    upload_2022-4-11_4-16-49.png this way we have the number of stacks
    (64 / 64) = 1 stack
    (128 / 64) = 2 stacks
    and so on

    BUT WAIT! what if its not a multiple of 64?? (ex. 70 oak wood, 165 oak wood) good question! to solve this problem we need to round down the obtained number of stacks!


    Floor: (you can find the same code in the examples of this function, there's a small explaination there aswell!)

    upload_2022-4-11_4-18-49.png what the floor function does is very simple, it... takes the value to the floor, no really, picture every full number as a room and each number is on top of each other, by using this function with a number that has decimals (ex. 5.1, 9.35), it will be rounded down (ex. 5.1 = 5, 9.35 = 9)

    lets take 163 as an example, dividing it by 64 gets up a total of 2.54 stacks which is not what we want, by rounding this number down we get the integer "2" and we leave the 0.54 , furthermore if we were to multiply these numbers by 64, we will notice that 2 * 64 = 128 (2 stacks) and that 0.54 * 64 = 35 which is the remaining wood that does not get affected by this code!

    Hold on tight, i know this is a very long explaination but bare with me, everyone gains from this!

    Loop: (same as before)

    now we loop {_n} times
    upload_2022-4-11_4-24-4.png
    what this means it that whatever is intended inside this loop will happen {_n} times ({_n} being the amount of stacks the player has)
    ex. if i had 1 stack this will loop only once, if i had 7 stacks this will loop 7 times etc.

    Change Effect [Remove] + Arithmetic + Inventory [Expression]

    now we remove the wood that is going to be compressed
    upload_2022-4-11_4-25-31.png
    by removing the amount of stacks * 64 we effectively remove the exact amount of compressable oak wood in the player's inventory

    Change Effect [Give]

    upload_2022-4-11_4-26-29.png
    now we simply give the amount of stacks ( 1 stack = 1 compressed item ) as 1 compressed item, to the loop player!

    Message:

    (If you're unfamiliar with skript, when using variables in text you need to put them between %%, this way skript knows that you're not just putting some brackets into some text but you want to insert the value of that variable there!)

    last but not necessary, lets send a message to the player that this compression has been done :emoji_grinning:
    upload_2022-4-11_4-28-12.png

    For any help leave comments!
    I will always be active in the Skunity Forums!