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!

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

Other Custom effects and expressions with skript-mirror

Discussion in 'Tutorials' started by btk5h, Dec 30, 2017.

  1. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    151
    Likes Received:
    151
    As of skript-mirror 0.8.0, you can now create your own custom effects and expressions. These serve as a replacement for Skript functions with more features and more familiar syntax.

    By combining custom syntax with reflection, it is now possible to extend Skript in ways previously only achievable through addons. In fact, in many cases, it is better to use skript-mirror's custom syntax instead of creating an addon:
    • Custom syntax is hot-reloadable (reloadable without restarting the server), just like other Skript features
    • Custom syntax does not require a compiler
    • It is much easier to achieve high quality standards—the learning curve is much smaller!
    Let's start by creating a simple effect:
    Code (Skript):
    1. effect greet [the] world:
    2.   broadcast "Hello, world!"
    3.  
    4. command /tutorial1:
    5.   trigger:
    6.     greet world
    7.     greet the world
    Notice, we can use the same Skript features, like [brackets] and (curvy brackets|parentheses).

    We can even use expressions:
    Code (Skript):
    1. effect greet %string%:
    2.   broadcast "Hello, %expression-1%"
    And if we want, we can accept multiple expressions as input. Notice how the type parameter is strings and we use expressions-1 instead of expression-1.
    Code (Skript):
    1. effect greet %strings%:
    2.   loop expressions-1:
    3.     broadcast "Hello, %loop-expression%"
    4.  
    5. command /tutorial2 <text>:
    6.   trigger:
    7.     greet argument split by " "
    Running /tutorial2 Alice Bob prints "Hello, Alice" and "Hello, Bob".

    We can even use waits and delays:
    Code (Skript):
    1. effect greet [the] world slowly:
    2.   broadcast "Hello"
    3.   wait 5 seconds
    4.   broadcast "World"
    5.  
    6. command /tutorial3:
    7.   trigger:
    8.     greet the world slowly
    9.     broadcast "end"
    However, this example prints "Hello", "end", then "World". This is because Skript is not waiting for the effect to complete before it continues with the following code. (This is how functions behave, too.)

    In order to fix this, we must indicate that the effect will be delayed before the delay occurs. We must also add continue at the end to indicate that the effect has ended and the code can continue to execute.
    Code (Skript):
    1. effect greet [the] world slowly:
    2.   delay the effect
    3.   broadcast "Hello"
    4.   wait 5 seconds
    5.   broadcast "World"
    6.   continue
    7.  
    8. command /tutorial3:
    9.   trigger:
    10.     greet the world slowly
    11.     broadcast "end"
    This prints "Hello", "World", "end", as you might expect.

    You may notice we now have a greet [the] world effect and a greet [the] world slowly effect. We can combine the logic for these two effects into a single effect using parser marks.
    Code (Skript):
    1. effect greet [the] world [(1¦slowly)]:
    2.   if parse mark is 1:
    3.     delay the effect
    4.     broadcast "Hello"
    5.     wait 10 seconds
    6.     broadcast "World"
    7.     continue
    8.   else:
    9.     broadcast "Hello, world!"
    Notice, the latter branch of the if statement does not need a continue because it never reaches a line that delays the expression.

    Expression tutorial coming soon. For now, you can read this tutorial for a taste of expressions.
     
    • Like Like x 6
    • Useful Useful x 3
    • Winner Winner x 1
  2. FUZIK

    FUZIK Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    113
    Likes Received:
    11
    what about the events?
     
  3. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    151
    Likes Received:
    151
    Hooking into Bukkit events is already possible. I may add support for user-defined events if the syntax is simple enough.
     
  4. i

    it_twit Active Member

    Joined:
    Jan 26, 2017
    Messages:
    37
    Likes Received:
    3
    Medals:
    If possible I would prefer user-defined types since custom events are already possible with mundosk. Also thanks for adding effects and expressions, they are really useful
     
  5. btk5h

    Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    151
    Likes Received:
    151
    What is the benefit of implementing custom types?
     
  6. i

    it_twit Active Member

    Joined:
    Jan 26, 2017
    Messages:
    37
    Likes Received:
    3
    Medals:
    Honestly I don't know, but I just feel like it would work well with the current features
     
  7. Mr_Simba

    Mr_Simba King of the Pridelands
    Moderator Supporter

    Joined:
    Dec 9, 2016
    Messages:
    257
    Likes Received:
    54
    Medals:
    As for creating our own types, enums which support your standard bit mask logic could be cool. Or just bitwise operators in general.

    This looks awesome, though.
     
  8. mel_instagibson

    Joined:
    Feb 4, 2017
    Messages:
    70
    Likes Received:
    4
    I'm having troubles understanding the delay and how you access custopm effects...

    I'm trying to add a "function" in which i check for a value in the database and return either false or the value if its not set/set

    something like this:

    Code (Skript):
    1.  
    2. effect check %player%:
    3.         delay the effect
    4.         execute "SELECT * from inventory.`%unsafe uuid of {_p}%`" in {db} and store output in {_e::*}
    5.         if {_e::*} is set:
    6.                 send "%{_e::*}%" to expr-1
    7.                 return {_e::*}
    8.         else:
    9.                 return false
    10.  
    11.  
    12. command /equip:
    13.         permission: *
    14.         trigger:
    15.                 check player
    16.  
    keeps giving me "can't understand condition/effect: check" so i dont even know if the custom effect is correct....
    Can someone give me an example on how to solve this? I dont even know what im doing wrong i tried every way of accessing the custom effect that comes to my mind

    using skript-mirror 0.9 and dev33
     
    #8 mel_instagibson, Feb 26, 2018
    Last edited: Feb 26, 2018
  9. Snow-Pyon

    Moderator Resource Staff

    Joined:
    Jan 25, 2017
    Messages:
    1,224
    Likes Received:
    168
    Medals:
    It's an already known bug of dev30+, you'll have to put the custom effect in another script that is loaded before the script that is using the custom effect for it to work.
     
    • Useful Useful x 1
  10. mel_instagibson

    Joined:
    Feb 4, 2017
    Messages:
    70
    Likes Received:
    4
    Of course its the one thing i thought about trying but didnt because i thought that cant be.
    well thats pretty annoying especially if you try to create functions that call other functions, any chance this will be fixed soon?
     
  11. Snow-Pyon

    Moderator Resource Staff

    Joined:
    Jan 25, 2017
    Messages:
    1,224
    Likes Received:
    168
    Medals:
    this isn't the case of functions, only of skript-mirror custom syntaxes. I'll see if I can fix it, no promises though.
     
  12. mel_instagibson

    Joined:
    Feb 4, 2017
    Messages:
    70
    Likes Received:
    4
    Can someone help me out with this?
    im trying to make a "function" that waits for some data from luckperms but i only get <none>s
    Code (Skript):
    1.  
    2.  
    3. expression last permissioncheck %offline player%:
    4.         get:
    5.                 return {permissioncheck}
    6.         set:
    7.                 set {permissioncheck} to change value
    8.         delete:
    9.                 delete {permissioncheck}
    10.  
    11. effect permissioncheck %offline player%:
    12.         trigger:
    13.                 if expr-1.getLastPlayed() is 0:
    14.                         set permissioncheck to "Unknown"
    15.                         stop
    16.                 else:
    17.                         delay the effect
    18.                         set {_api} to LuckPerms.getApi()
    19.                         set {_uuid} to {_p}.getUniqueId()
    20.                         {_api}.getUserManager().loadUser({_uuid})
    21.                         loop 10 times:
    22.                                 wait 1 tick
    23.                                 {_api}.getUserManager().isLoaded({_uuid}) is true
    24.                                 stop loop
    25.                         set permissioncheck to "%{_u}.getPermissions()%"
    26.                         continue
    27.  
    28. command /test <offline player>:
    29.         permission: *
    30.         trigger:
    31.                 send "%last permissioncheck arg-1%"
    32.  
    i tried to work with existing posts, the docs and even discord history but i just cant find any helpful examples or some sort of more detailed documentation.
    just want to make a function that returns either a string of permission nodes or "Unknown"
    --- Double Post Merged, Dec 14, 2018, Original Post Date: Dec 11, 2018 ---
    can someone help me please?

    i just need a function which returns a string after a lookup and allows a delay

    or can i only put the full code in front of everything where i need it?
     
Loading...