Solved Need help with Packet sending

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

Orbinfog

New Member
Oct 6, 2020
6
0
1
Hiya everyone,
This is the first time I have ever asked for help on these forums as I often figure things out myself but I cannot do this myself and I really need some help with it.

I am using Skript 2.5.3, Skript-Packet v2.0.1 and Skript-Reflect v2.2.3 along with many other addons that should not be important in this.
Now, I have a pretty decent knowledge of Skript but really none when it comes to JavaScript. I am trying to send a packet to the player to change their pitch and yaw. I understand how to send packets and all that, I have been able to send other packets successfully using Skript-Packet, it's just this one.

Below is the function I am using. I am using the PacketPlayOutPosition packet to control the pitch and yaw. Ignore all of the fields except field 5. All of the other fields are correct and working properly. It is field 5 that I really need help with.

function FirearmRecoil(p: player, v: number, h: number):

#V = vertical recoil (pitch), H = horizontal (yaw)
set {_packet} to new play_server_position packet
set field 0 of {_packet} to 0.doubleValue()
set field 1 of {_packet} to 0.doubleValue()
set field 2 of {_packet} to 0.doubleValue()
set field 3 of {_packet} to {_h}.floatValue()
set field 4 of {_packet} to {_v}.floatValue()
set field 5 of {_packet} to ############Need help here
set field 6 of {_packet} to 0
send {_p} packet {_packet}
https://minidigger.github.io/MiniMappingViewer/#/spigot/server/1.15.2/PacketPlayOutPosition
To get the packet to work as I intend it to, I need to set field 5 to a HashSet with the values "X, X_ROT, Y, Y_ROT, Z". The problem is I have no idea how to do that. I don't even know if it is possible with Sk-Reflect (Sk-Mirror fork).

Using what DeeCaaD said on the Spigot Forums (https://www.spigotmc.org/threads/change-players-yaw-pitch-for-recoil-effect.338132/), with actual Java he just does:

private Set<EnumPlayerTeleportFlags> teleportFlags = new HashSet<>(Arrays.asList(EnumPlayerTeleportFlags.X, EnumPlayerTeleportFlags.Y, EnumPlayerTeleportFlags.Z));

And then sends the packet with that Set as the fifth field.

Is it possible to do that with Skript using Sk-Reflect? If not, are there any other workarounds to get it to work?

Cheers,
- Orbinfog

(quick edit: It has to be a HashSet, because otherwise objects/lists etc are not accepted)
 
Last edited:
Code:
import:
   net.minecraft.network.protocol.game.PacketPlayOutPosition
   java.util.Set

function packetPosition(loc: location, teleport: boolean) :: object:
   if {_teleport} is true:
       set {_set} to Set.of()
       return new PacketPlayOutPosition({_loc}.getX(),{_loc}.getY(),{_loc}.getZ(),{_loc}.getYaw(),{_loc}.getYaw(),{_set},0,true)
   else:
       set {_set} to Set.of(PacketPlayOutPosition.EnumPlayerTeleportFlags.a, PacketPlayOutPosition.EnumPlayerTeleportFlags.b, PacketPlayOutPosition.EnumPlayerTeleportFlags.c)
       return new PacketPlayOutPosition(0,0,0,{_loc}.getYaw(),{_loc}.getPitch(),{_set},0,true)
 
  • Like
Reactions: Orbinfog
Code:
import:
   net.minecraft.network.protocol.game.PacketPlayOutPosition
   java.util.Set

function packetPosition(loc: location, teleport: boolean) :: object:
   if {_teleport} is true:
       set {_set} to Set.of()
       return new PacketPlayOutPosition({_loc}.getX(),{_loc}.getY(),{_loc}.getZ(),{_loc}.getYaw(),{_loc}.getYaw(),{_set},0,true)
   else:
       set {_set} to Set.of(PacketPlayOutPosition.EnumPlayerTeleportFlags.a, PacketPlayOutPosition.EnumPlayerTeleportFlags.b, PacketPlayOutPosition.EnumPlayerTeleportFlags.c)
       return new PacketPlayOutPosition(0,0,0,{_loc}.getYaw(),{_loc}.getPitch(),{_set},0,true)

Ok awesome, that mainly works, but I get:
[Skript] No matching static constructor: PacketPlayOutPosition.<init> called with (0 (Long), 0 (Long), 0 (Long), -175.7 (Float), 18.6 (Float), [Y, Z, X] (SetN), 0 (Long), true (Boolean))
In the console.

When I use a test command with the function. How do I fix this? Also, excuse me if this is a stupid question, I barely know anything about Java; but with the return new PacketPlayOutPosition part of the function, do I then set the packet to that value or is that the packet itself being sent?
 
Ok awesome, that mainly works, but I get:
[Skript] No matching static constructor: PacketPlayOutPosition.<init> called with (0 (Long), 0 (Long), 0 (Long), -175.7 (Float), 18.6 (Float), [Y, Z, X] (SetN), 0 (Long), true (Boolean))
In the console.

When I use a test command with the function. How do I fix this? Also, excuse me if this is a stupid question, I barely know anything about Java; but with the return new PacketPlayOutPosition part of the function, do I then set the packet to that value or is that the packet itself being sent?
mb on your's server version packet has different fields or another import name of this class, idk
but after creation of PacketPlayOutPosition instance you need send this to player
Code:
player.getHandle().b.a({_packet})
this also can be different on your server version
 
Last edited:
  • Like
Reactions: Orbinfog
mb on your's server version packet has different fields or another import name of this class, idk
but after creation of PacketPlayOutPosition instance you need send this to player
Code:
player.getHandle().b.a({_packet})
this also can be different on your server version

Awesome man, thank you so much! I got it working. While I'm at it, do you have any idea how to use the PacketPlayOutCamera packet? I want to be able to use it to give the player Creeper or Enderman vision (as if they were spectating the entity) but allow them to move as normal, so they have control. Because when sending the packet with different entity IDs it gives away the players' control. (https://wiki.vg/Protocol#Set_Camera). If not, don't worry about it I'll just make a new thread some time.
 
Status
Not open for further replies.