14.11.2010, 02:28
(
Последний раз редактировалось TheXIII; 11.12.2010 в 11:29.
)
[Description]
also known as.. DOWNLOAD!
This simple include allows you to create more dynamic list-style dialogs, while keeping it just as simple to identify player chosen listitem under OnDialogResponse callback.[Functions]
This include only has three functions. Which are:[OnDialogResponse]
Quote:
AddDListItem(playerid, Item[], ItemID = -1, , ItemParameter = -1); ShowPlayerDList(playerid, DialogID, Caption[], Button1[], Button2[]);playerid - ID of player to who the list item should be assigned.
Item[] - The item to add.
ItemID - Manually assigned ID to the added item. Pretty much the same as dialogid in
ItemParameter - With this you can easily pass extra parameters, such as player or vehicle IDs (Added in v1.1)
ShowPlayerDialog. -1 by default.Clear_DList(playerid);(Added in v1.2)playerid The ID of the player to show the dialog to.
DialogID - An ID to assign this dialog to, so responses can be processed. Max dialogid is 32767. Using negative values will close any open dialog.
Caption[] - The title at the top of the dialog.
Button1[] - The text on the left button.
Button2[] - The text on the right button.playerid - ID of a player whos list variables you want to clear.
This function should not be needed. However, it does exist, so you can manually clean up the dynamic list variables of a player. You could use it under OnPlayerDialogResponse, or OnPlayerDisconnect etc. to remove bugs.
How to use the item ID and item parameter?[Installing]
Well, there are two extra variables, called DLItemID, and DLParam, which you can use like any other integer variable. Look at the Sample Usage.
Just add it as any include. Except..[Sample Usage]
pawn Код:#define DLD_STRING_SIZE 256 // Optional. Change if your DLists can be longer as 256 characters total. If not defined defaults to 256
#define DLD_MAX_LIST_ITEMS 10 // Optional. Change if you need more than 10 list items. If not defined defaults to 10
#include <DLDiag>
[Include itself]pawn Код:enum
{
DLITEM_PM,
DLITEM_KICK,
DLITEM_BAN,
DLITEM_GIVEMONEY
}
// This enum is not required. ItemID can be regular integer, like 1 or 126.
// But this way you can keep things nicely organized :)
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
// I know this looks kinda messy, but I just wanted to show some possibilities.
AddDListItem(playerid, "Personal Message", DLITEM_PM, clickedplayerid);
if( IsPlayerAdmin(playerid) ) AddDListItem(playerid, "Kick", DLITEM_KICK, clickedplayerid);
if( IsPlayerAdmin(playerid) ) Function2(playerid, clickedplayerid);
AddDListItem(playerid, "Give Money", DLITEM_GIVEMONEY, clickedplayerid);
AddDListItem(playerid, "Close");
ShowPlayerDlist(playerid, 1, "Example of Dynamic List Dialog", "Cool", "Close");
return true;
}
public Function2(playerid, ExtraParam)
{
return AddDListItem(playerid, "Ban", DLITEM_BAN, ExtraParam);
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch( dialogid )
{
case 1:
{
switch( DLItemID )
{
case DLITEM_PM:
{
// Do Stuff
}
case DLITEM_BAN: Ban(DLParam);
case DLITEM_KICK: Kick(DLParam);
case DLITEM_GIVEMONEY: // Do Oter Stuff
}
}
}
}
also known as.. DOWNLOAD!
Since it's really short include I will simply post it right here.[Changelog]
Still, if you find it easier to drag a file to your include folders from archive, instead of creating a new file, a and copy-pasting content to it, like me. I have also uploaded it.
[SolidFiles]
pawn Код:/*
_____ _ _____ _
| __ \| | | __ \(_)
| | | | | | | | |_ __ _ __ _
| | | | | | | | | |/ _` |/ _` |
| |__| | |____| |__| | | (_| | (_| |
|_____/|______|_____/|_|\__,_|\__, |
DynamicListDialog (v1.2) __/ |
ByTheXIII |___/
*/
/*=====================================
native AddDListItem(playerid, Item[], ItemID = -1, ItemParam = -1);
native ShowPlayerDList(playerid, DialogID, Caption[], Button1[], Button2[]);
native Clear_DList(playerid);
=====================================*/
#if defined _DLDiag_included
#endinput
#endif
#define _DLDiag_included
#if !defined _samp_included
#error "<a_samp> must be included before <DLDiag>"
#endif
#if !defined DLD_STRING_SIZE
#define DLD_STRING_SIZE 256
#endif
#if !defined DLD_MAX_LIST_ITEMS
#define DLD_MAX_LIST_ITEMS 10
#endif
#define DLItemID DLDPlayerListItems[playerid][listitem]
#define DLParam DLDPlayerListParam[playerid][listitem]
new DLDString[DLD_STRING_SIZE];
new DLDPlayerListItems[MAX_PLAYERS][DLD_MAX_LIST_ITEMS];
new DLDPlayerListParam[MAX_PLAYERS][DLD_MAX_LIST_ITEMS];
new DLDLastIS;
stock AddDListItem(playerid, ItemStr[DLD_STRING_SIZE], ItemID = -1, ItemParam = -1)
{
DLDPlayerListItems[playerid][DLDLastIS] = ItemID;
DLDPlayerListParam[playerid][DLDLastIS] = ItemParam;
if( !DLDLastIS ){DLDString = ""; format(DLDString, sizeof(DLDString), "%s", ItemStr);}
else format(DLDString, sizeof(DLDString), "%s\r\n%s", DLDString, ItemStr);
DLDLastIS++;
return DLDLastIS -1;
}
stock ShowPlayerDList(playerid, DialogID, Caption[], Button1[], Button2[])
{
DLDLastIS = 0;
ShowPlayerDialog(playerid, DialogID, DIALOG_STYLE_LIST, Caption, DLDString, Button1, Button2);
DLDString = "";
return true;
}
stock Clear_DList(playerid)
{
for( new i; i < DLD_MAX_LIST_ITEMS; i++ )
{
DLDPlayerListItems[playerid][i] = 0;
DLDPlayerListParam[playerid][i] = 0;
}
return true;
}
v1.0
Release.
v1.1
Added extra parameter.
v1.2
Added Clear_DList function. + automatic string clearing to avoid possible bugs.