mtasa-resources
mtasa-resources copied to clipboard
Dialogs
Description
This pull request was created to replace the existing msgbox resource. (Successor of #464)
Tasks
- [x] ~~Add new resource~~
- [x] ~~Add documentation~~
- [x] ~~Add deprecated warning to the old 'msgbox' resource~~
- [x] ~~Replace old syntax in resources~~
Preview
Functions
MessageBeep
Description
This function plays a sound from the messageSounds table.
Syntax
messageBeep( string soundType, [ int soundVolume ] )
Example
This example plays an info sound with the default volume (1)
messageBeep("INFO")
This example plays a question sound with specified volume (0.5)
messageBeep("QUESTION", 0.5)
Arguments
- soundType: A string specifying the sound data, which is in the messageSounds table.
- soundVolume: An integer between 1 and 0 that specifies the volume. (optional)
Returns
Returns the sound element.
MessageBox
Description
This function creates a dialog box with a callback function.
Syntax
messageBox( string messageTitle, string messageContent, string messageCallback, [ string messageIcon, string messageButton, int messageButtonDefault, string messageSound, int messageSoundVolume] )
Example
This example creates a dialog containing an information.
messageBox("Welcome", "Multi Theft Auto provides the best online Grand Theft Auto experience there is.", "callbackFunction", "INFO", "OK")
function callbackFunction(callbackResult)
if callbackResult == "OK" then
print("Read")
end
end
This example creates a dialog containing a question.
messageBox("Save", "Are you sure you want to save your changes? This action will overwrite your previous saves.", "callbackFunction", "QUESTION", "YESNOCANCEL")
function callbackFunction(callbackResult)
if callbackResult == "YES" then
print("Save")
elseif callbackResult == "NO" then
print("Undo")
else
print("Cancel")
end
end
This example creates a dialog containing a warning.
messageBox("Mismatch", "The selected file does not exist. Would you like to try the download again?", "callbackFunction", "WARNING", "ABORTRETRYIGNORE")
function callbackFunction(callbackResult)
if callbackResult == "ABORT" then
print("Abort")
elseif callbackResult == "RETRY" then
print("Retry")
else
print("Ignore")
end
end
This example creates a dialog containing an error.
messageBox("Your wallet is empty", "You do not have enough money to purchase the selected vehicle.", "callbackFunction", "ERROR", "OK")
function callbackFunction(callbackResult)
if callbackResult == "OK" then
print("Read")
end
end
Arguments
- messageTitle: A string specifing the title of the message (note that it will be always uppercase)
- messageContent: A string specifing the content of the message
- messageCallback: A string specifying the name of the function that will be exported when a button is pressed. (Note that you must specify the function name as a string and specify the function as exportable in the meta.xml of the source.)
- messageIcon: A string specifing the icon of the message, which is in the messageIcons table.
- messageButton: A string specifing the button(s) of the message, which is in the messageButtons table.
- messageButtonDefault: An integer specifing the default button (note that it will receive a bolder font)
- messageSound: A string specifing the sound of the message, which is in the messageSounds table.
- messageSoundVolume: An integer between 1 and 0 specifing the volume of the sound.
Returns
This function does not contain returns because it uses a callback function.
MessageBoxEx
Description
This function creates a dialog box without a callback function.
Syntax
messageBoxEx( string messageTitle, string messageContent, [ string messageIcon, string messageButton, int messageButtonDefault, string messageSound, int messageSoundVolume] )
Example
This example creates a dialog containing an information.
local buttonOK = messageBoxEx("Welcome", "Multi Theft Auto provides the best online Grand Theft Auto experience there is.", "INFO", "OK")
addEventHandler("onClientGUIClick", buttonOK,
function()
print("Read")
end
)
This example creates a dialog containing a question.
local buttonYes, buttonNo, buttonCancel = messageBoxEx("Save", "Are you sure you want to save your changes? This action will overwrite your previous saves.", "QUESTION", "YESNOCANCEL")
addEventHandler("onClientGUIClick", buttonYes,
function()
print("Save")
end
)
addEventHandler("onClientGUIClick", buttonNo,
function()
print("Undo")
end
)
addEventHandler("onClientGUIClick", buttonCancel,
function()
print("Cancel")
end
)
This example creates a dialog containing a warning.
local buttonAbort, buttonRetry, buttonIgnore = messageBoxEx("Save", "Are you sure you want to save your changes? This action will overwrite your previous saves.", "QUESTION", "YESNOCANCEL")
addEventHandler("onClientGUIClick", buttonAbort,
function()
print("Abort")
end
)
addEventHandler("onClientGUIClick", buttonRetry,
function()
print("Retry")
end
)
addEventHandler("onClientGUIClick", buttonIgnore,
function()
print("Ignore")
end
)
This example creates a dialog containing an error.
local buttonOK = messageBoxEx("Your wallet is empty", "You do not have enough money to purchase the selected vehicle.", "ERROR", "OK")
addEventHandler("onClientGUIClick", buttonOK,
function()
print("Read")
end
)
Arguments
- messageTitle: A string specifing the title of the message (note that it will be always uppercase)
- messageContent: A string specifing the content of the message
- messageIcon: A string specifing the icon of the message, which is in the messageIcons table.
- messageButton: A string specifing the button(s) of the message, which is in the messageButtons table.
- messageButtonDefault: An integer specifing the default button (note that it will receive a bolder font)
- messageSound: A string specifing the sound of the message, which is in the messageSounds table.
- messageSoundVolume: An integer between 1 and 0 specifing the volume of the sound.
Returns
Returns as many buttons in order as specified in the messageButton argument.
If nobody else has comments after a week or two I'll just send it.