Solved If loop-value contains

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

Status
Not open for further replies.

porcodioo

Member
Nov 4, 2022
4
0
1
19
Hello, today i tried to make a skript that searches an item through the whole server (also inside a players' inventory). The part that searches a player's inventory works, although the part that searches the chest's inventory doesn't. How can i make this work?

Code:
function itemSearch(p: player, i: item):
  set {_results.%{_p}%} to 0
  send "&a&lItemSearch &8- &7You're searching an item..." to {_p}
  loop all chests:
    set {_loc} to loop-value's location
    if block at {_loc} contains {_i}:
      add 1 to {_results.%{_p}%}
      set {_v} to loop-value
      set {_x} to {_v}'s x coordinate
      set {_y} to {_v}'s y coordinate
      set {_z} to {_v}'s z coordinate
      send "&8 - &7Container &8(&7%{_x}% %{_y}% %{_z}%&8)" to {_p}
  loop all barrels:
    loop items in loop-value:
      if loop-value is {_i}:
        add 1 to {_results.%{_p}%}
        set {_v} to loop-value
        set {_x} to {_v}'s x coordinate
        set {_y} to {_v}'s y coordinate
        set {_z} to {_v}'s z coordinate
        send "&8 - &7Container &8(&7%{_x}% %{_y}% %{_z}%&8)" to {_p}
  loop all players:
    if loop-player has {_i}:
      add 1 to {_results.%{_p}%}
      send "&8 - &7Player &8(&7Open inv&8)" to {_p}
  send "&a&lItemSearch &8- &7Process terminated (Risultati: %{_results.%{_p}%}%)" to {_p}
 
command /itemsearch:
  trigger:
    if player's tool isn't air:
      set {_i} to player's held item
      set {_t} to name of player's held item
      set {_l::*} to lore of player's held item
      globalSearch(player, {_i})

Errors: None
 
I don't think you can loop all the specific block.
Maybe you need to listen on place and on break event and store the location of all chests and barrels in a list, and loop this list when searching for item.
 
I don't think you can loop all the specific block.
Maybe you need to listen on place and on break event and store the location of all chests and barrels in a list, and loop this list when searching for item.
This would work if the chests weren't already placed. I was considering for a possible reset, but that's exaggerated.
I think looping all blocks makes the server lag too much.
[doublepost=1672248167,1672229895][/doublepost]
I don't think you can loop all the specific block.
Maybe you need to listen on place and on break event and store the location of all chests and barrels in a list, and loop this list when searching for item.
Even though i tried this, it still doesn't work. Can you show an example of the code?
 
This would work if the chests weren't already placed. I was considering for a possible reset, but that's exaggerated.
I think looping all blocks makes the server lag too much.
[doublepost=1672248167,1672229895][/doublepost]
Even though i tried this, it still doesn't work. Can you show an example of the code?
Code:
# Store the location of containers
on place:
 
    event-block is chests or barrel
 
    set {_loc} to location of event-block
 
    set {_w} to {_loc}'s world # Also store world
    set {_x} to {_loc}'s x coordinate
    set {_y} to {_loc}'s y coordinate
    set {_z} to {_loc}'s z coordinate
 
    add "%{_x}%/%{_y}%/%{_z}%/%{_w}%" to {containerList::*} # Just for I don't like to store the full location
    send "You have placed a container" to player
 
# Remove the location (Not so reliable, you should also listen BlockExplodeEvent etc)
on break:
 
    event-block is chests or barrel
 
    set {_loc} to location of event-block
 
    set {_w} to {_loc}'s world
    set {_x} to {_loc}'s x coordinate
    set {_y} to {_loc}'s y coordinate
    set {_z} to {_loc}'s z coordinate
 
    remove "%{_x}%/%{_y}%/%{_z}%/%{_w}%" from {containerList::*}
    send "You have broke a container" to player
 
function itemSearch(p: player, i: item) :: number: # Return the number of target containers

    set {_result} to 0
 
    send "&a&lItemSearch &8- &7You're searching an item..." to {_p}
 
    loop {containerList::*}:

        set {_data::*} to loop-value-1 parsed as "%number%/%number%/%number%/%world%"
        set {_loc} to location({_data::1},{_data::2},{_data::3},{_data::4})
    
        loop inventory of block at {_loc}: # Loop the inventory of container

            1 of loop-value-2 is {_i}
        
            add 1 to {_result}
            send "&8 - &7Container &8(&7%{_data::1}% %{_data::2}% %{_data::3}% %{_data::4}%&8)" to {_p}
 
    return {_result}
 
command /itemsearch:
    trigger:
 
        if player's tool is not air:
 
            set {_i} to player's held item
            set {_n} to itemSearch(player, 1 of {_i})
            send "&8 - &7Container Number: %{_n}%"
This should work for you.
 
Last edited:
Status
Not open for further replies.