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.
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}%"