Send chunk (packet) to a player

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

aeim

Member
Feb 21, 2017
38
5
8
27
Hi, I have to change the chunk loading system to reduce a lot of lag when I ride my flying chicken,
the following code work fine and allow me to not lag anymore:

code_language.skript:
on packet event play_server_map_chunk:
    {game} is "start"
    if vehicle of player is a chicken:
        set {_Cx} to (int pnum 0 of event-packet)
        set {_Cz} to (int pnum 1 of event-packet)
        {CHUNK::%event-player%::%{_Cx}%_%{_Cz}%} is not set
        cancel event
        while event-player is riding a chicken:
            set {_Px} to chunk-x of chunk of event-player
            set {_Pz} to chunk-z of chunk of event-player
            set {_x} to {_Cx} - {_Px}
            set {_z} to {_Cz} - {_Pz}
            set {_D} to sqrt ( ({_x}^2) + ({_z}^2) )
            
            if {_D} <= 6:
                set {CHUNK::%event-player%::%{_Cx}%_%{_Cz}%} to true
                send packet event-packet to event-player
                wait a second
                delete {CHUNK::%event-player%::%{_Cx}%_%{_Cz}%}
                stop
            wait a second

But i have a small problem here :
send packet event-packet to event-player

Cause this can be an old packet and the chunk can be modified while I ride my chicken, I don't know how to send an actual chunk to a player ( Load/unload chunk is server side, and placing a block do not send a new chunk packet)

So if i do :

code_language.skript:
command /chunk <integer> <integer>:
    trigger:
        set {_packet} to new play_server_unload_chunk packet
        set int pnum 0 of {_packet} to arg-1
        set int pnum 1 of {_packet} to arg-2
        send packet {_packet} to player
        
on packet event play_server_unload_chunk:
    {game} is "start"
    set {_Cx} to (int pnum 0 of event-packet)
    set {_Cz} to (int pnum 1 of event-packet)
    broadcast "unload %{_Cx}% %{_Cz}%"

How to send a chunk to a player ?
 
Why are you sending a packet of the chunk?

The world class object of Spigot has the ability to load chunks. If your game is dependent on an open world based game, try loading all the chunks within your games boundary. Skellett, MundoSk and like 3 other addons have the ability to load and unload chunks. WorldBorder (a plugin on Bukkit) has the ability to load all chunks within an area if you want to use commands in console for your area, this works. Most of the time this is the main system minigames use to load chunks. Pretty sure sending packets will currupt something in the world. Another alternative would be using FAWE for chunk based management which will do all this async and quickly.
 
Status
Not open for further replies.