> For the complete documentation index, see [llms.txt](https://novoline.gitbook.io/novoscript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://novoline.gitbook.io/novoscript/api/events.md).

# Events

## enable

This event will be called when the module enables

```javascript
module.onEvent("enable",function(){
    // do stuff
})
```

## disable

```javascript
module.onEvent("disable",function(){
    // do stuff
})
```

This event will be called when the module disables

## playerUpdateEvent

This event will be called on the local player update if the chunk you're currently at is loaded. Called before preUpdateEvent and postUpdateEvent

```javascript
module.onEvent("playerUpdateEvent",function(event){
    // do stuff
})
```

## playerPreUpdate

This event will be called before sending all of the position packets

| Method      | Parameters | Type    | Description                          |
| ----------- | ---------- | ------- | ------------------------------------ |
| getX        | None       | double  | Position X of a player               |
| getY        | None       | double  | Position Y of a player               |
| getZ        | None       | double  | Position Z of a player               |
| setX        | double     | void    | Sets the position X for a player     |
| setY        | double     | void    | Sets the position Y for a player     |
| setZ        | double     | void    | Sets the position Z for a player     |
| getYaw      | None       | float   | Rotation yaw of a player             |
| getPitch    | None       | float   | Rotation pitch of a player           |
| setYaw      | float      | void    | Sets the yaw for a player (Silent)   |
| setPitch    | float      | void    | Sets the pitch for a player (Silent) |
| isOnGround  | None       | boolean | The ground state of a player         |
| setOnGround | boolean    | void    | Sets the ground state for a player   |

```javascript
module.onEvent("playerPreUpdateEvent",function(event){
    var y = event.getY();
    event.setY(y + 0.001);
    // do stuff
})
```

## playerPostUpdate

This event will be called after sending all of the position packets

```javascript
module.onEvent("playerPostUpdateEvent",function(event){
    // do stuff
})
```

## moveEvent

This event will be called before the player moves

| Method       | Parameters | Type   | Description                            |
| ------------ | ---------- | ------ | -------------------------------------- |
| getX         | None       | double | X motion of a player                   |
| getY         | None       | double | Y motion of a player                   |
| getZ         | None       | double | Z motion of a player                   |
| setX         | double     | void   | Sets the X motion for a player         |
| setY         | double     | void   | Sets the Y motion for a player         |
| setZ         | double     | void   | Sets the Z motion for a player         |
| setMoveSpeed | double     | void   | Sets the movement speed for the player |

```javascript
// BHop twice as fast as vanilla hop
module.onEvent("moveEvent",function(event){
    if(player.isOnGround()){
        event.setY(player.setMotionY(0.39999999));
    }
    event.setMoveSpeed(player.getBaseMoveSpeed() * 2);
    
})
```

## render2DEvent

This event will be called before the overlay is rendered

| Method          | Parameters | Type             | Description                            |
| --------------- | ---------- | ---------------- | -------------------------------------- |
| getPartialTicks | None       | float            | The delta between the last render tick |
| getResolution   | None       | ScaledResolution | Scaled resolution of the window        |

```javascript
module.onEvent("render2DEvent",function(event){
    var resolution = event.getResolution();
    render_util.drawFilledRectangle(0,0,resolution.getScaledWidth(),resolution getScaledHeight(),0xffffff);
    // do stuff
})
```

## render3D

This event will be called before the world is rendered

| Method          | Parameters | Type  | Description                            |
| --------------- | ---------- | ----- | -------------------------------------- |
| getPartialTicks | void       | float | The delta between the last render tick |

```javascript
module.onEvent("render3DEvent",function(event){
    var partialTicks = event.getPartialTicks();
    // do stuff
})
```

## loadWorld

This event will be called before the world is loaded

```javascript
module.onEvent("loadWorldEvent",function(event){
    // do stuff
})
```

## packetSend

This event will be called before the packet is send

| Method    | Parameters                     | Type   | Description                                                                  |
| --------- | ------------------------------ | ------ | ---------------------------------------------------------------------------- |
| setPacket | <p>String;</p><p>Object...</p> | void   | Replaces the packet you send with the one you provide. See the example below |
| getPacket | None                           | Packet | Returns the packet you send (only a few of them are editable)                |

```javascript
module.onEvent("packetSendEvent",function(event){
    if(event.getPacket().getName() == "0x04"){
        var packet = event.getPacket();
        
        // Spoofing ground state to be always true
        {
            packet.setOnGround(true);
        }
        // Another way of doing this
        {
            event.setPacket("0x04",packet.getX(),packet.getY(),packet.getZ(),true);
        }
        // do stuff
    }
})
```

#### Cancelling the event

```javascript
module.onEvent("packetSendEvent",function(event){
    if(event.getPacket().getName() == "0x04"){
        event.setCancelled(true); 
    }
})
```

{% content-ref url="/pages/-MdV0CMPRkhaTi7HUpOB" %}
[Packets](/novoscript/api/objects-1/packets.md)
{% endcontent-ref %}

## packetReceive

This event will be called before the packet is received

| Method    | Parameters | Type   | Description                    |
| --------- | ---------- | ------ | ------------------------------ |
| getPacket | None       | Packet | Returns the packet you receive |

```javascript
// No Rotate
module.onEvent("packetReceiveEvent",function(event){
    if(event.getPacket().getName() == "S0x08"){ // S08PacketPlayerPosLook
        var packet = event.getPacket();
        packet.setYaw(player.getYaw());
        packet.setPitch(player.setPitch());
    }
    // do stuff
})
```

#### Canceling the event

```javascript
module.onEvent("packetReceiveEvent",function(event){
    if(event.getPacket().getName() == "S0x08"){
        event.setCancelled(true);
    }
})
```

{% content-ref url="/pages/-MdV0CMPRkhaTi7HUpOB" %}
[Packets](/novoscript/api/objects-1/packets.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://novoline.gitbook.io/novoscript/api/events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
