add server-side and client-side entity spawn wrappers and shared helper#762
add server-side and client-side entity spawn wrappers and shared helper#762TGIANN wants to merge 2 commits intooverextended:mainfrom
Conversation
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
| 'imports/spawnEntity/server.lua', | ||
| 'imports/createObject/server.lua', | ||
| 'imports/createPed/server.lua', | ||
| 'imports/createVehicle/server.lua', |
| ---@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 |
There was a problem hiding this comment.
It would be best to have a types file or have game types like this defined as part of fivem-lls-addon.
|
My biggest issues with this are
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 |
Add
lib.createObject,lib.createPed, andlib.createVehiclefor the server, plus a sharedlib.spawnEntityhelper used by both client and server wrappers. Each wrapper splits its body at module load time based oncache.gameso that the correct CREATE_OBJECT/PED/VEHICLE native signature is used on FiveM vs RedM.Server wrappers default
orphanModeto 2 (KeepEntity). ServercreateVehicleusesCreateVehicleServerSetter(withvehicleType) on FiveM and the CFXCreateVehiclenative on RedM, wherevehicleType,properties, andseatare not exposed.Existing client wrappers were refactored to delegate model loading to
lib.spawnEntity, with a few client-side fixes folded in:SetEntityHeadingfor createObjectnetMissionEntitywithisNetworkin createPedisNetworkassert in createPedisNetwork,netMissionEntity, anddoorFlagas optional in the type annotations to match runtime behavior