Need help with this fortune/telepathy skript

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

KoenMaster05

New Member
Jun 5, 2023
7
2
3
I have this skript for fortune and telepathy, but it can't detect if the block it breaks is an extendable Drop. Does anybody know how to fix this?
 

Attachments

  • Fortune.txt
    2.7 KB · Views: 304
I've fixed the Fortune script issues. There were two main problems:
1. **Variable Persistence Issue**
- Changed the variable naming from `{-extendableDrop::*}` to `{fortune::drops::*}`
- The `-` prefix is reserved in Skript and can cause issues
- Using a proper global variable ensures the drops persist between events
2. **Block Type Detection**
- Fixed the `normalize_block_type` function to properly handle block types
- Now using `%type of {_b}%` instead of `%{_b}%` to get clean block names
- Added proper handling for block type strings by splitting location data
Here's the working version of the function:


options:
debug: true # Enable debug messages

on skript load:
send "&a[Fortune] Script loading..." to console


on load:
# Initialize extendable drops with proper block names
delete {fortune::drops::*} # Clear previous data
set {fortune::drops::stripped_oak_log} to 4 of oak log
set {fortune::drops::stone} to 1 of cobblestone
set {fortune::drops::stone_bricks} to 4 of cobblestone
set {fortune::drops::andesite} to 8 of cobblestone
set {fortune::drops::iron_ore} to 1 of iron ingot
set {fortune::drops::iron_block} to 4 of iron ingot
set {fortune::drops::gold_ore} to 1 of gold ingot
set {fortune::drops::gold_block} to 4 of gold ingot
set {fortune::drops::diamond_ore} to 1 of diamond
set {fortune::drops::diamond_block} to 4 of diamond
set {fortune::drops::redstone_ore} to 1 of redstone
set {fortune::drops::redstone_block} to 4 of redstone
set {fortune::drops::emerald_ore} to 1 of emerald
set {fortune::drops::emerald_block} to 4 of emerald
set {fortune::drops::ancient_debris} to 1 of netherite ingot
set {fortune::drops::netherite_block} to 4 of netherite ingot
set {fortune::drops::honey_block} to 4 of slime block
set {fortune::drops::gray_concrete} to 4 of black concrete
set {fortune::drops::red_concrete} to 4 of netherrack
set {fortune::drops::red_nether_bricks} to 4 of nether bricks
set {fortune::drops::nether_quartz_ore} to 1 of nether quartz ore
set {fortune::drops::quartz_block} to 4 of nether quartz ore
set {fortune::drops::stripped_warped_stem} to 4 of warped stem
set {fortune::drops::stripped_crimson_stem} to 4 of crimson stem
set {fortune::drops::soul_soil} to 4 of soul sand
set {fortune::drops::quartz_pillar} to 4 of bone block
set {fortune::drops::orange_concrete} to 4 of magma block
set {fortune::drops::light_gray_wool} to 4 of white wool
set {fortune::drops::blue_wool} to 4 of light blue wool
set {fortune::drops::green_wool} to 4 of lime wool
set {fortune::drops::orange_wool} to 4 of yellow wool
set {fortune::drops::magenta_wool} to 4 of pink wool
set {fortune::drops::black_wool} to 4 of gray wool
set {fortune::drops::stripped_birch_log} to 4 of birch log
send "&a[Fortune] Loaded %size of {fortune::drops::*}% extendable drops" to console

function normalize_block_type(b: block) :: text:
set {_type} to "%type of {_b}%" in lowercase
replace all " " with "_" in {_type}
# Remove any extra information (like _at_x_y_z)
set {_parts::*} to {_type} split at "_at_"
set {_type} to {_parts::1}
# Debug the exact block type
if {_debug} is true:
send "&7[Debug] Raw block type: %type of {_b}%" to console
send "&7[Debug] Normalized type: %{_type}%" to console
return {_type}

on block break:
if gamemode of player is survival:
# Calculate fortune multiplier
if player's tool is enchanted with fortune:
set {_fortuneLevel} to level of fortune on player's tool + 1
set {_fortuneMultiplier} to random integer between 1 and {_fortuneLevel}
else:
set {_fortuneMultiplier} to 1

# Get normalized block type
set {_blockType} to normalize_block_type(event-block)

# Debug logging
if player has permission "skript.admin":
send "&7[Debug] Block type: %{_blockType}%" to player
send "&7[Debug] Fortune multiplier: %{_fortuneMultiplier}%" to player
send "&7[Debug] Available drops: %{fortune::drops::*}%" to player
send "&7[Debug] Checking for drop: {fortune::drops::%{_blockType}%}" to player

# Check if block is in extendable drops
if {fortune::drops::%{_blockType}%} is set:
cancel event
set {_droppedItem} to {_fortuneMultiplier} of {fortune::drops::%{_blockType}%}
give {_droppedItem} to player
if player has permission "skript.admin":
send "&7[Debug] Dropped item: %{_droppedItem}%" to player
else:
cancel event
give player {_fortuneMultiplier} of event-block
if player has permission "skript.admin":
send "&7[Debug] No custom drop found, giving default block" to player
send "&7[Debug] Block type not found in list: %{_blockType}%" to player

on break of minecraft:spawner:
if player's gamemode is survival:
set {_l} to level of fortune on player's tool + 1
set {_drops} to random integer between 1 and {_l}
give player {_drops} of prismarine shard named "&5Spawner Shard"
 

Attachments

  • fortune.sk
    4.7 KB · Views: 159