#Help with making this a function

1 messages · Page 1 of 1 (latest)

green elm
#

I know I need to make this section of code a function because I keep repeating it, but I can't think of an effective way to make it one.

on inventory click:
    name of event-inventory is "&cᴋɪʟʟs"
    cancel event
    event-inventory is not player's inventory
    {playerstats::achievements::%player's uuid%::kills::rowOne} isn't set: #from here
        event-slot = 10:
            {playerstats::mobKills::%player's uuid%} >= 100:
                achievementReward(player, 500, 2)
                add 1 to {playerstats::achievements::%player's uuid%::kills::rowOne} #to here is repeated
#

I can't use event-slot in a function though

soft patio
#

I'd recommend using Skript-GUI

#

and what you can do is:

green elm
#

yeah i have a feeling i need to do that

soft patio
#
function openGUI(p: player):
  create a gui with virtual chest inventory with 3 rows named "&ckills":
    make gui slot 10 with book named "&cAchievement":
      {playerstats::mobKills::%player's uuid%} >= 100:
        achievementReward(player, 500, 2)
        add 1 to {playerstats::achievements::%player's uuid%::kills::rowOne}
        openGUI({_p})
    open last gui to {_p}
#

you can even do another function for the playerstats and etc

#

if u want

green elm
#

my code right now is repeating this part:

{playerstats::achievements::%player's uuid%::kills::rowOne} isn't set:
        event-slot = 10:
            {playerstats::mobKills::%player's uuid%} >= 100:
                achievementReward(player, 500, 2)
                add 1 to {playerstats::achievements::%player's uuid%::kills::rowOne}
    {playerstats::achievements::%player's uuid%::kills::rowOne} = 1:
        event-slot = 11:
            {playerstats::mobKills::%player's uuid%} >= 500:
                achievementReward(player, 2000, 4)
                add 1 to {playerstats::achievements::%player's uuid%::kills::rowOne}
    {playerstats::achievements::%player's uuid%::kills::rowOne} = 2:
        event-slot = 12:
            {playerstats::mobKills::%player's uuid%} >= 1000:
                achievementReward(player, 4500, 6)
                add 1 to {playerstats::achievements::%player's uuid%::kills::rowOne}
soft patio
#

uff, yeah I see

green elm
#

i just would rather not to clean up the code since i want to add more achivements eventually

#

but the event-slot is screwing me up

soft patio
#

Do you want infinite achievements or limited?

green elm
#

i have it limited to 7 right now

soft patio
#

aha

green elm
#

cuz this code WORKS

#

but tis not gonna be good long term

soft patio
#

its hard coded

#

yes

#

rather than soft coded

green elm
#

yeah its gonna suck in the future

soft patio
#

Indeed

green elm
#

im not good at soft coding things

#

lmao

soft patio
#

so what you wanna do is probably start using functions more

soft patio
green elm
#

i do have the numbers themselves as a function

#

or an equation rather

#

i should prob make the amount given derived from the lore of the item or sm

soft patio
#

what exactly are you trying to do

green elm
#

its like get x amount of kills and u get gems and coins, and u cant re-claim it again later

#

i tgoes up like 100, 500, 1000, 2500, 5000, 10000, 25000 for mob kills and i have the rewards like this

if loop-value < 7:
    setSlotLore(5, 9+loop-value, "&e +%500*loop-value^2%⛀ Coins", {_p})
else:
    setSlotLore(5, 9+loop-value, "&e +50000⛀ Coins", {_p}
    setSlotLore(7, 9+loop-value, "&6 +1 Bloodthirsty Trophy", {_p})
soft patio
#

that is not soft coding lol

green elm
#

yeah i didnt say it was i just said i have some numbers as functions

soft patio
#

well, my advice would be probably removing all code that includes vanilla-gui or whatever you used

#

and doing skript-gui instead

#

can u send the whole skript and ill do it for you

#

it will make it 100 times easier for you to code

#

and i can save you alot of lines

green elm
#

thats super nice tysm lemme grab it all rq

#

uiSlots is defined in a different file it just adds that glass pane ring around the border

soft patio
#

did you do this all yourself?

green elm
#

yeah i did

soft patio
#
command /achievements [<string>]:
    aliases: a
    permission: op
    trigger:
        if arg-1 = "reset":
            if player is op:
                delete {playerstats::achievements::%player's uuid%::*}
        set {_c} to a chest inventory with 3 rows named "&8Achievements"
        uiSlots(3, {_c})
        create a gui with virtual chest inventory with 3 rows named "&7Achievements (GUI)":
            make gui slot 11 with {items::achievements} named "&cᴋɪʟʟs":
                #do stuff
            make gui slot 13 with unflower named "&eᴡᴇᴀʟᴛʜ":
                #do stuff
        
        if arg-1 = "kills":
            create a gui with virtual chest inventory with 3 rows named "&cᴋɪʟʟs":
                #uiSlots(6, {_c})  idk what this does
                make gui slot 10 with redstone named "&cKills 1" with lore "%nl%&7Kill 100 mobs":
                    #do stuff
                make gui slot 11 with redstone named "&cKills 2" with lore "%nl%&7Kill 500 mobs":
                    #do stuff 
                make gui slot 12 with redstone named "&cKills 3" with lore "%nl%&7Kill 1000 mobs":
                    #do stuff
                make gui slot 13 with redstone named "&cKills 4" with lore "%nl%&7Kill 2500 mobs":
                    #do stuff
                make gui slot 14 with redstone named "&cKills 5" with lore "%nl%&7Kill 5000 mobs":
                    #do stuff
                make gui slot 15 with redstone named "&cKills 5" with lore "%nl%&7Kill 5000 mobs":
                    #do stuff
                make gui slot 16 with redstone named "&cKills 6" with lore "%nl%&7Kill 10000 mobs":
                    #do stuff
                make gui slot 17 with redstone named "&cKills 7" with lore "%nl%&7Kill 25000 mobs":
                    #do stuff
#

I made some of it

#

at the comments, just fill out whatever you want it to do. If its something repeating over and over, make a function for it.

green elm
#

i see i see ty much 🙏

green elm
#

im getting errors on the "make gui slot" lines

#

but it seems right in the documentation

soft patio
#

did you install skript-gui?

green elm
#

yeah i did

#

and now its saying i cant make gui shapes because it isnt a "location"

#

i literally copied and pasted the example gui

#
command /achievements2 [<string>]:
    aliases: a
    permission: op
    trigger:
        if arg-1 = "reset":
            if player is op:
                delete {playerstats::achievements::%player's uuid%::*}
       
        create a gui with virtual chest inventory with 3 rows named "My EPIC GUI!" and shape "xxxxxxxxx", "x-------x", and "xxxxxxxxx":
        make gui slot "-" with dirt named "! BORDER !":
            send "Say goodbye to your GUI border %player%!" to player
            remove gui slot "x"
        open last gui for player
soft patio
#

uhh

#

replace "-" with

#

an integer

green elm
#

mk

soft patio
#

oh wait

#

dont use shapes if you do not understand them

green elm
#

i do understand them

#

x is the border and - is blank

#

i didnt realize - was a blank

#

i thought i could just make it a value too lmao

#

thats mb

soft patio
#

lmao

#

you can really do any letters or numbers

green elm
#

ya makes sense now

true comet
#

I'm not sure if this is what you wanted. But for me, all it was is some indentation errors.

    aliases: a
    permission: op
    trigger:
        if arg-1 = "reset":
            if player is op:
                delete {playerstats::achievements::%player's uuid%::*}
       
        create a gui with virtual chest inventory with 3 rows named "My EPIC GUI!" and shape "xxxxxxxxx", "x-------x", and "xxxxxxxxx":
            make gui slot "-" with dirt named "! BORDER !":
                send "Say goodbye to your GUI border %player%!" to player
                remove gui slot "x"
            open last gui for player```
#

Here's a list of my test servers skript-addons and versions.

green elm
#

yeah everything worked out fine, thanks! 😁