Solved Nesting variables within option nams

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

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

YourMCAdmin

Member
Jan 31, 2017
18
0
0
37
Skript Version:2.2-dev23
Skript Author:Bensku
Minecraft Version:1.11.2

Bare with me here when I try to explain what I mean and what I'm doing. I want to know if it's possible (or if anyone can think of a work around) to use a variable later in the code to call an option. As you will see I'm using the same options over and over depending on mob type and weapon used. If I could just plug in the victim mob's type in the name of an option, it would cut down my code by a lot! Something like {@%{_victim%}Iron} But obviously, that's messy and Skript doesn't like it haha.

In the options, I'm setting percentages for something to happen when a specific mob is killed. Iron and Diamond are just sword types to weight chances.

code_language.skript:
options:
    playerIron: 10%
    playerDiamond: 25%
    creeperIron: .1%
    creeperDiamond: .25%
    skeletonIron: .1%
    skeletonDiamond: .25%
    zombieIron: .1%
    zombieDiamond: .25%
    ...etc the rest of the mobs eventually

Then when an entity is killed
code_language.skript:
on death:
    set {_victim} to victim
    if attacker is holding a diamond sword:
        chance of {@%{_victim}%Diamond}
        do stuff.
    if attacker is holding a iron sword:
        chance of {@%{_victim}%Iron}  
        do stuff

I want all mob deaths to be easily configurable and keep my code as small as possible. If I have to manually type each mob type death, I can, but using a variable inside an option would cut down a lot of work! Does anyone know of any work arounds or maybe offer me some advice?

Thanks so much! :emoji_slight_smile:
 
Last edited:
does chance of not need to have a %? like chance of 10% ect. make sure the variable is actually a number
If the "%" is defined in the options, "chance of {@option}" does not need the %. It definitely works that way. But that's not what I'm trying to figure out. I'm trying to figure out if I can use a variable to refer to an option name.
 
If the "%" is defined in the options, "chance of {@option}" does not need the %. It definitely works that way. But that's not what I'm trying to figure out. I'm trying to figure out if I can use a variable to refer to an option name.
Never tried it so couldn't tell you, do you or did you own a survival server? i think i know you hehe
 
Yes I do. Almost 6 years running! Does "LegitLand" ring a bell? Haha
Ah it does indeed haha, i used to be a very active member on it when i was alot younger, probs about 3-4 years ago now, i'm pretty sure i got banned for knocking a picture frame off a shop as it was griefing haha. Great to see that your server is still running and active though.
 
You can't do it like that such as you can't use variable in option names, I would do something like:
code_language.skript:
on skript start: #This event is called when Skript is loaded and only once.
    set {chances::player::iron} to 10
    set {chances::player::diamond} to 25
    set {chances::creeper::iron} to .1
    set {chances::creeper::diamond} to .25
    #and so on

on death of player: #I suppose you want this only for players, you could remove that part.
    if attacker's tool is a diamond sword:
        chance of {chances::%victim%::diamond}%:
            #do stuff
 
Status
Not open for further replies.