Server events

A list of server side events you can use in your scripts.

Core events

These events are part of FiveM and do not require any resource.

Index

Functions

entityCreated

  • entityCreated(handle: number): void
  • A server-side event that is triggered when an entity has been created.

    Parameters

    • handle: number

    Returns void

entityCreating

  • entityCreating(handle: number): void
  • A server-side event that is triggered when an entity is being created.

    This event can be canceled to instantly delete the entity.

    Parameters

    • handle: number

    Returns void

entityRemoved

  • entityRemoved(entity: number): void
  • Triggered when an entity is removed on the server.

    Parameters

    • entity: number

      The handle of the entity that got removed.

    Returns void

onResourceListRefresh

  • onResourceListRefresh(): void
  • A server-side event triggered when the refresh command completes.

    Returns void

onResourceStart

  • onResourceStart(resource: string): void
  • An event that is triggered immediately when a resource has started.

    Parameters

    • resource: string

      The name of the resource that just started.

    Returns void

onResourceStarting

  • onResourceStarting(resource: string): void
  • An event that is triggered when a resource is trying to start.

    This can be canceled to prevent the resource from starting.

    Parameters

    • resource: string

      The name of the resource that is trying to start.

    Returns void

onResourceStop

  • onResourceStop(resource: string): void
  • An event that is triggered immediately when a resource is stopping.

    Parameters

    • resource: string

      The name of the resource that is stopping.

    Returns void

onServerResourceStart

  • onServerResourceStart(resource: string): void
  • An event that is queued after a resource has started.

    Parameters

    • resource: string

      The name of the resource that has started.

    Returns void

onServerResourceStop

  • onServerResourceStop(resource: string): void
  • An event that is triggered after a resource has stopped.

    Parameters

    • resource: string

      The name of the resource that has stopped.

    Returns void

playerConnecting

  • playerConnecting(playerName: string, setKickReason: (reason: string) => void, deferrals: { defer: any; done: any; handover: any; presentCard: any; update: any }, source: string): void
  • A server-side event that is triggered when a player is trying to connect.

    This event can be canceled to reject the player instantly, assuming you haven't yielded.

    Parameters

    • playerName: string

      The display name of the player connecting.

    • setKickReason: (reason: string) => void

      A function used to set a reason message for when the event is canceled.

        • (reason: string): void
        • Parameters

          • reason: string

          Returns void

    • deferrals: { defer: any; done: any; handover: any; presentCard: any; update: any }

      An object to control deferrals.

      • defer: function
        • defer(): void
        • deferrals.defer will initialize deferrals for the current resource. It is required to wait for at least a tick after calling defer before calling update, presentCard or done.

          Returns void

      • done: function
        • done(failureReason?: string): void
        • deferrals.done finalizes a deferral. It is required to wait for at least a tick before calling done after calling a prior deferral method.

          Parameters

          • Optional failureReason: string

            If specified, the connection will be refused, and the user will see the specified message as a result. If this is not specified, the user will be allowed to connect.

          Returns void

      • handover: function
        • handover(data: {}): void
        • deferrals.handover adds handover data for the client to be able to use at a later point.

          Parameters

          • data: {}

            Data to pass to the connecting client.

            • [key: string]: any

          Returns void

      • presentCard: function
        • presentCard(card: string | object, cb?: (data: any, rawData: string) => void): void
        • deferrals.presentCard will send an Adaptive Card to the client.

          Parameters

          • card: string | object

            An object containing card data, or a serialized JSON string with the card information.

          • Optional cb: (data: any, rawData: string) => void

            If present, will be invoked on an Action.Submit event from the Adaptive Card.

              • (data: any, rawData: string): void
              • A callback to be invoked for Action.Submit.

                Parameters

                • data: any

                  A parsed version of the data sent from the card.

                • rawData: string

                  A JSON string containing the data sent from the card.

                Returns void

          Returns void

      • update: function
        • update(message: string): void
        • deferrals.update will send a progress message to the connecting client.

          Parameters

          • message: string

            The string to send to the client.

          Returns void

    • source: string

      The player's temporary NetID (a number in Lua/JS), not a real argument, use [FromSource] or source.

    Returns void

playerEnteredScope

  • playerEnteredScope(data: { for: string; player: string }): void
  • A server-side event that is triggered when a player enters another player's scope.

    Parameters

    • data: { for: string; player: string }

      Data containing the players entering each other's scope.

      • for: string

        The player for which the scope is being entered.

      • player: string

        The player that is entering the scope.

    Returns void

playerJoining

  • playerJoining(source: string, oldID: string): void
  • A server-side event that is triggered when a player has a finally-assigned NetID.

    Parameters

    • source: string

      The player's NetID (a number in Lua/JS), not a real argument, use [FromSource] or source.

    • oldID: string

      The original TempID for the connecting player, as specified during playerConnecting.

    Returns void

playerLeftScope

  • playerLeftScope(data: { for: string; player: string }): void
  • A server-side event that is triggered when a player leaves another player's scope.

    Parameters

    • data: { for: string; player: string }

      Data containing the players leaving each other's scope.

      • for: string

        The player for which the scope is being left.

      • player: string

        The player that is leaving the scope.

    Returns void

startProjectileEvent

  • startProjectileEvent(sender: number, data: { commandFireSingleBullet: boolean; effectGroup: number; firePositionX: number; firePositionY: number; firePositionZ: number; initialPositionX: number; initialPositionY: number; initialPositionZ: number; ownerId: number; projectileHash: number; targetEntity: number; throwTaskSequence: number; unk10: number; unk11: number; unk12: number; unk13: number; unk14: number; unk15: number; unk16: number; unk3: number; unk4: number; unk5: number; unk6: number; unk7: number; unk9: number; unkX8: number; unkY8: number; unkZ8: number; weaponHash: number }): void
  • Triggered when a projectile is created.

    Parameters

    • sender: number

      The ID of the player that triggered the event.

    • data: { commandFireSingleBullet: boolean; effectGroup: number; firePositionX: number; firePositionY: number; firePositionZ: number; initialPositionX: number; initialPositionY: number; initialPositionZ: number; ownerId: number; projectileHash: number; targetEntity: number; throwTaskSequence: number; unk10: number; unk11: number; unk12: number; unk13: number; unk14: number; unk15: number; unk16: number; unk3: number; unk4: number; unk5: number; unk6: number; unk7: number; unk9: number; unkX8: number; unkY8: number; unkZ8: number; weaponHash: number }

      The event data.

      • commandFireSingleBullet: boolean
      • effectGroup: number
      • firePositionX: number
      • firePositionY: number
      • firePositionZ: number
      • initialPositionX: number
      • initialPositionY: number
      • initialPositionZ: number
      • ownerId: number
      • projectileHash: number
      • targetEntity: number
      • throwTaskSequence: number
      • unk10: number
      • unk11: number
      • unk12: number
      • unk13: number
      • unk14: number
      • unk15: number
      • unk16: number
      • unk3: number
      • unk4: number
      • unk5: number
      • unk6: number
      • unk7: number
      • unk9: number
      • unkX8: number
      • unkY8: number
      • unkZ8: number
      • weaponHash: number

    Returns void