Solved get first line with packets

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

loadka95

Active Member
Feb 24, 2017
78
6
8
26
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!
 
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:
Java:
handle.getStringArrays().read(0);
and the equivalent of that in Skript would be:
code_language.skript:
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_language.skript:
"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.
 
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_language.skript:
set {_packetb} to new play_client_update_sign packet
set {_firstline} to the first element out of string array pinfo 0 of {_packetb}
message "%{_firstline}%"
 
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_language.skript:
set {_packetb} to new play_client_update_sign packet
set {_firstline} to the first element out of string array pinfo 0 of {_packetb}
message "%{_firstline}%"
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
 
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
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_language.skript:
on packet:
    if event-string is "PacketPlayInUpdateSign":
        set {_this} to packet field "b"
 
it's getting all the lines like this "[first,second,third,fourth] and I only need the first line
Then use
code_language.skript:
set {_split::*} to {_text} split at ","
where {_text} is the complete sign text.
Then, {_split::1} contains the first line.
 
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_language.skript:
on packet:
    if event-string is "PacketPlayInUpdateSign":
        set {_this} to packet field "b"
This is skellett's packet syntax. Use MundoSKs
 
Then use
code_language.skript:
set {_split::*} to {_text} split at ","
where {_text} is the complete sign text.
Then, {_split::1} contains the first line.
after I split it, the {_split::*} has nothing in it..
[doublepost=1503249758,1503249627][/doublepost]
This is skellett's packet syntax. Use MundoSKs
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
 
after I split it, the {_split::*} has nothing in it..
[doublepost=1503249758,1503249627][/doublepost]
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
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_language.skript:
on packet event play_client_update_sign:
  set {_lines::*} to string array pinfo 0 of event-packet
  #now {_lines::1} is the first line of the sign.
 
  • Like
Reactions: loadka95
is there a reason you're not using the existing on sign change event?

code_language.skript:
on sign change:
    broadcast "%line 1%"
 
is there a reason you're not using the existing on sign change event?

code_language.skript:
on sign change:
    broadcast "%line 1%"
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.
 
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.
I created the sign using (open sign editor) packet, and the event is not working with it
 
Status
Not open for further replies.