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.

Simba's Snippets ♥

Discussion in 'Snippets' started by Mr_Simba, May 22, 2017.

  1. Mr_Simba

    Mr_Simba King of the Pridelands
    Supporter

    Joined:
    Dec 9, 2016
    Messages:
    256
    Likes Received:
    56
    Medals:
    Hi

    I wouldn't expect much here (mostly because I'll forget to update it), but I have a few useful snippets on my server that I use for tons of stuff and I figured you guys might find some use with these, especially cause I haven't contributed a ton content-wise since the new forums have been launched.


    Name History Command
    Requires: skUtilities
    Description: A simple command to check the name change history of the given player. Works for both offline and online people, should work regardless of server version and such. Sorry if there's a better way to do this using skUtilities' JSON stuff, but it was my first time utilizing its URL functionality at all and I'm more comfortable parsing out stuff from strings (and it works the same and just as well regardless).
    Code (Skript):
    1. command /whowas <offline player>:
    2.     aliases: namehistory
    3.     trigger:
    4.         set {_uuid} to "%offline player-argument's UUID%"
    5.         replace all "-" in {_uuid} with ""
    6.         set {_results::*} to contents from url "https://api.mojang.com/user/profiles/%{_uuid}%/names"
    7.         replace all """" in {_results::1} with ""
    8.         set {_results::*} to {_results::1} split at "},{"
    9.        
    10.         send "" to the command sender
    11.         send "&6&l%offline player-argument%'s Name History:" to the command sender
    12.         loop {_results::*}:
    13.             # Ensure this value even contains the 'name' tag, otherwise it's just junk left over from the split
    14.             "%loop-value%" contains "name"
    15.            
    16.             # If there's no 'changedToAt' in the looped value, it's the original name, so we don't need to parse out the time change
    17.             if "%loop-value%" doesn't contain "changedToAt":
    18.                 set {_val} to loop-value
    19.                 replace all "[{name:" and "}]" in {_val} with ""
    20.                 send "&8[&7%loop-index%&8] &6%{_val}% &c(Original)" to the command sender
    21.            
    22.             # Otherwise they changed FROM another name TO this one at some point, so we have to parse out the time
    23.             else:
    24.                 set {_parsedResult::*} to loop-value split at ",changedToAt:"
    25.                 replace all "name:" in {_parsedResult::1} with ""
    26.                 replace all "}]" in {_parsedResult::2} with ""
    27.                
    28.                 set {_changeTime} to convert unix ("%{_parsedResult::2}%" parsed as number) to date
    29.                 send "&8[&7%loop-index%&8] &6%{_parsedResult::1}% &c(%{_changeTime}%)" to the command sender
    30.        
    31.             delete {_changeTime}
    32.             delete {_parsedResult::*}
    33.    
    34.         send "" to the command sender


    makeLook Function (force entity to look somewhere)
    Requires: SkStuff
    Description: Makes the given entity look at the given location (which of course can be another entity or a block or whatever you want). Works as you'd expect. And before you ask, yes, I tried removing the SkStuff dependency by just generating a location with the new yaw and pitch and teleporting the entity to it, but it doesn't work (don't ask me why). Also, if it "doesn't work sometimes", it's more likely that the entity just happened to decide to look somewhere else randomly right as/after the function ran, which is uncontrollable unless you use SkStuff to remove the 'look around randomly' pathfinder goal.
    Code (Skript):
    1. function makeLook(e: living entity, loc: location):
    2.     set {_xD} to {_loc}'s x location - {_e}'s x location
    3.     set {_yD} to {_loc}'s y location - {_e}'s y location
    4.     set {_zD} to {_loc}'s z location - {_e}'s z location
    5.     set {_yaw} to atan2({_xD}, {_zD}) - 90
    6.    
    7.     set {_adj2} to ({_xD}*{_xD}) + ({_zD}*{_zD})
    8.     set {_parallel} to sqrt({_adj2})
    9.     set {_pitch} to atan2({_yD}, {_parallel}) - 90
    10.    
    11.     add "{Rotation:[%{_yaw}%f, %{_pitch}%f]}" to NBT of {_e}


    setCooldown Function (sets a visual cooldown on an item for a player)

    Requires: MundoSK (you NEED the latest beta from GitHub for it to work)
    Description: Sends a visual cooldown to the given player for a certain item type. This is displayed as an overlay that covers up all instances of the item type in the player's inventory, which slides downwards over the duration. Note that this does NOT actually do anything on its own or stop the client from using items -- it's just a visual thing that's useful for properly displaying item cooldowns to players. Nice for activated abilities.
    Code (Skript):
    1. function setCooldown(p: player, itemType: item, durationInTicks: integer):
    2.     set {_packet} to new play_server_set_cooldown packet
    3.     set "item" pinfo 0 of {_packet} to {_itemType}
    4.     set int pnum 0 of {_packet} to {_durationInTicks}
    5.     send packet {_packet} to {_p}



    Will add more as I decide they're appropriate or remember to.
     
    EWS and Snow-Pyon like this.
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    The second snippet is already present in QuarSK btw
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Yeah, but I don't have QuarSK!
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Uh, you beat me, I was going to add this to my snippets someday but been way busy nowadays :emoji_sob:
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Did you make that function just not to have to install my addon ? Otherwise, were you looking for the download ?
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    It's not like I'm going out of my way to not install it, but I'm not gonna install an entire addon for 1 effect when it can be recreated in a handful of lines w/vanilla Skript. Also I needed this effect + wrote it many months ago so I don't know if I was even aware that your addon had it at the time.
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    I don't think my addon was released at the time
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    I don't think so either, I'm not 100% sure. But yeah it wasn't written particularly recently (I don't know exactly when I did it but it's been at least a couple of months).
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    Code (Skript):
    1.     function setCooldown(p: player, itemType: item, durationInTicks: integer):
    2.         set {_packet} to new play_server_set_cooldown packet
    3.         set "item" pinfo 0 of {_packet} to {_itemType}
    4.         set int pnum 0 of {_packet} to {_durationInTicks}
    5.         send packet {_packet} to {_p}
    I'm new to functions, can you tive an example on how to implement functions?
     
  10. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    There's a nice tutorial on them in the tutorials section here
     
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
  12. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,183
    Likes Received:
    232
    No, you'll want a beta build from GitHub, I'm using this one.
     
    aescraft likes this.

Share This Page

Loading...