警告
此回调是在 SA-MP 0.3a 中添加的,在早期版本中不起作用!
描述
当玩家通过单击按钮、按 ENTER/ESC 或双击列表项(如果使用列表样式对话框)响应使用 ShowPlayerDialog 显示的对话框时,将调用此回调。
| 名字 |
描述 |
| playerid |
响应对话的玩家的 ID。 |
| dialogid |
玩家响应的对话的 ID,在 ShowPlayerDialog 中分配。 |
| response |
1 表示左键,0 表示右键(如果只显示一个按钮,则始终为 1) |
| listitem |
玩家选择的列表项的 ID(从 0 开始)(仅当使用列表样式对话框时,否则将为 -1)。 |
| inputtext[] |
玩家在输入框中输入的文本或选定的列表项文本。 |
返回
它总是在 filterscripts 中首先调用,因此返回 1 会阻止其他 filterscript 看到它。
例子
// Define the dialog ID so we can handle responses#define DIALOG_RULES 1// In some commandShowPlayerDialog(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");public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){ if (dialogid == DIALOG_RULES) { if (response) // If they clicked 'Yes' or pressed enter { SendClientMessage(playerid, COLOR_GREEN, "Thank you for agreeing to the server rules!"); } else // Pressed ESC or clicked cancel { Kick(playerid); } return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText. } return 0; // You MUST return 0 here! Just like OnPlayerCommandText.}#define DIALOG_LOGIN 2// In some commandShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please enter your password:", "Login", "Cancel");public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){ if (dialogid == DIALOG_LOGIN) { if (!response) // If they clicked 'Cancel' or pressed esc { Kick(playerid); } else // Pressed ENTER or clicked 'Login' button { if (CheckPassword(playerid, inputtext)) { SendClientMessage(playerid, COLOR_RED, "You are now logged in!"); } else { SendClientMessage(playerid, COLOR_RED, "LOGIN FAILED."); // Re-show the login dialog ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", "Please enter your password:", "Login", "Cancel"); } } return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText. } return 0; // You MUST return 0 here! Just like OnPlayerCommandText.}#define DIALOG_WEAPONS 3// In some commandShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "Weapons", "Desert Eagle\nAK-47\nCombat Shotgun", "Select", "Close");public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){ if (dialogid == DIALOG_WEAPONS) { if (response) // If they clicked 'Select' or double-clicked a weapon { // Give them the weapon switch(listitem) { case 0: GivePlayerWeapon(playerid, WEAPON_DEAGLE, 14); // Give them a desert eagle case 1: GivePlayerWeapon(playerid, WEAPON_AK47, 120); // Give them an AK-47 case 2: GivePlayerWeapon(playerid, WEAPON_SHOTGSPA, 28); // Give them a Combat Shotgun } } return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText. } return 0; // You MUST return 0 here! Just like OnPlayerCommandText.}#define DIALOG_WEAPONS 3// In some commandShowPlayerDialog(playerid, DIALOG_WEAPONS, DIALOG_STYLE_LIST, "Weapons","Weapon\tAmmo\tPrice\n\M4\t120\t500\n\MP5\t90\t350\n\AK-47\t120\t400","Select", "Close");public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]){ if (dialogid == DIALOG_WEAPONS) { if (response) // If they clicked 'Select' or double-clicked a weapon { // Give them the weapon switch(listitem) { case 0: GivePlayerWeapon(playerid, WEAPON_M4, 120); // Give them an M4 case 1: GivePlayerWeapon(playerid, WEAPON_MP5, 90); // Give them an MP5 case 2: GivePlayerWeapon(playerid, WEAPON_AK47, 120); // Give them an AK-47 } } return 1; // We handled a dialog, so return 1. Just like OnPlayerCommandText. } return 0; // You MUST return 0 here! Just like OnPlayerCommandText.}
笔记
提示
根据对话框的样式,参数可以包含不同的值(单击查看更多示例)。
提示
如果有多个对话框 ID,则可以通过不同的对话框 ID 进行切换。
警告
当游戏模式重新启动时,玩家的对话框不会隐藏,如果玩家在重新启动后响应此对话框,则会导致服务器打印“Warning: PlayerDialogResponse PlayerId: 0 dialog ID doesn’t match last sent dialog ID”。