item2chat skript not working

  • 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.
Wrong syntax.
Code:
<tooltip:Your tooltip>

On Skript 2.3.6 and lower this will work. On Skript 2.3.7+ you will need to cancel the chat event and send a message to all players using
Code:
send formatted %string% to %players%

One last thing is, for lore of items in a tooltip, you want to format it properly. In 2.3.6 and lower, you can set a var to the lore and replace all || with %nl% to format it properly. On 2.3.7+ lore is now a list so you will need to figure out a way to format the lore properly as a string (hint, uses %nl% again)

You can also do this in skript-mirror which is probably more natural. Credit to ShaneBee for posting this as a snippet in the Skript Chat discord (https://discordapp.com/channels/138464183946575874/388811398140002307/664992644224516124).

code_language.skript:
option ver:
    get:
        return console.getServer().getClass().getPackage().getName().split("\.")[3]
import:
    net.minecraft.server.{@ver}.ChatComponentText
    org.bukkit.craftbukkit.{@ver}.inventory.CraftItemStack
    java.lang.String as ST #this is because importing String doesnt work

# THE FUN PART
on chat:
    if message contains "[item]":
        if event is not cancelled:
            cancel event
            if event.getFormat() contains "%%":
                set {_m} to ST.format(event.getFormat(), player.getDisplayName(), message)
            else:
                set {_m} to event.getFormat()
            if first character of event.getMessage().toString() = "&":
                set {_c} to first 2 characters of event.getMessage().toString()
            else:
                set {_c} to ""
            set {_m::*} to {_m} split at "[item]"
            set {_a} to new ChatComponentText({_m::1})
            set {_f} to {_a}.getChatModifier()
            {_a}.addSibling(CraftItemStack.asNMSCopy(random item of player's tool).B())
            {_a}.a(formatted "%{_c}%%{_m::2}%")
            loop all players:
                (loop-player).getHandle().sendMessage({_a})
 
Last edited:
Status
Not open for further replies.