Skip to content
This repository was archived by the owner on Aug 9, 2025. It is now read-only.

Factories

tbeck edited this page Sep 17, 2023 · 3 revisions

Learn how to use entity factories. Use your own entity structs with custom properties.
⛔️ This page may not be up to date.


Entity factories allows you to optimize your server performance by defining the data you need to store in a player or vehicle on compile time.
This allows much faster data access than via .SetData, .Data.

Creating a player factory

  1. Create a new player struct
type MyPlayer struct {
    entity.Player
    LoggedIn bool
}
  1. Create the factory callback
func CreatePlayer(ptr unsafe.Pointer, id uint16) entity.IPlayer {
    p := &MyPlayer{}
    p.SetPointer(ptr)
    p.SetID(id)

    return p
}
  1. Register the factory
factories.SetPlayerFactory(CreatePlayer)

Usage Example

event.On.PlayerConnect(func (player entity.IPlayer) {
    p := player.(*MyPlayer)
    p.LoggedIn = true
})

Clone this wiki locally