Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ability to create server-side vehicles with custom ids #1936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

@pentaflops
Copy link
Contributor

@pentaflops pentaflops commented Dec 21, 2020
edited
Loading

Add new argument specificID

int engineRequestModel ( str elementType [, int parentID, int specificID ] )

Before creating a vehicle with a custom id, you need to request a model (server-side):

int requestModel ( int specificID, str elementType [, int parentID ] )

Returns false if the model has already been requested

Added new packet to sync and requesting new ID on the client custom models.
If a vehicle with a conflicting id is created on the server, the client will receive a error protocol 39.

Increased bitstream version and added backward compatibility (need add minclientversion to use requestModel)

If the community will support these changes, then I plan to add support for skins and objects

xLive, sacr1ficez, jayceon123, PlatinMTA, MrDadosz, Shuubaru, ArranTuna, AlexTMjugador, Gallardo994, jey-banned, and fresholia reacted with thumbs up emoji Dutchman101 reacted with rocket emoji
@StrixG StrixG added the enhancement New feature or request label Dec 21, 2020
Copy link
Contributor

Pirulax commented Dec 21, 2020

We have an issue about this #1701.
Have you read it?

Copy link
Contributor

We have an issue about this #1701.
Have you read it?

#1701 is already merged and it works, but only for clientside peds, which in reality won't be of much use. I guess this PR is trying to solve that.

Copy link
Contributor

Pirulax commented Dec 21, 2020

Sorry, its #1835

PlatinMTA and AlexTMjugador reacted with thumbs up emoji pentaflops reacted with confused emoji

Copy link
Contributor

Pirulax commented Dec 23, 2020

I dont feel like this is a good solution.
And since it breaks backwards compatibility, we might as well just implement the solution described by me in #1835

Copy link
Member

I dont feel like this is a good solution.

It's good simply solution

Copy link
Member

Please, test it with old client and new server

Copy link
Contributor

Pirulax commented Dec 25, 2020

You can't simply change the value from a char to a short, this will cause packet misalignment if the server is running an older version.

This PR must break backwards compatibility, and since it does, we might as well just do it as described in #1835

Copy link
Contributor

Allerek commented Dec 30, 2020
edited
Loading

When doing so, we should allow to set custom vehicle-name when requesting ID for it. #1849

If name not specified, take parent id name.

Pirulax, oxmaulmike2581, pentaflops, Shuubaru, Allerek, jey-banned, and AlexTMjugador reacted with thumbs up emoji

Copy link
Contributor

Allerek commented Jan 26, 2021

I see we have some minor checks like:
HasPoliceRadio
DoCheckHasLandingGear
HasTaxiLight
IsTrainModel
HasSirens
etc.
But do we have
-ZR-350 lights
-Packer
-Andromeda back door
(i dont think we have more 'misc' options)
?

Copy link
Contributor Author

@Pirulax check review pls

Copy link
Member

sbx320 commented Apr 20, 2021

I don't think requesting a specific id is a good solution either as it will lead to collisions between resources.

AlexTMjugador and Pirulax reacted with thumbs up emoji

Copy link
Contributor

Pirulax commented Apr 20, 2021

Thanks for the PR very much. I'm sorry but I (we?) have to decline it.
We've discussed how it should be implemented, and came to the conclusion that using script entities instead of ID's is a better choice (to avoid people hardcoding stuff).
I really have a bias against using integer's as model ID's as it gets really messy, especially with dynamic IDs.
See #custom-model-ids channel on Dev discord.

TheNormalnij, Allerek, and pentaflops reacted with thumbs down emoji

Copy link
Member

TheNormalnij commented Apr 20, 2021
edited
Loading

Why you want avoid hardcoding stuff? Numeric IDs are easy, backward compatible, good for databases.
script entities instead of ID's sounds like a creepy abstraction layer.

And yeah this stuff is for manual management

StrixG and pentaflops reacted with thumbs up emoji

Copy link
Contributor Author

pentaflops commented Apr 20, 2021
edited
Loading

From discord:
My implementation allows you to work with custom vehicles as with a standar vehicles, without need to adapt many current scripts for this (only scripts current use engineRequestModel so that there are no id conflicts). And this is important.

Obviously, the problem of collisions should be solved by developer who will add new vehicles. You are now proposing to complicate something that does not require complication. Adding non-static identification don't solve any problem, it only complicates.

Copy link
Member

AlexTMjugador commented Apr 21, 2021
edited
Loading

The problem I see with using numeric IDs as-is is that they lure people into thinking they are the simplest solution that keeps backwards compatibility, but on practical terms, when actually requesting custom model IDs in the client and the server, complexity scalates quickly, because 1) each server has to reinvent the wheel to manage this problem, 2) depend on a community resource that does this for them or 3) be ignorant of this problem and wonder why things break.

One may think that, if model IDs could only be requested on the server, then these discrepancies would be solved, but requesting a model for every client just because a single client wants to show a vehicle preview in a car shop, for example, wastes a fair amount of bandwidth. Besides, we would break backwards compatibility anyway, because model requests are clientside right now.

It also makes sense to promote element models to their own entity, as with these changes they would have associated logic and a lifetime that's not necessarily the same as the lifetime of the elements that use them, to name some reasons. Insisting on representing entities with primitive data types is known as the primitive obsession antipattern and usually leads to suboptimal solutions in the long (or even short) run. Also, MTA is reasonably expected to keep serverside things synchronized in a transparent and relatively effortless manner, and this approach breaks this expectation.

For reference and clarity purposes, I made this UML class diagram showing an hypothetical OOP Lua API that I think it'd be nice to implement (with some ideas from @sbx320 and @Pirulax):

Custom model IDs API UML class diagram

Custom model IDs API UML class diagram

PlantUML code of the above diagram:

@startuml "Custom model IDs API"
title Custom model IDs API
class Element {
	+setModel(ElementModel model) : void
	+getModel() : ElementModel
	-- Rest of methods --
	...
}
class ElementModel {
	{static} +fromGameModelId(int id) : Model
	{static} +getAllModels() : Model [1..*]
	{static} +request(ElementModelType type, ElementModel parent) : CustomModel
	-int internalId
}
note left: This API is shared.\n\ninternalId is only known by MTA C++ code.\n\nWhen a client requests a new model,\nits internalId is the next free one for\nuse with GTA.\n\nWhen a server requests a new model,\nits internalId may be a sequential number,\nand clients should request a new model\n(maybe with a different internalId in each\nclient). If a client runs out of internalIds\nduring this operation, it may 1) be kicked\nor 2) the request may return false\n(preferred).\n\nClients keep a server internal ID -> actual\ninternal ID mapping, so they know how to\ntranslate server IDs in packets and so on\nappropriately to keep sync.\n\nServer databases may store models as a\n(type, ID) pair, where "type" distinguishes\nbetween GTA and custom models, and ID\ncan be an index for a Lua table entry that\ncontains data about that model, like a\nfactory method that calls\nElementModel.request to initialize the\nmodel for the first time.\n\nWhen a ElementModel element gets\ndestroyed, the elements that use it are\nreset to the parent element model or\nanother suitable default. This can happen\nwhen the resource that requested them\nstops or destroyElement() is used.
ElementModel "1" --> "0..*" ElementModel : children
Element <|.. ElementModel
enum ElementModelType {
	PED
	VEHICLE
	OBJECT
}
ElementModel ..> ElementModelType
@enduml

Edit: a getAll method for ElementModel would not be needed because it'd be yet another element type, and we can use getElementsByType already.

If we agree that this is a good API, then we can implement these features with less risk of them being rejected or problematic in the long term. Of course it'd depend on things like #1591, but I think it's a good way to go.

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

Reviewers

@Pirulax Pirulax Awaiting requested review from Pirulax

1 more reviewer

@TheNormalnij TheNormalnij TheNormalnij left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

enhancement New feature or request

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /