Add server-side model allocation and functions (follow-up #5232) - #5233
Add server-side model allocation and functions (follow-up #5232)#5233MohabCodeX wants to merge 7 commits into
Conversation
…l Allocation Part 1) - Move hardcoded handling array to handling.conf - Add objects.conf, peds.conf, and vehicles.conf - Add config loader classes for handling, vehicles, objects, and peds
…del Allocation Part 2) - Add CModel base class and CModelVehicle, CModelPed, CModelObject classes - Add CModelManager for dynamic model allocation and base model registration - Integrate CModelManager with CGame startup and CResource cleanup
… Allocation Part 3) - Connect entity managers (vehicle, ped, object) to CModelManager for dynamic validation - Update vehicle property getters to query CModelVehicle - Enable parent handling ID resolution in CHandlingManager
…part 4) - Add CLuaEngineDefs with modern ArgumentParser bindings for server model functions: engineRequestModel, engineFreeModel, engineGetModelParent, engineGetModelType, engineGetModelAllocatingResource, engineGetModelsByType, and engineIsModelCustom. - Support requestedId in CModelManager::RequestModel to allow 1:1 synchronization with client-allocated model IDs. - Fix base model parent ID resolution in CModel. - Register CLuaEngineDefs in CLuaManager. - Verified in-game with model_allocation_test resource: 21 unit tests passed and custom BMW vehicle successfully spawned."
|
I used a similar idea but with server logical IDs separated from each client’s local GTA runtime IDs. You can check my commits and docs here: server model registry (Dryxio/mtasa-neon@a7a20d32b), completed registry (Dryxio/mtasa-neon@dc25a615c), API docs (https://mtasa-neon-wiki.vercel.app/neon/models-and-streaming) |
|
Man, you’re doing some really great work <3 Thank you for the suggestions and sharing. I’ll definitely go through them and review the ideas you mentioned. |
…ic sync - Enables server-driven model allocation without requiring manual ID coordination or client pre-allocation. - Automatically inherits handling physics, properties, and vehicle attributes from base game models. - Safely remaps live in-game entities to their parent models whenever a custom model is freed in real-time.
Quick update
Special thanks again to @Dryxio. |
This PR is a follow-up to #5232 and implements a server-authoritative model allocation system. It allows servers to dynamically register custom vehicle, ped, and object models, automatically synchronize them with connected and joining players, inherit properties and handling from base models, and safely remap active entities when models are freed.
Special thanks to @Dryxio for proposing the concept, sharing his initial implementation approach, and providing valuable insights that helped shape this server-authoritative system.
Summary of Changes
New Lua Functions
engineRequestModelSide: Shared (Client & Server)
Allocates a new custom model ID inheriting properties and handling from an existing base model.
Syntax
Required Arguments
modelType: The element type to allocate ("vehicle","ped", or"object").parentModelId: The base game model ID to inherit properties and handling from.Optional Arguments
name: A unique custom name or alias for the model.Returns
42341..65534) on success, orfalseon failure.engineFreeModelSide: Shared (Client & Server)
Frees a previously allocated custom model ID. Any live entities in the game world using this model will automatically fall back to their parent model.
Syntax
Required Arguments
modelId: The custom model ID to free.Returns
trueif the model was successfully freed, orfalseotherwise.engineGetModelParentSide: Shared (Client & Server)
Retrieves the parent base model ID that a custom model inherits properties from.
Syntax
Required Arguments
modelId: The model ID to query.Returns
falseon failure.engineGetModelTypeSide: Shared (Client & Server)
Retrieves the element type associated with a model ID.
Syntax
Required Arguments
modelId: The model ID to query.Returns
"vehicle","ped", or"object"as a string, orfalseon failure.engineGetModelNameSide: Shared (Client & Server)
Retrieves the registered custom name of a model ID.
Syntax
Required Arguments
modelId: The model ID to query.Returns
falseif not found.engineGetModelFromNameSide: Shared (Client & Server)
Resolves a custom model's registered name to its logical model ID.
Syntax
Required Arguments
name: The model name to look up.Returns
falseif no model with that name exists.engineGetModelAllocatingResourceSide: Server-only
Retrieves the resource that originally requested and allocated the custom model.
Syntax
Required Arguments
modelId: The custom model ID to query.Returns
false.engineGetModelsByTypeSide: Shared (Client & Server)
Returns a table containing all registered model IDs of a specific type.
Syntax
Required Arguments
modelType: The model type to filter by ("vehicle","ped", or"object").Optional Arguments
minModelId: An optional lower bound to filter model IDs from.Returns
engineIsModelCustomSide: Shared (Client & Server)
Checks whether a model ID represents a custom allocated model.
Syntax
Required Arguments
modelId: The model ID to check.Returns
trueif the model is a custom allocated model, orfalseif it is a vanilla game model.engineGetModelRuntimeIDSide: Client-only
Gets the internal GTA engine slot currently bound to a server logical model ID.
Syntax
Required Arguments
modelId: The server logical model ID (42341..65534).Returns
false.engineGetModelLogicalIDSide: Client-only
Resolves an internal GTA engine slot ID back to its server logical model ID.
Syntax
Required Arguments
runtimeSlot: The internal GTA engine slot ID.Returns
false.Example Workflow
1. Server Script (
server.lua)2. Client Script (
client.lua)Testing & Verification
server_model_registry_test.zip
/testmodelsruns automated assertions covering dynamic allocation, handling inheritance, name resolution, and resource cleanup./spawnbmw,/spawnlada, and/spawnisuzuspawn and warp into the custom vehicles./freebmwfrees the custom model while seated and reverts the car to the base Merit (551)./allocbmwre-allocates the model and transforms the car back to the BMW M5.