Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- XMenu by Bondowocopz(X337)
- Example code :
- ShowPlayerMenu(playerid, Menu1, "XMenu Title", "Option 1\nOption 2\nOption 3", "XMenu Example");
- Response :
- Menu:Menu1(playerid, listitem)
- {
- switch(listitem)
- {
- case 0:
- {
- SendClientMessage(playerid, -1, "You've choosed option 1");
- }
- case 1:
- {
- SendClientMessage(playerid, -1, "You've choosed option 2");
- }
- case 2:
- {
- SendClientMessage(playerid, -1, "You've choosed option 3");
- }
- }
- }
- Credits:
- - SA-MP Team - a_samp
- - Slice - strlib
- */
- #define MAX_MENU_ITEM_TEXT 64
- #define Menu:%0(%1) \
- forward tdmenu_%0(%1); public tdmenu_%0(%1)
- #define ShowPlayerMenu(%0,%1, \
- __ShowMenu(%0, #%1,
- stock x_isnumeric(str[])
- {
- new
- ch,
- i;
- while ((ch = str[i++])) if (!('0' <= ch <= '9')) return 0;
- return 1;
- }
- stock bool:x_isempty(const string[]) {
- if (ispacked(string))
- return string{0} == '\0';
- else
- return string[0] == '\0';
- }
- stock x_strexplode(output[][], const input[], const delimiter[] = !",", limit = cellmax, bool:trim = true, bool:ignorecase = false, size1 = sizeof(output), size2 = sizeof(output[])) {
- if (!size1 || !size2) {
- printf("(x_strexplode) ERROR: size1 = %d, size2 = %d. Can't be 0.", size1, size2);
- return 0;
- }
- if (x_isempty(delimiter)) {
- print(!"(x_strexplode) ERROR: delimiter is empty.");
- return 0;
- }
- if (trim) {
- new i = -1;
- if (ispacked(input)) {
- while (input{++i}) {
- if (input{i} > ' ') {
- i = -1;
- break;
- }
- }
- } else {
- while (input[++i]) {
- if (input[i] > ' ') {
- i = -1;
- break;
- }
- }
- }
- if (i != -1)
- return 0;
- } else if (x_isempty(input)) {
- return 0;
- }
- if (limit == 0) {
- return 0;
- } else if (limit == cellmax) {
- limit = 0;
- }
- new
- pos = 0,
- next,
- bool:packed = ispacked(input),
- dlen = strlen(delimiter),
- count = 0,
- end
- ;
- while (pos != -1) {
- ++count;
- if (limit > 0 && count >= limit) {
- next = -1;
- } else {
- next = strfind(input, delimiter, ignorecase, pos);
- }
- end = (next == -1) ? cellmax : next;
- if (trim) {
- if (end == cellmax)
- end = strlen(input);
- if (packed) {
- while (0 < input{pos} <= ' ') pos++;
- while (end > 0 && input{end - 1} <= ' ') end--;
- } else {
- while (0 < input[pos] <= ' ') pos++;
- while (end > 0 && input[end - 1] <= ' ') end--;
- }
- }
- strmid(output[count - 1], input, pos, end, size2);
- if (count >= size1 || next == -1 || (limit < 0 && count >= -limit))
- break;
- pos = next + dlen;
- }
- return count;
- }
- static
- Text:tdmnu_MenuTextdrawBG,
- PlayerText:tdmnu_MenuTextdrawTitle[MAX_PLAYERS],
- PlayerText:tdmnu_MenuTextdrawDesc[MAX_PLAYERS],
- PlayerText:tdmnu_MenuTextdrawOpts[MAX_PLAYERS],
- PlayerText:tdmnu_MenuTextdrawClose[MAX_PLAYERS],
- tdmnu_MenuFunction[MAX_PLAYERS][32 char],
- bool:tdmnu_MenuOpened[MAX_PLAYERS],
- tdmnu_TotalOpts[MAX_PLAYERS]
- ;
- #if !defined isnull
- #define isnull(%1) \
- ((%1[0] == 0) || (%1[0] == 1 && %1[1] == 0))
- #endif
- public OnGameModeInit()
- {
- tdmnu_MenuTextdrawBG = TextDrawCreate(26.525003, 147.573745, "box");
- TextDrawLetterSize(tdmnu_MenuTextdrawBG, 0.000000, 18.312500);
- TextDrawTextSize(tdmnu_MenuTextdrawBG, 147.000000, 0.000000);
- TextDrawAlignment(tdmnu_MenuTextdrawBG, 1);
- TextDrawColor(tdmnu_MenuTextdrawBG, -1);
- TextDrawUseBox(tdmnu_MenuTextdrawBG, 1);
- TextDrawBoxColor(tdmnu_MenuTextdrawBG, 144);
- TextDrawSetShadow(tdmnu_MenuTextdrawBG, 0);
- TextDrawSetOutline(tdmnu_MenuTextdrawBG, 0);
- TextDrawBackgroundColor(tdmnu_MenuTextdrawBG, 255);
- TextDrawFont(tdmnu_MenuTextdrawBG, 1);
- TextDrawSetProportional(tdmnu_MenuTextdrawBG, 1);
- TextDrawSetShadow(tdmnu_MenuTextdrawBG, 0);
- #if defined Tdmnu_OnGameModeInit
- return Tdmnu_OnGameModeInit();
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- #define OnGameModeInit Tdmnu_OnGameModeInit
- #if defined Tdmnu_OnGameModeInit
- forward Tdmnu_OnGameModeInit();
- #endif
- public OnPlayerConnect(playerid)
- {
- tdmnu_MenuTextdrawTitle[playerid] = CreatePlayerTextDraw(playerid, 83.974967, 147.486572, "AMMUNATION");
- PlayerTextDrawLetterSize(playerid, tdmnu_MenuTextdrawTitle[playerid], 0.303750, 1.502933);
- PlayerTextDrawAlignment(playerid, tdmnu_MenuTextdrawTitle[playerid], 2);
- PlayerTextDrawColor(playerid, tdmnu_MenuTextdrawTitle[playerid], -1);
- PlayerTextDrawSetShadow(playerid, tdmnu_MenuTextdrawTitle[playerid], 0);
- PlayerTextDrawSetOutline(playerid, tdmnu_MenuTextdrawTitle[playerid], 0);
- PlayerTextDrawBackgroundColor(playerid, tdmnu_MenuTextdrawTitle[playerid], 255);
- PlayerTextDrawFont(playerid, tdmnu_MenuTextdrawTitle[playerid], 2);
- PlayerTextDrawSetProportional(playerid, tdmnu_MenuTextdrawTitle[playerid], 1);
- PlayerTextDrawSetShadow(playerid, tdmnu_MenuTextdrawTitle[playerid], 0);
- tdmnu_MenuTextdrawDesc[playerid] = CreatePlayerTextDraw(playerid, 86.949989, 165.860000, "Lorem ipsum dolor sit amet conclusion snis");
- PlayerTextDrawLetterSize(playerid, tdmnu_MenuTextdrawDesc[playerid], 0.169999, 1.039999);
- PlayerTextDrawTextSize(playerid, tdmnu_MenuTextdrawDesc[playerid], 0.000000, 119.070014);
- PlayerTextDrawAlignment(playerid, tdmnu_MenuTextdrawDesc[playerid], 2);
- PlayerTextDrawColor(playerid, tdmnu_MenuTextdrawDesc[playerid], -1061109505);
- PlayerTextDrawUseBox(playerid, tdmnu_MenuTextdrawDesc[playerid], 1);
- PlayerTextDrawBoxColor(playerid, tdmnu_MenuTextdrawDesc[playerid], 255);
- PlayerTextDrawSetShadow(playerid, tdmnu_MenuTextdrawDesc[playerid], 0);
- PlayerTextDrawSetOutline(playerid, tdmnu_MenuTextdrawDesc[playerid], 0);
- PlayerTextDrawBackgroundColor(playerid, tdmnu_MenuTextdrawDesc[playerid], 255);
- PlayerTextDrawFont(playerid, tdmnu_MenuTextdrawDesc[playerid], 1);
- PlayerTextDrawSetProportional(playerid, tdmnu_MenuTextdrawDesc[playerid], 1);
- PlayerTextDrawSetShadow(playerid, tdmnu_MenuTextdrawDesc[playerid], 0);
- tdmnu_MenuTextdrawOpts[playerid] = CreatePlayerTextDraw(playerid, 30.300010, 180.346633, "1. Option 1~n~2. Option 2~n~3. Option 3~n~4. Option 4~n~5. Option 5~n~6. Option 6~n~7. Option 7~n~8. Option 8~n~9. Option 9~n~1");
- PlayerTextDrawLetterSize(playerid, tdmnu_MenuTextdrawOpts[playerid], 0.211245, 1.002665);
- PlayerTextDrawTextSize(playerid, tdmnu_MenuTextdrawOpts[playerid], 146.000000, 0.000000);
- PlayerTextDrawAlignment(playerid, tdmnu_MenuTextdrawOpts[playerid], 1);
- PlayerTextDrawColor(playerid, tdmnu_MenuTextdrawOpts[playerid], -5963521);
- PlayerTextDrawUseBox(playerid, tdmnu_MenuTextdrawOpts[playerid], 1);
- PlayerTextDrawBoxColor(playerid, tdmnu_MenuTextdrawOpts[playerid], 0);
- PlayerTextDrawSetShadow(playerid, tdmnu_MenuTextdrawOpts[playerid], 0);
- PlayerTextDrawSetOutline(playerid, tdmnu_MenuTextdrawOpts[playerid], 0);
- PlayerTextDrawBackgroundColor(playerid, tdmnu_MenuTextdrawOpts[playerid], 255);
- PlayerTextDrawFont(playerid, tdmnu_MenuTextdrawOpts[playerid], 1);
- PlayerTextDrawSetProportional(playerid, tdmnu_MenuTextdrawOpts[playerid], 1);
- PlayerTextDrawSetShadow(playerid, tdmnu_MenuTextdrawOpts[playerid], 0);
- tdmnu_MenuTextdrawClose[playerid] = CreatePlayerTextDraw(playerid, 86.624984, 298.667541, "Press (~b~T~w~) or (~b~F6~w~) to enter number~n~Press (~b~CAPSLOCK~w~) to close");
- PlayerTextDrawLetterSize(playerid, tdmnu_MenuTextdrawClose[playerid], 0.195695, 1.129464);
- PlayerTextDrawTextSize(playerid, tdmnu_MenuTextdrawClose[playerid], 0.000000, 119.890190);
- PlayerTextDrawAlignment(playerid, tdmnu_MenuTextdrawClose[playerid], 2);
- PlayerTextDrawColor(playerid, tdmnu_MenuTextdrawClose[playerid], -1);
- PlayerTextDrawUseBox(playerid, tdmnu_MenuTextdrawClose[playerid], 1);
- PlayerTextDrawBoxColor(playerid, tdmnu_MenuTextdrawClose[playerid], 255);
- PlayerTextDrawSetShadow(playerid, tdmnu_MenuTextdrawClose[playerid], 0);
- PlayerTextDrawSetOutline(playerid, tdmnu_MenuTextdrawClose[playerid], 0);
- PlayerTextDrawBackgroundColor(playerid, tdmnu_MenuTextdrawClose[playerid], 255);
- PlayerTextDrawFont(playerid, tdmnu_MenuTextdrawClose[playerid], 1);
- PlayerTextDrawSetProportional(playerid, tdmnu_MenuTextdrawClose[playerid], 1);
- PlayerTextDrawSetShadow(playerid, tdmnu_MenuTextdrawClose[playerid], 0);
- tdmnu_MenuOpened[playerid] = false;
- #if defined Tdmnu_OnPlayerConnect
- return Tdmnu_OnPlayerConnect(playerid);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect Tdmnu_OnPlayerConnect
- #if defined Tdmnu_OnPlayerConnect
- forward Tdmnu_OnPlayerConnect(playerid);
- #endif
- stock __ShowMenu(playerid, function[], title[], options[], desc[] = "")
- {
- new
- items[10][MAX_MENU_ITEM_TEXT],
- len = 10 * MAX_MENU_ITEM_TEXT,
- text[10 * MAX_MENU_ITEM_TEXT],
- total
- ;
- x_strexplode(items, options, "\n");
- for(new i = 0; i < 10; i++)
- {
- if(isnull(items[i]))
- continue;
- format(text, len, "%s~n~~y~%d. ~w~%s", text, i + 1, items[i]);
- total++;
- }
- if(!IsPlayerInAnyVehicle(playerid))
- PlayerTextDrawSetString(playerid, tdmnu_MenuTextdrawClose[playerid], "Press ~b~T~w~ or ~b~F6~w~ to enter number~n~Press ~b~LMB~w~ to close");
- else
- PlayerTextDrawSetString(playerid, tdmnu_MenuTextdrawClose[playerid], "Press ~b~T~w~ or ~b~F6~w~ to enter number~n~Press ~b~~k~~VEHICLE_HORN~~w~ to close");
- if(strlen(desc) < 3)
- format(desc, 18, "(No Description)");
- PlayerTextDrawSetString(playerid, tdmnu_MenuTextdrawOpts[playerid], text);
- PlayerTextDrawSetString(playerid, tdmnu_MenuTextdrawDesc[playerid], desc);
- PlayerTextDrawSetString(playerid, tdmnu_MenuTextdrawTitle[playerid], title);
- TextDrawShowForPlayer(playerid, tdmnu_MenuTextdrawBG);
- PlayerTextDrawShow(playerid, tdmnu_MenuTextdrawTitle[playerid]);
- PlayerTextDrawShow(playerid, tdmnu_MenuTextdrawOpts[playerid]);
- PlayerTextDrawShow(playerid, tdmnu_MenuTextdrawDesc[playerid]);
- PlayerTextDrawShow(playerid, tdmnu_MenuTextdrawClose[playerid]);
- strpack(tdmnu_MenuFunction[playerid], function, 32 char);
- tdmnu_MenuOpened[playerid] = true;
- tdmnu_TotalOpts[playerid] = ++total;
- return 1;
- }
- stock HidePlayerMenu(playerid)
- {
- TextDrawHideForPlayer(playerid, tdmnu_MenuTextdrawBG);
- PlayerTextDrawHide(playerid, tdmnu_MenuTextdrawTitle[playerid]);
- PlayerTextDrawHide(playerid, tdmnu_MenuTextdrawOpts[playerid]);
- PlayerTextDrawHide(playerid, tdmnu_MenuTextdrawDesc[playerid]);
- PlayerTextDrawHide(playerid, tdmnu_MenuTextdrawClose[playerid]);
- tdmnu_MenuOpened[playerid] = false;
- }
- stock IsMenuOpened(playerid)
- {
- return tdmnu_MenuOpened[playerid];
- }
- public OnPlayerText(playerid, text[])
- {
- if(tdmnu_MenuOpened[playerid])
- {
- if(x_isnumeric(text))
- {
- new option = strval(text);
- if(option > 0 && option <= tdmnu_TotalOpts[playerid])
- {
- new str[64];
- strcat(str, "tdmenu_");
- strcat(str, tdmnu_MenuFunction[playerid]);
- HidePlayerMenu(playerid);
- CallLocalFunction(str, "dd", playerid, option - 1);
- return 0;
- }
- }
- }
- #if defined tdmn_OnPlayerText
- return tdmn_OnPlayerText(playerid, text);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerText
- #undef OnPlayerText
- #else
- #define _ALS_OnPlayerText
- #endif
- #define OnPlayerText tdmn_OnPlayerText
- #if defined tdmn_OnPlayerText
- forward tdmn_OnPlayerText(playerid, text[]);
- #endif
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(tdmnu_MenuOpened[playerid])
- {
- new bool = IsPlayerInAnyVehicle(playerid);
- if((newkeys & KEY_FIRE && !bool) || (newkeys & KEY_CROUCH && bool))
- {
- HidePlayerMenu(playerid);
- return 0;
- }
- }
- #if defined Tdmnu_OnPlayerKeyStateChange
- return Tdmnu_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerKeyStateChange
- #undef OnPlayerKeyStateChange
- #else
- #define _ALS_OnPlayerKeyStateChange
- #endif
- #define OnPlayerKeyStateChange Tdmnu_OnPlayerKeyStateChange
- #if defined Tdmnu_OnPlayerKeyStateChange
- forward Tdmnu_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
- #endif
- public OnPlayerDeath(playerid, killerid, reason)
- {
- tdmnu_MenuOpened[playerid] = false;
- HidePlayerMenu(playerid);
- #if defined TDMenu_OnPlayerDeath
- return TDMenu_OnPlayerDeath(playerid, killerid, reason);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerDeath
- #undef OnPlayerDeath
- #else
- #define _ALS_OnPlayerDeath
- #endif
- #define OnPlayerDeath TDMenu_OnPlayerDeath
- #if defined TDMenu_OnPlayerDeath
- forward TDMenu_OnPlayerDeath(playerid, killerid, reason);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement