Skript Integration - jojodmo/CustomItems GitHub Wiki
Using CustomItems with Skript
Make sure you have the skript plugin on your server
To use CustomItems with Skript, use the action runSkript
in your item yml file, and provide the parameter actionID(s)
. This ID will be used to run your Skript code.
Then, in your Skript file, use on CustomItems handle, and then replace the default action id "putYourActionIDHere".
You can use %target% to get the target entity of the action, if there is one, and %targetplayer% to get the target player, if there is one.
You can also use %player% to get the player, and %block% to get the block, if there is one.
Additionally, you can check if an item is a custom item using Skript. Just use %item% is a custom item with the id "myCustomItemID"
or %item% is not a custom item with the id "myCustomItemID"
. For example, you could run something only if the player's tool is a CustomItem with the id "myCustomItem"
if %itemtype% is a Custom Item with the id "item id here"
if the player's tool is a Custom Item with the id "magicStick":
You could also check if a block is a custom block!
if %block% is a Custom Item block with the id "myBlock"
if the block is a Custom Item block with the id "myBlock":
Here's an example of the item "magicStick", which will run the below Skript file when a player right-clicks a block with it!
Magic Stick Example
# in magicStick.yml
name: Magic Stick
item:
material: "minecraft:STICK"
handlers:
rightClickBlock:
actions:
-
action: runSkript
actionIDs:
- "myActionID"
Now, when a player right-clicks a block with the magicStick item, on CustomItems handle
in Skript will run. The actionID we used is "myActionID", so we can check if we have the correct action ID using if the action id is "myActionID"
:
Example Skript File for Magic Stick
on CustomItems handle:
if the action id is "myActionID":
# You can use %player%, %block%, %target%, and %targetPlayer%
broadcast "%player% just hit %target%"
# Only run if the player's tool is the custom item with the id "magicStick"
if the player's tool is a CustomItem with the id "magicStick":
broadcast "%player% is holding a magicStick!"
# Only run this if the player hit a block with the id "myBlock"
if the block is a CustomItem block with the id "myBlock":
broadcast "%player% just hit a custom myBlock with a magicStick!"
Another Example Item (Transmute Staff)
When a player right-clicks lava with this item, it turns into cobblestone and removes one experience level from the player, and when they right-click water, it turns into ice and removes one experience level from the player.
# in transmute_staff.yml
name: transmute_staff
item:
material: BLAZE_ROD
displayName: '&dTransmute Staff'
lore:
- '&7A magical item that harnesses the power of the &8Your XP&r&7.'
- '&7Item Use : Turns lava in to cobblestone for 1 level.'
- '&7Item Use 2 : Turns water in to ice for 1 level.'
canBeUsedGenerically: false
handlers:
rightClick:
actions:
-
action: runSkript
actionIDs:
- "waterlava"
-
action: playerPlaySound
sound: entity.experience_orb.pickup
Example Skript File for Transmute Staff
File in plugins\Skript\scripts
# in waterlava.sk
on CustomItems handle:
if the action id is "waterlava":
if target block is water:
if player's level is higher or equal to 1:
remove 1 from player's level
set target block to ice
if target block is lava:
if player's level is higher or equal to 1:
remove 1 from player's level
set target block to cobblestone