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

LMKgaming

Member
Mar 13, 2025
21
1
3
28
Can anyone help me? I do this code below which i think these are same result, but when i test it, the function way return wrong value at variable amout of {_block} while the direct way also use the {_block} variable but i return the right value.
Only amount of {_block} is wrong, another custom item in {_blocks::*} is counting right result.
Code:
function getItem(item: string, level: integer) :: item:
    set {_n} to nbt compound from file "plugins/Skript/serverData/%{_item}%%{_level}%.nbt"
    set {_block} to item from nbt {_n}
    return {_block}

function countItem(itemList: items, p: player) :: integers:
    loop {_itemList::*}:
        set {_res::%loop-index%} to 0
    loop all items in the inventory of {_p}:
        loop {_itemList::*}:
            if custom nbt of loop-value-2 is not nbt compound from "{}":
                if custom nbt of loop-item is custom nbt of loop-value-2:
                    add amount of loop-item to {_res::%loop-index%}
            else if loop-item is loop-value-2:
                add amount of loop-item to {_res::%loop-index%}
    return {_res::*}

every 0.5 seconds:
    loop {rank::sergeant::*}:
        set {_player} to loop-value-1 parsed as player
        if {_player} is online:
            loop {autoCrafting::%loop-value-1%::*}:
                # Prepare variables
                set {_block} to loop-index-2
                set {_blocks::*} to getItem({_block}, 1), getItem({_block}, 2) and getItem({_block}, 3)
                replace all "_" with " " in {_block}
                set {_block} to "%{_block}%" parsed as item type
                add {_block} to {_blocks::*}
                
                # Count item in inventory using function
                set {_lists::*} to countItem({_blocks::*}, {_player})
                broadcast "%{_lists::*}%"
                
                # Count item in inventory directly
                set {_amount} to 0
                set {_amount_lv_1} to 0
                set {_amount_lv_2} to 0
                loop all items in the inventory of {_player}:
                    if custom nbt of loop-item is custom nbt of {_blocks::1}:
                        add amount of loop-item to {_amount_lv_1}
                    else if custom nbt of loop-item is custom nbt of {_blocks::2}:
                        add amount of loop-item to {_amount_lv_2}
                    else if custom nbt of loop-item is custom nbt of {_blocks::3}:
                        continue
                    else if custom nbt of loop-item is nbt compound from "{}":
                        if loop-item is {_block}:
                            add amount of loop-item to {_amount}
                broadcast "%{_block}% = %{_amount}% : %{_amount_lv_1}% : %{_amount_lv_2}%"
 
I may be very wrong but I believe the issue is this:
There is no variable name here just a "{}"
Code:
if custom nbt of loop-value-2 is not nbt compound from "{}": #<------


Also a general fyi, while your skript will be lag free for now, once you start getting more players you will have lag issues having to loop an entire list every 0.5 seconds. You may want to look at changing this in the future.