1. 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!

  2. LOOKING FOR A VERSION OF SKRIPT??:

    You can always check our our Wiki for downloads and any other information about Skript!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Nesting variables within option nams

Discussion in 'Skript' started by YourMCAdmin, Mar 21, 2017.

Thread Status:
Not open for further replies.
  1. YourMCAdmin

    YourMCAdmin Member

    Joined:
    Jan 31, 2017
    Messages:
    18
    Likes Received:
    0
    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 (Skript):
    1.  
    2. options:
    3.     playerIron: 10%
    4.     playerDiamond: 25%
    5.     creeperIron: .1%
    6.     creeperDiamond: .25%
    7.     skeletonIron: .1%
    8.     skeletonDiamond: .25%
    9.     zombieIron: .1%
    10.     zombieDiamond: .25%
    11.     ...etc the rest of the mobs eventually
    12.  
    Then when an entity is killed
    Code (Skript):
    1.  
    2. on death:
    3.     set {_victim} to victim
    4.     if attacker is holding a diamond sword:
    5.         chance of {@%{_victim}%Diamond}
    6.         do stuff.
    7.     if attacker is holding a iron sword:
    8.         chance of {@%{_victim}%Iron}  
    9.         do stuff
    10.  
    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:

     
    #1 YourMCAdmin, Mar 21, 2017
    Last edited: Mar 21, 2017
  2. Best Answer:
    Post #7 by ShaneBee, Mar 21, 2017
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    158
    does chance of not need to have a %? like chance of 10% ect. make sure the variable is actually a number
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    158
    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.
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    158
    Never tried it so couldn't tell you, do you or did you own a survival server? i think i know you hehe
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    158
    Yes I do. Almost 6 years running! Does "LegitLand" ring a bell? Haha
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    158
    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.
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,123
    Likes Received:
    158
    You can't do it like that such as you can't use variable in option names, I would do something like:
    Code (Skript):
    1.  
    2. on skript start: #This event is called when Skript is loaded and only once.
    3.     set {chances::player::iron} to 10
    4.     set {chances::player::diamond} to 25
    5.     set {chances::creeper::iron} to .1
    6.     set {chances::creeper::diamond} to .25
    7.     #and so on
    8.  
    9. on death of player: #I suppose you want this only for players, you could remove that part.
    10.     if attacker's tool is a diamond sword:
    11.         chance of {chances::%victim%::diamond}%:
    12.             #do stuff
    13.  
     
Thread Status:
Not open for further replies.
Loading...