This repository was archived by the owner on Aug 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
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.
- Create a new player struct
type MyPlayer struct {
entity.Player
LoggedIn bool
}- Create the factory callback
func CreatePlayer(ptr unsafe.Pointer, id uint16) entity.IPlayer {
p := &MyPlayer{}
p.SetPointer(ptr)
p.SetID(id)
return p
}- Register the factory
factories.SetPlayerFactory(CreatePlayer)event.On.PlayerConnect(func (player entity.IPlayer) {
p := player.(*MyPlayer)
p.LoggedIn = true
})You encountered a problem 💥? Check out the Troubleshooting Guide!
If you can't find a solution there file a new issue in this repository or contact me on Discord.