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 out 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 get first line with packets

Discussion in 'Skript' started by loadka95, Aug 19, 2017.

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

    loadka95 Active Member

    Joined:
    Feb 24, 2017
    Messages:
    78
    Likes Received:
    6
    I'm don't know a lot about packets, can someone help me get the first line from the sign when you click the done button? i know you have to use the Update Sign packet, but i can figure it out :/
    Thanks!

     
  2. Best Answer:
    Post #9 by ShaneBee, Aug 20, 2017
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    the string array pinfo 0 of the packet contains all the lines of the sign, you can get the first line by using the first element of expression. Also, for the next time, you can look into the PacketWrapper.

    For example, in this case, you wanted to know how to get the lines from the play_client_update_sign packet, then you'd go to the WrapperPlayClientUpdateSign class and look at the methods, one of these methods is getLines, you'd look at what it returns, on this case it is the following:
    Code (Java):
    1. handle.getStringArrays().read(0);
    and the equivalent of that in Skript would be:
    Code (Skript):
    1. string array pinfo 0 of %packet%
    Which is pretty much self explanatory, will explain it anyways:
    • string array pinfo is the equivalent of getStringArrays. Some methods might not have the same name though, like some packets that returns an item stack, it'd use the getItemModifiers method, and the Skript equivalent of that is:
    Code (Skript):
    1. "ItemModifier" pinfo %number% of %packet%
    • read(number) or write(number), read(0) in this case would be the action and index, if it's read(number) that means it's reading the value at the number index. If it's write(number) that means it's writting over the current value at the number index, so it's basically setting the value at the number index.
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Im trying, but i can't get it to work. I didn't used packets before, so i need some help :emoji_slight_smile:
    this is what i got so far:
    Code (Skript):
    1. set {_packetb} to new play_client_update_sign packet
    2. set {_firstline} to the first element out of string array pinfo 0 of {_packetb}
    3. message "%{_firstline}%"
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    When making a new packet it doesn't have any of the info -- it's simply a container for the packet. In this case, the string array isn't yet set and so it will be null. You'll have to set it yourself if you want to fake a packet, or use the packet event to intercept incoming ones
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    I tried with the on packet event, but it's getting all the lines like this "[first,second,third,fourth] and I only need the first line..
    Code (Skript):
    1. on packet:
    2.     if event-string is "PacketPlayInUpdateSign":
    3.         set {_this} to packet field "b"
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Then use
    Code (Skript):
    1. set {_split::*} to {_text} split at ","
    where {_text} is the complete sign text.
    Then, {_split::1} contains the first line.
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    This is skellett's packet syntax. Use MundoSKs
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    after I split it, the {_split::*} has nothing in it..
    --- Double Post Merged, Aug 20, 2017, Original Post Date: Aug 20, 2017 ---
    As I said, i don't know anything about packets, so even If I use MundoSk, i still can't get the first line from the sing
     
  10. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    What did you try, with MundoSK? Also, you can't split it because it isn't a text, it's an array object. What you can do with that is either convert the array to a Skript list with Skript-Mirror's spread expression or convert it to a text (surrounding it with quotes and percent signs) then spliting it by a comma and removing the squared brackets from the first and the last object.

    Anyways, as you seem to try it at least, here is the MundoSK way, which is much more easier than Skellett's one:

    Code (Skript):
    1. on packet event play_client_update_sign:
    2.   set {_lines::*} to string array pinfo 0 of event-packet
    3.   #now {_lines::1} is the first line of the sign.
     
    loadka95 likes this.
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    Thank to everyone who helped! :emoji_slight_smile:
     
  12. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    is there a reason you're not using the existing on sign change event?

    Code (Skript):
    1. on sign change:
    2.     broadcast "%line 1%"
     
  13. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    I was gonna ask the same to be honest, as this event is triggered when a player press the "Done" button and the update sign packet is called while the player is editing the sign.
     
  14. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,184
    Likes Received:
    231
    I created the sign using (open sign editor) packet, and the event is not working with it
     
Thread Status:
Not open for further replies.

Share This Page

Loading...