Skip to content

add server-side and client-side entity spawn wrappers and shared helper#762

Open
TGIANN wants to merge 2 commits intooverextended:mainfrom
TGIANN:main
Open

add server-side and client-side entity spawn wrappers and shared helper#762
TGIANN wants to merge 2 commits intooverextended:mainfrom
TGIANN:main

Conversation

@TGIANN
Copy link
Copy Markdown
Contributor

@TGIANN TGIANN commented May 2, 2026

Add lib.createObject, lib.createPed, and lib.createVehicle for the server, plus a shared lib.spawnEntity helper used by both client and server wrappers. Each wrapper splits its body at module load time based on cache.game so that the correct CREATE_OBJECT/PED/VEHICLE native signature is used on FiveM vs RedM.

Server wrappers default orphanMode to 2 (KeepEntity). Server createVehicle uses CreateVehicleServerSetter (with vehicleType) on FiveM and the CFX CreateVehicle native on RedM, where vehicleType, properties, and seat are not exposed.

Existing client wrappers were refactored to delegate model loading to lib.spawnEntity, with a few client-side fixes folded in:

  • pass heading as the float arg in SetEntityHeading for createObject
  • replace undefined netMissionEntity with isNetwork in createPed
  • drop duplicate isNetwork assert in createPed
  • mark isNetwork, netMissionEntity, and doorFlag as optional in the type annotations to match runtime behavior

Add `lib.createObject`, `lib.createPed`, and `lib.createVehicle` for the
server, plus a shared `lib.spawnEntity` helper used by both client and
server wrappers. Each wrapper splits its body at module load time based
on `cache.game` so that the correct CREATE_OBJECT/PED/VEHICLE native
signature is used on FiveM vs RedM.

Server wrappers default `orphanMode` to 2 (KeepEntity). Server
`createVehicle` uses `CreateVehicleServerSetter` (with `vehicleType`)
on FiveM and the CFX `CreateVehicle` native on RedM, where
`vehicleType`, `properties`, and `seat` are not exposed.

Existing client wrappers were refactored to delegate model loading to
`lib.spawnEntity`, with a few client-side fixes folded in:
- pass heading as the float arg in `SetEntityHeading` for createObject
- replace undefined `netMissionEntity` with `isNetwork` in createPed
- drop duplicate `isNetwork` assert in createPed
- mark `isNetwork`, `netMissionEntity`, and `doorFlag` as optional in
  the type annotations to match runtime behavior
@TGIANN
Copy link
Copy Markdown
Contributor Author

TGIANN commented May 2, 2026

Comment thread fxmanifest.lua Outdated
Comment on lines +46 to +49
'imports/spawnEntity/server.lua',
'imports/createObject/server.lua',
'imports/createPed/server.lua',
'imports/createVehicle/server.lua',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unnecessary.

Comment thread imports/createVehicle/client.lua Outdated
Comment on lines +9 to +18
---@alias SeatPosition
---| -2 # SF_ANY
---| -1 # SF_FrontDriverSide
---| 0 # SF_FrontPassengerSide
---| 1 # SF_BackDriverSide
---| 2 # SF_BackPassengerSide
---| 3 # SF_AltFrontDriverSide
---| 4 # SF_AltFrontPassengerSide
---| 5 # SF_AltBackDriverSide
---| 6 # SF_AltBackPassengerSide
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be best to have a types file or have game types like this defined as part of fivem-lls-addon.

@thelindat
Copy link
Copy Markdown
Member

thelindat commented May 2, 2026

My biggest issues with this are

  • code duplication
  • type disparity (i.e. function declarations differ greatly between fivem/redm/fxserver)
  • uses RPCs in some cases (almost never good)

I'd personally want to see classes used for any entity wrappers, e.g.

lib.entity as a base class inherited by lib.object, lib.ped, lib.vehicle with some common methods across server and client.

Networked entities from clients are also somewhat discouraged and potentially disabled on many servers, so focusing on server-created entities is more important.

@TGIANN
Copy link
Copy Markdown
Contributor Author

TGIANN commented May 2, 2026

My biggest issues with this are

  • code duplication
  • type disparity (i.e. function declarations differ greatly between fivem/redm/fxserver)
  • uses RPCs in some cases (almost never good)

I'd personally want to see classes used for any entity wrappers, e.g.

lib.entity as a base class inherited by lib.object, lib.ped, lib.vehicle with some common methods across server and client.

Networked entities from clients are also somewhat discouraged and potentially disabled on many servers, so focusing on server-created entities is more important.

I've re edit everything. If everything is as you want and there are no issues, I can prepare the docs

test script
tgiann-test.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants