Solved Checking player's inventory for item ignoring lore

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

    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.

inavir

Member
May 1, 2017
10
0
0
Should be simple enough right?
code_language.skript:
command /test:
  trigger:
    set {_amount} to 4
    player has {_amount} of stone with of power 1 named test:
      broadcast "good"
    else:
      broadcast "bad"

Unfortunately this works only until I add lore to the item. I'd use skQuery's lored itemstack expression, except the lore of the item is multilined, and varies, so I just want to match the item type, enchantment and name, or at least just the name.

I've found that the code below works, but it's a fairly inelegant solution, and was hoping for an alternative.
code_language.skript:
command /test:
  trigger:
    set {_amount} to 4
    loop all items in player's inventory:
      name of loop-item contains "test":
        set {_item} to loop-item
        player has {_amount} of {_item}:
          broadcast "good"

I've also tried turning that into a function, except this time the amount check fails for whatever reason.
code_language.skript:
function hasNamedItem(player: player, name: text, amount: number) :: boolean:
  set {_hasNamedItem} to false
  loop all items in {_player}'s inventory:

    name of loop-item contains "%{_name}%":
      broadcast "Name check success" # Succeeds

      set {_item} to loop-item

      broadcast "Checking if %{_player}% has %{_amount}%"
      {_player} has {_amount} of {_item}:
        broadcast "Amount check success" # Fails
        set {_hasNamedItem} to true
        stop loop

  return {_hasNamedItem}

command /test:
  trigger:
    if hasNamedItem(player, "test", 1):
      broadcast "yay"
    else:
      broadcast "boo"
 
Well the original snippet would error but
code_language.skript:
if items in player's inventory where [name of item input is "123"] is set:
 
  • Like
Reactions: inavir
Well the original snippet would error but
code_language.skript:
if items in player's inventory where [name of item input is "123"] is set:

This seems to be give me an internal error when I use this.
code_language.skript:
command /test:
  trigger:
    if items in player's inventory where [name of item input is "123"] is set:
      broadcast "yay"
    else:
      broadcast "boo"

Code:
[20:19:03] [Server thread/ERROR]: #!#!
[20:19:03] [Server thread/ERROR]: #!#! [Skript] Severe Error:
[20:19:03] [Server thread/ERROR]: #!#!
[20:19:03] [Server thread/ERROR]: #!#! Something went horribly wrong with Skript.
[20:19:03] [Server thread/ERROR]: #!#! This issue is NOT your fault! You can't probably fix it yourself, either.
[20:19:03] [Server thread/ERROR]: #!#! It looks like you are using some plugin(s) that alter how Skript works (addons).
[20:19:03] [Server thread/ERROR]: #!#! Here is full list of them:
[20:19:03] [Server thread/ERROR]: #!#! SkStuff Skellett (https://forums.skunity.com/resources/skellett-the-addon-with-a-beast-name.24/) SkQuery TuSKe (github.com/Tuke-Nuke/TuSKe)
[20:19:03] [Server thread/ERROR]: #!#! We could not identify which of those are specially related, so this might also be Skript issue.
[20:19:03] [Server thread/ERROR]: #!#! You should try disabling those plugins one by one, trying to find which one causes it.
[20:19:03] [Server thread/ERROR]: #!#! If the error doesn't disappear even after disabling all listed plugins, it is probably Skript issue.
[20:19:03] [Server thread/ERROR]: #!#! In that case, you will be given instruction on how should you report it.
[20:19:03] [Server thread/ERROR]: #!#! On the other hand, if the error disappears when disabling some plugin, report it to author of that plugin.
[20:19:03] [Server thread/ERROR]: #!#! Only if the author tells you to do so, report it as Skript issue (url below)
[20:19:03] [Server thread/ERROR]: #!#! Issue tracker: https://github.com/bensku/Skript/issues (only if you know what you're doing!)
[20:19:03] [Server thread/ERROR]: #!#!
[20:19:03] [Server thread/ERROR]: #!#! Stack trace:
[20:19:03] [Server thread/ERROR]: #!#! java.lang.ArrayStoreException: ch.njol.skript.util.InventorySlot
[20:19:03] [Server thread/ERROR]: #!#!     at com.w00tmast3r.skquery.elements.expressions.ExprInput.get(ExprInput.java:24)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.lang.util.SimpleExpression.getArray(SimpleExpression.java:104)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.expressions.base.PropertyExpression.get(PropertyExpression.java:74)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.lang.util.SimpleExpression.check(SimpleExpression.java:163)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.lang.util.SimpleExpression.check(SimpleExpression.java:158)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.conditions.CondCompare.check(CondCompare.java:258)
[20:19:03] [Server thread/ERROR]: #!#!     at com.w00tmast3r.skquery.skript.LambdaCondition.check(LambdaCondition.java:27)
[20:19:03] [Server thread/ERROR]: #!#!     at com.w00tmast3r.skquery.elements.expressions.ExprWhere.get(ExprWhere.java:31)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.lang.util.SimpleExpression.getAll(SimpleExpression.java:78)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.conditions.CondIsSet.check(CondIsSet.java:75)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.conditions.CondIsSet.check(CondIsSet.java:81)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.lang.Condition.run(Condition.java:56)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.lang.Conditional.walk(Conditional.java:51)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.lang.TriggerItem.walk(TriggerItem.java:89)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.lang.Trigger.execute(Trigger.java:55)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.command.ScriptCommand.execute2(ScriptCommand.java:220)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.command.ScriptCommand.execute(ScriptCommand.java:182)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.command.Commands.handleCommand(Commands.java:269)
[20:19:03] [Server thread/ERROR]: #!#!     at ch.njol.skript.command.Commands$1.onPlayerCommand(Commands.java:164)
[20:19:03] [Server thread/ERROR]: #!#!     at com.destroystokyo.paper.event.executor.MethodHandleEventExecutor.execute(MethodHandleEventExecutor.java:35)
[20:19:03] [Server thread/ERROR]: #!#!     at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:78)
[20:19:03] [Server thread/ERROR]: #!#!     at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
[20:19:03] [Server thread/ERROR]: #!#!     at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:514)
[20:19:03] [Server thread/ERROR]: #!#!     at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:499)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PlayerConnection.handleCommand(PlayerConnection.java:1417)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1230)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:45)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PacketPlayInChat.a(PacketPlayInChat.java:5)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:14)
[20:19:03] [Server thread/ERROR]: #!#!     at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
[20:19:03] [Server thread/ERROR]: #!#!     at java.util.concurrent.FutureTask.run(Unknown Source)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:843)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:424)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:767)
[20:19:03] [Server thread/ERROR]: #!#!     at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:665)
[20:19:03] [Server thread/ERROR]: #!#!     at java.lang.Thread.run(Unknown Source)
[20:19:03] [Server thread/ERROR]: #!#!
[20:19:03] [Server thread/ERROR]: #!#! Version Information:
[20:19:03] [Server thread/ERROR]: #!#!   Skript: 2.2-dev30b (custom version)
[20:19:03] [Server thread/ERROR]: #!#!   Bukkit: 1.12.1-R0.1-SNAPSHOT
[20:19:03] [Server thread/ERROR]: #!#!   Minecraft: 1.12.1
[20:19:03] [Server thread/ERROR]: #!#!   Java: 1.8.0_77 (Java HotSpot(TM) 64-Bit Server VM 25.77-b03)
[20:19:03] [Server thread/ERROR]: #!#!   OS: Windows 10 amd64 10.0
[20:19:03] [Server thread/ERROR]: #!#!
[20:19:03] [Server thread/ERROR]: #!#! Running CraftBukkit: false
[20:19:03] [Server thread/ERROR]: #!#! Running Spigot (or compatible): true
[20:19:03] [Server thread/ERROR]: #!#! Running Paper (or compatible): true
[20:19:03] [Server thread/ERROR]: #!#!
[20:19:03] [Server thread/ERROR]: #!#! Current node: null
[20:19:03] [Server thread/ERROR]: #!#! Current item: stream is set
[20:19:03] [Server thread/ERROR]: #!#! Thread: Server thread
[20:19:03] [Server thread/ERROR]: #!#!
[20:19:03] [Server thread/ERROR]: #!#! Language: english
[20:19:03] [Server thread/ERROR]: #!#! Link parse mode: DISABLED
[20:19:03] [Server thread/ERROR]: #!#!
[20:19:03] [Server thread/ERROR]: #!#! End of Error.
[20:19:03] [Server thread/ERROR]: #!#!

Is it related to my server/skript/addon versions? I'm current on 1.12.1, with version 2.2-dev30b of bensku's skript, along with skellett, skquery, skstuff, and tuske.
 
Well, instead, you could use the that are expression of MundoSK:

code_language.skript:
if items in player's inventory that are 4 of stone with lore "whatever" is set:
    #do stuff
or just use the contains condition, it may work fine on this case:
code_language.skript:
if items in player's inventory contains 4 of stone with lore "whatever":
 
Status
Not open for further replies.