05.05.2013, 22:34
You can write all your dialog code into the function that uses it without a need for making dialogid defines and callback functions which is much better for keeping your code organized, as a matter of fact I would never even consider doing dialogs any other way.
Here is an example.
Don't you think that looks a lot better and makes more sense than traditional methods?
Here is an example.
pawn Код:
// Set gang name
CMD:gangname(playerid, arg[])
{
// Is player in a gang?
if(p_DATA[playerid][p_GangID] != 0)
{
// Is player leader ?
if(p_DATA[playerid][p_GangRank] == 1)
{
inline Response(pid, dialogid, response, listitem, string:text[])
{
#pragma unused listitem, dialogid, pid
if (response)
{
if(strlen(text) > 3 || strlen(text) <= 30)
{
new line[128];
format(line, sizeof(line), "%s gang is now known as %s", Gang_Name[p_DATA[playerid][p_GangSlot]], text);
SendClientMessageToAll(STEALTH_YELLOW, line);
format(Gang_Name[p_DATA[playerid][p_GangSlot]], 32, "%s", text);
// Save gang name to DB
SaveGangName(p_DATA[playerid][p_GangSlot]);
}
else
{
SendClientMessage(playerid, STEALTH_YELLOW, "Gang names must be more than 4 characters and no more than 30");
Dialog_ShowCallback(playerid, using inline Response, DIALOG_STYLE_INPUT, "Enter a name for your gang", "New Gang Name", "Ok", "Cancel");
}
}
}
Dialog_ShowCallback(playerid, using inline Response, DIALOG_STYLE_INPUT, "Enter a name for your gang", "New Gang Name", "Ok", "Cancel");
}
else SendClientMessage(playerid, STEALTH_YELLOW, "You must be gang leader to use this command.");
}
else SendClientMessage(playerid, STEALTH_YELLOW, "You are not a in a gang");
return 1;
}