警告
此回调是在 SA-MP 0.3a 中添加的,在早期版本中不起作用!

描述

当玩家通过单击按钮、按 ENTER/ESC 或双击列表项(如果使用列表样式对话框)响应使用 ShowPlayerDialog 显示的对话框时,将调用此回调。
名字 描述
playerid 响应对话的玩家的 ID。
dialogid 玩家响应的对话的 ID,在 ShowPlayerDialog 中分配。
response 1 表示左键,0 表示右键(如果只显示一个按钮,则始终为 1)
listitem 玩家选择的列表项的 ID(从 0 开始)(仅当使用列表样式对话框时,否则将为 -1)。
inputtext[] 玩家在输入框中输入的文本或选定的列表项文本。

返回

它总是在 filterscripts 中首先调用,因此返回 1 会阻止其他 filterscript 看到它。

例子

  1. // Define the dialog ID so we can handle responses
  2. #define DIALOG_RULES 1
  3. // In some command
  4. ShowPlayerDialog(playerid, DIALOG_RULES, DIALOG_STYLE_MSGBOX, "Server Rules", "- No Cheating\n- No Spamming\n- Respect Admins\n\nDo you agree to these rules?", "Yes", "No");
  5. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  6. {
  7. if (dialogid == DIALOG_RULES)
  8. {
  9. if (response) // If they clicked 'Yes' or pressed enter
  10. {
  11. SendClientMessage(playerid, COLOR_GREEN, "Thank you for agreeing to the server rules!");
  12. }
  13. else // Pressed ESC or clicked cancel
  14. {
  15. Kick(playerid);
  16. }
  17. return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
  18. }
  19. return 0; // You MUST return 0 here! Just like OnPlayerCommandText.
  20. }
  21. #define DIALOG_LOGIN 2
  22. // In some command
  23. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please enter your password:", "Login", "Cancel");
  24. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  25. {
  26. if (dialogid == DIALOG_LOGIN)
  27. {
  28. if (!response) // If they clicked 'Cancel' or pressed esc
  29. {
  30. Kick(playerid);
  31. }
  32. else // Pressed ENTER or clicked 'Login' button
  33. {
  34. if (CheckPassword(playerid, inputtext))
  35. {
  36. SendClientMessage(playerid, COLOR_RED, "You are now logged in!");
  37. }
  38. else
  39. {
  40. SendClientMessage(playerid, COLOR_RED, "LOGIN FAILED.");
  41. // Re-show the login dialog
  42. ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please enter your password:", "Login", "Cancel");
  43. }
  44. }
  45. return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
  46. }
  47. return 0; // You MUST return 0 here! Just like OnPlayerCommandText.
  48. }
  49. #define DIALOG_WEAPONS 3
  50. // In some command
  51. ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "Weapons", "Desert Eagle\nAK-47\nCombat Shotgun", "Select", "Close");
  52. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  53. {
  54. if (dialogid == DIALOG_WEAPONS)
  55. {
  56. if (response) // If they clicked 'Select' or double-clicked a weapon
  57. {
  58. // Give them the weapon
  59. switch(listitem)
  60. {
  61. case 0: GivePlayerWeapon(playerid, WEAPON_DEAGLE, 14); // Give them a desert eagle
  62. case 1: GivePlayerWeapon(playerid, WEAPON_AK47, 120); // Give them an AK-47
  63. case 2: GivePlayerWeapon(playerid, WEAPON_SHOTGSPA, 28); // Give them a Combat Shotgun
  64. }
  65. }
  66. return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
  67. }
  68. return 0; // You MUST return 0 here! Just like OnPlayerCommandText.
  69. }
  70. #define DIALOG_WEAPONS 3
  71. // In some command
  72. ShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "Weapons",
  73. "Weapon\tAmmo\tPrice\n\
  74. M4\t120\t500\n\
  75. MP5\t90\t350\n\
  76. AK-47\t120\t400",
  77. "Select", "Close");
  78. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  79. {
  80. if (dialogid == DIALOG_WEAPONS)
  81. {
  82. if (response) // If they clicked 'Select' or double-clicked a weapon
  83. {
  84. // Give them the weapon
  85. switch(listitem)
  86. {
  87. case 0: GivePlayerWeapon(playerid, WEAPON_M4, 120); // Give them an M4
  88. case 1: GivePlayerWeapon(playerid, WEAPON_MP5, 90); // Give them an MP5
  89. case 2: GivePlayerWeapon(playerid, WEAPON_AK47, 120); // Give them an AK-47
  90. }
  91. }
  92. return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText.
  93. }
  94. return 0; // You MUST return 0 here! Just like OnPlayerCommandText.
  95. }

笔记

提示
根据对话框的样式,参数可以包含不同的值(单击查看更多示例)。
提示
如果有多个对话框 ID,则可以通过不同的对话框 ID 进行切换。
警告
当游戏模式重新启动时,玩家的对话框不会隐藏,如果玩家在重新启动后响应此对话框,则会导致服务器打印“Warning: PlayerDialogResponse PlayerId: 0 dialog ID doesn’t match last sent dialog ID”。