Discord Thread What is wrong with my current code?

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

This thread came from the skUnity Discord. You can't reply to it here but if you join the skUnity Discord, you'll be able to post a reply there. The thread link is part of the thread's message.
Status
Not open for further replies.

skUnity Discord

Site Manager
Aug 5, 2023
12,755
0
0
The skUnity Discord
discord.gg
code_language.skript:
options:
    P : &6Stats &8| &7
    A : &8➟&7
    L: &8&m---------------------------




function loadStats(s: player, e: player):
    set metadata tag "stats" of {_e} to chest inventory with 3 rows named "&8%{_s}%'s Stats"
    set slot (all integers between 0 and 27) of metadata tag "stats" of {_e} to black stained glass pane named "&8&ka"
    set {_k} to kill entity stat using {_s} for {_s}
    set {_d} to deaths stat using {_s} for {_s}
    set {_m} to format({_s}'s balance)
    set {_playtime} to time format from time played of {_s}
    set {_mb} to mob kills stat using {_s} for {_s}
    set {_blocksplaced} to {Stats::BlockPlace::%uuid of {_s}%} ? 0
    set {_blocksbroken} to {Stats::BlockBreak::%uuid of {_s}%} ? 0
    set {_killsformatted} to killsformat({_k})
    set {_bbformatted} to bbformat({_blocksbroken})
    set slot 10 of metadata tag "stats" of {_e} to diamond sword with all flags hidden named "&b&lPLAYER KILLS" with lore "&fPlayer kills: &a%{_killsformatted}%"
    set slot 11 of metadata tag "stats" of {_e} to skeleton skull with all flags hidden named "&7&lDEATHS" with lore "&fCurrent deaths: &a%{_d}%"
    set slot 12 of metadata tag "stats" of {_e} to gold ingot with all flags hidden named "&e&lMONEY" with lore "&fMoney: &a$%{_m}%"
    set slot 13 of metadata tag "stats" of {_e} to clock with all flags hidden named "&e&lPLAYTIME" with lore "&fCurrent playtime: &a%{_playtime}%"
    set slot 14 of metadata tag "stats" of {_e} to zombie head with all flags hidden named "&2&lMOB KILLS" with lore "&fMob kills: &a%{_mb}%"
    set slot 15 of metadata tag "stats" of {_e} to dirt block with all flags hidden named "<##B5825A>&lBLOCKS PLACED" with lore "&fBlocks placed: &a%{_blocksplaced}%"
    set slot 16 of metadata tag "stats" of {_e} to diamond pickaxe with all flags hidden named "&b&lBLOCKS BROKEN" with lore "&fBlocks broken: &a%{_bbformatted}%"
    open metadata tag "stats" of {_e} to {_e}

command /stats [<offlineplayer>]:
    cooldown: 3 seconds#
    cooldown message: {@P} &7Please wait &6%remaining time% &7until using this command again!
    aliases: /stat
    trigger:
        if arg-1 is not set:
            loadStats(sender, sender)
        else if arg-1 is set:
            loadStats(arg-1, sender)

on inventory click:
    if event-inventory = (metadata tag "stats" of player):
        cancel event

on block place:
    add 1 to {Stats::BlockPlace::%uuid of player%}

on block break:
    add 1 to {Stats::BlockBreak::%uuid of player%}
    
function killsformat(s: string) :: number:
    set {_s} to {_s} in lower case
    loop ("k|m|b|t|qa|qi|sx|sp|oc" split at "|"):
        add 1 to {_i} if {_s} partially matches "(\d|\.)(k|m|b|t|qa|qi|sx|sp|oc)"
        set {_z::*} to split {_s} at loop-value
        replace all "," in {_z::1} with ""
        {_z::1} does not partially match "[^.0-9]":
            return ({_z::1} parsed as number) * (10 ^ ({_i} * 3))
    return 0
    
function bbformat(bbs: string) :: number:
    set {_bbs} to {_bbs} in lower case
    loop ("k|m|b|t|qa|qi|sx|sp|oc" split at "|"):
        add 1 to {_bbi} if {_bbs} partially matches "(\d|\.)(k|m|b|t|qa|qi|sx|sp|oc)"
        set {_bbz::*} to split {_bbs} at loop-value
        replace all "," in {_bbz::1} with ""
        {_bbz::1} does not partially match "[^.0-9]":
            return ({_bbz::1} parsed as number) * (10 ^ ({_bbi} * 3))
    return 0

Posted by: inqy. from the skUnity Discord. View the thread on skUnity Discord here
 
code_language.skript:
options:
    P : &6Stats &8| &7
    A : &8➟&7
    L: &8&m---------------------------




function loadStats(s: player, e: player):
    set metadata tag "stats" of {_e} to chest inventory with 3 rows named "&8%{_s}%'s Stats"
    set slot (all integers between 0 and 27) of metadata tag "stats" of {_e} to black stained glass pane named "&8&ka"
    set {_k} to kill entity stat using {_s} for {_s}
    set {_d} to deaths stat using {_s} for {_s}
    set {_m} to format({_s}'s balance)
    set {_playtime} to time format from time played of {_s}
    set {_mb} to mob kills stat using {_s} for {_s}
    set {_blocksplaced} to {Stats::BlockPlace::%uuid of {_s}%} ? 0
    set {_blocksbroken} to {Stats::BlockBreak::%uuid of {_s}%} ? 0
    set {_killsformatted} to stats({_k})
    set {_bbformatted} to stats({_blocksbroken})
    set slot 10 of metadata tag "stats" of {_e} to diamond sword with all flags hidden named "&b&lPLAYER KILLS" with lore "&fPlayer kills: &a%{_killsformatted}%"
    set slot 11 of metadata tag "stats" of {_e} to skeleton skull with all flags hidden named "&7&lDEATHS" with lore "&fCurrent deaths: &a%{_d}%"
    set slot 12 of metadata tag "stats" of {_e} to gold ingot with all flags hidden named "&e&lMONEY" with lore "&fMoney: &a$%{_m}%"
    set slot 13 of metadata tag "stats" of {_e} to clock with all flags hidden named "&e&lPLAYTIME" with lore "&fCurrent playtime: &a%{_playtime}%"
    set slot 14 of metadata tag "stats" of {_e} to zombie head with all flags hidden named "&2&lMOB KILLS" with lore "&fMob kills: &a%{_mb}%"
    set slot 15 of metadata tag "stats" of {_e} to dirt block with all flags hidden named "<##B5825A>&lBLOCKS PLACED" with lore "&fBlocks placed: &a%{_blocksplaced}%"
    set slot 16 of metadata tag "stats" of {_e} to diamond pickaxe with all flags hidden named "&b&lBLOCKS BROKEN" with lore "&fBlocks broken: &a%{_bbformatted}%"
    open metadata tag "stats" of {_e} to {_e}

command /stats [<offlineplayer>]:
    cooldown: 3 seconds#
    cooldown message: {@P} &7Please wait &6%remaining time% &7until using this command again!
    aliases: /stat
    trigger:
        if arg-1 is not set:
            loadStats(sender, sender)
        else if arg-1 is set:
            loadStats(arg-1, sender)

on inventory click:
    if event-inventory = (metadata tag "stats" of player):
        cancel event

on block place:
    add 1 to {Stats::BlockPlace::%uuid of player%}

on block break:
    add 1 to {Stats::BlockBreak::%uuid of player%}
    
function stats(s: string) :: number:
    set {_s} to {_s} in lower case
    loop ("k|m|b|t|qa|qi|sx|sp|oc" split at "|"):
        add 1 to {_i} if {_s} partially matches "(\d|\.)(k|m|b|t|qa|qi|sx|sp|oc)"
        set {_z::*} to split {_s} at loop-value
        replace all "," in {_z::1} with ""
        {_z::1} does not partially match "[^.0-9]":
            return ({_z::1} parsed as number) * (10 ^ ({_i} * 3))
    return 0

changed to 1
no errors
but it just shows up as 0 blocks broken
its this i think
set {_killsformatted} to stats({_k})
I didnt know what to put in the brackets so I put {_k} because I thought then its getting it from the kills
<@415356187161395201>

Posted by: inqy. from the skUnity Discord.
 
?
I dont see you helping
{_k} is a number (the number of kills). Your format function takes a string as an input and outputs a number so it is not necessary
Ye, idk why you are formatting
All of your original variables are already numbers
So putting them in a function that goes from string to number is pointless and probably breaks it

Posted by: the.phill from the skUnity Discord.
 
your format is the wrong way round
the function turns 1m into 1000000 but you're asking it to turn 1000000 into 1m

Posted by: bluelhf from the skUnity Discord.
 
Status
Not open for further replies.