Skip to content

Implement Dialog packet and add MP.ConfirmationDialog #427

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

Merged
merged 2 commits into from
Jun 26, 2025
Merged

Conversation

WiserTixx
Copy link
Collaborator

@WiserTixx WiserTixx commented Mar 30, 2025

This PR implements a new lua function and packet used for sends dialogs to the client.

Example:

BeamNG.drive.x64_kX4w6Kaly9.mp4

Example serverside code:

--MP.ConfirmationDialog(player_id: number, title: string, body: string, buttons: object, interaction_id: string, warning: boolean = false, reportToServer: boolean = true, reportToExtensions: boolean = true)

function onChatMessage(player_id, player_name, message)
    MP.ConfirmationDialog(player_id, "Warning", "Watch your tone buddy!!", 
        {
            {
                label = "OK",
                key = "dialogOK",
                isCancel = true
            }
        }, "interactionID", true)
end

MP.RegisterEvent("onChatMessage", "onChatMessage")


function dialogOK(player_id, interaction_id)
    MP.SendChatMessage(-1, MP.GetPlayerName(player_id) .. " clicked OK")
end

MP.RegisterEvent("dialogOK", "dialogOK")

Details:

Each dialog can have multiple buttons, each button having it's own callback event (key).
Each dialog can also have one button with isCancel being true, settings this property to true causes the button's event to be called when the users pressed esc to exit out of the dialog. If a dialog is created without any button being the cancel button then the user will only be able to exit the dialog by restarting the session or pressing one of the buttons.

interaction_id will be sent as the event data with a button press event, to track from which dialog the button press came. As when multiple dialogs are opened they will stack and it will become difficult to track what button on which dialog was pressed without having multiple event handlers.

Waiting on BeamMP/BeamMP#715 to be merged.


By creating this pull request, I understand that code that is AI generated or otherwise automatically generated may be rejected without further discussion.
I declare that I fully understand all code I pushed into this PR, and wrote all this code myself and own the rights to this code.

Copy link
Collaborator

@SaltySnail SaltySnail left a comment

Choose a reason for hiding this comment

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

Cool feature, lgtm. Be sure to add the example code to the docs so people know how the format the packet

@WiserTixx WiserTixx requested a review from SaltySnail June 25, 2025 12:23
Copy link
Collaborator

@SaltySnail SaltySnail left a comment

Choose a reason for hiding this comment

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

lgtm

WiserTixx added a commit to BeamMP/BeamMP that referenced this pull request Jun 26, 2025
# Dialog packet


![image](https://github.com/user-attachments/assets/cc3ce7c0-0a4e-4df3-b050-1e48d48a04c8)

![image](https://github.com/user-attachments/assets/eba3aa62-d49f-4563-b6ef-5fa5b7d4c5ad)

This PR adds a new `D`ialog packet which takes json information to open
BeamNG's confirmation dialog.
HTML can be used to format the body and there are 2 styles available,
`experimental` (warning) ` and ` (none/default).

Server side PR BeamMP/BeamMP-Server#427
@WiserTixx WiserTixx merged commit add0b86 into minor Jun 26, 2025
9 checks passed
@WiserTixx WiserTixx deleted the lua-dialog branch June 26, 2025 04:52
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