Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Script Type: Include
- Script Name: Buttons Include
- Script Version: V1.1
- Script Author: SpiritEvil
- Script Description: Create Buttons using only ONE line of code!
- +++++++++++++++++++++++ | Cahgnge Log | +++++++++++++++++++++++
- + +
- + *V1.0 Initial Release +
- + =========================================================== +
- + *V1.1 Added GetButtonpos +
- + *V1.1 Added GetButtonSize +
- + *V1.1 Added GetButtonColors +
- + *V1.1 Added GetButtonText +
- + *V1.1 Hooked OnPlayerClickTextdraw +
- + (You will no longer need to add anything on your script) +
- + *V1.1 Makes usage of Global Textdraws instead of Player TDs +
- + *V1.1 Small bug fixes +
- + =========================================================== +
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- */
- /* Natives List:
- native Button:CreateButtonForPlayer(playerid, text[], Float:x, Float:y, Float:width = 72.0, Float:height = 23.0);
- native ShowButtonForPlayer(playerid, Button:btnid);
- native DestroyButton(Button:btnid);
- native DestroyButtonForPlayer(playerid, Button:btnid);
- native HideButtonForPlayer(playerid, Button:btnid);
- native SetButtonTextForPlayer(playerid, Button:btnid, text[]);
- native ChangeButtonColorsForPlayer(playerid, Button:btnid, strokeCol, buttonCol, textCol);
- native IsValidButton(Button:btnid);
- native UpdateButtonForPlayer(playerid, Button:btnid);
- native GetButtonPos(Button:btnid, &Float:x, &Float:y);
- native GetButtonSize(Button:btnid, &Float:width, &Float:height);
- native GetButtonColors(Button:btnid, &strokeCol, &buttonCol, &textCol);
- native GetButtonText(Button:btnid);
- */
- forward OnPlayerClickButton(playerid, Button:btnid);
- #include <a_samp>
- #define MAX_BUTTONS 100
- #define INVALID_BUTTON_ID (Button:-1)
- #define HOVER_COLOR 0x1696CCFF //Change this to the color you like! (default: 0x1696CCFF)
- enum buttonInfo
- {
- Float:btn_x,
- Float:btn_y,
- Float:btn_w,
- Float:btn_h,
- btn_txt[200],
- btn_col_stroke,
- btn_col_bg,
- btn_col_txt,
- bool:btn_created,
- };
- new Buttons[MAX_BUTTONS][buttonInfo];
- new Text:btn_td1[MAX_BUTTONS][MAX_PLAYERS],
- Text:btn_td2[MAX_BUTTONS][MAX_PLAYERS],
- Text:btn_td3[MAX_BUTTONS][MAX_PLAYERS];
- stock Button:CreateButtonForPlayer(playerid, text[], Float:x, Float:y, Float:width = 72.0, Float:height = 23.0)
- {
- new btnid;
- for(btnid = 0; btnid <= sizeof(Buttons); btnid++)
- if(!Buttons[btnid][btn_created]) break;
- if(Buttons[btnid][btn_created] || btnid == sizeof Buttons)
- return INVALID_BUTTON_ID;
- new Text:textdraw;
- textdraw = btn_td1[btnid][playerid] = TextDrawCreate(x, y, "_");
- TextDrawBackgroundColor(textdraw, 255);
- TextDrawFont(textdraw, 1);
- TextDrawLetterSize(textdraw, 0.500000, height / 10);
- TextDrawColor(textdraw, -1);
- TextDrawSetOutline(textdraw, 0);
- TextDrawSetProportional(textdraw, 1);
- TextDrawSetShadow(textdraw, 1);
- TextDrawUseBox(textdraw, 1);
- TextDrawBoxColor(textdraw, 255);
- TextDrawTextSize(textdraw, x + width, 0.000000);
- textdraw = btn_td2[btnid][playerid] = TextDrawCreate(x+2, y+3, "_");
- TextDrawBackgroundColor(textdraw, 255);
- TextDrawFont(textdraw, 1);
- TextDrawLetterSize(textdraw, 0.500000, height / 10 - 0.5);
- TextDrawColor(textdraw, -1);
- TextDrawSetOutline(textdraw, 0);
- TextDrawSetProportional(textdraw, 1);
- TextDrawSetShadow(textdraw, 1);
- TextDrawUseBox(textdraw, 1);
- TextDrawBoxColor(textdraw, -16776961);
- TextDrawTextSize(textdraw, x + width - 2, 0.000000);
- textdraw = btn_td3[btnid][playerid] = TextDrawCreate(x+8, y+3, text);
- TextDrawBackgroundColor(textdraw, 255);
- TextDrawFont(textdraw, 1);
- TextDrawLetterSize(textdraw, 0.5, height / 10 - 0.8);
- TextDrawColor(textdraw, -1);
- TextDrawSetOutline(textdraw, 1);
- TextDrawSetProportional(textdraw, 1);
- TextDrawUseBox(textdraw, 1);
- TextDrawBoxColor(textdraw, 0);
- TextDrawTextSize(textdraw, x + width - 1, height);
- TextDrawSetSelectable(textdraw, 1);
- Buttons[btnid][btn_x] = x;
- Buttons[btnid][btn_y] = y;
- Buttons[btnid][btn_h] = height;
- Buttons[btnid][btn_w] = width;
- format(Buttons[_:btnid][btn_txt], 200, "%s", text);
- Buttons[btnid][btn_col_stroke] = 255;
- Buttons[btnid][btn_col_bg] = -16776961;
- Buttons[btnid][btn_col_txt] = -1;
- Buttons[btnid][btn_created] = true;
- //printf("%i", _:btnid);
- return Button:btnid;
- }
- stock ShowButtonForPlayer(playerid, Button:btnid)
- {
- if(IsPlayerConnected(playerid))
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- TextDrawShowForPlayer(playerid, btn_td1[_:btnid][playerid]);
- TextDrawShowForPlayer(playerid, btn_td2[_:btnid][playerid]);
- TextDrawShowForPlayer(playerid, btn_td3[_:btnid][playerid]);
- SelectTextDraw(playerid, HOVER_COLOR);
- return 1;
- }
- return 0;
- }
- stock DestroyButton(Button:btnid)
- {
- for(new playerid = 0; playerid <= GetMaxPlayers(); playerid++)
- {
- if(IsPlayerConnected(playerid))
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- TextDrawDestroy(btn_td1[_:btnid][playerid]);
- TextDrawDestroy(btn_td2[_:btnid][playerid]);
- TextDrawDestroy(btn_td3[_:btnid][playerid]);
- Buttons[_:btnid][btn_created] = false;
- Buttons[_:btnid][btn_x] = -1;
- Buttons[_:btnid][btn_y] = -1;
- Buttons[_:btnid][btn_w] = -1;
- Buttons[_:btnid][btn_h] = -1;
- btn_td1[_:btnid][playerid] = Text:INVALID_TEXT_DRAW;
- btn_td2[_:btnid][playerid] = Text:INVALID_TEXT_DRAW;
- btn_td3[_:btnid][playerid] = Text:INVALID_TEXT_DRAW;
- Buttons[_:btnid][btn_col_stroke] = -1;
- Buttons[_:btnid][btn_col_bg] = -1;
- Buttons[_:btnid][btn_col_txt] = -1;
- return 1;
- }
- }
- }
- return 0;
- }
- stock DestroyButtonForPlayer(playerid, Button:btnid)
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- TextDrawDestroy(btn_td1[_:btnid][playerid]);
- TextDrawDestroy(btn_td2[_:btnid][playerid]);
- TextDrawDestroy(btn_td3[_:btnid][playerid]);
- Buttons[_:btnid][btn_created] = false;
- Buttons[_:btnid][btn_x] = -1;
- Buttons[_:btnid][btn_y] = -1;
- Buttons[_:btnid][btn_w] = -1;
- Buttons[_:btnid][btn_h] = -1;
- btn_td1[_:btnid][playerid] = Text:-1;
- btn_td2[_:btnid][playerid] = Text:-1;
- btn_td3[_:btnid][playerid] = Text:-1;
- Buttons[_:btnid][btn_col_stroke] = -1;
- Buttons[_:btnid][btn_col_bg] = -1;
- Buttons[_:btnid][btn_col_txt] = -1;
- //Buttons[btnid][btn_txt] = "_";
- return 1;
- }
- return 0;
- }
- stock HideButtonForPlayer(playerid, Button:btnid)
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- TextDrawHideForPlayer(playerid, btn_td1[_:btnid][playerid]);
- TextDrawHideForPlayer(playerid, btn_td2[_:btnid][playerid]);
- TextDrawHideForPlayer(playerid, btn_td3[_:btnid][playerid]);
- return 1;
- }
- return 0;
- }
- stock SetButtonTextForPlayer(playerid, Button:btnid, text[])
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- TextDrawSetString(btn_td3[_:btnid][playerid], text);
- format(Buttons[_:btnid][btn_txt], 200, "%s", text);
- return 1;
- }
- return 0;
- }
- stock ChangeButtonColorsForPlayer(playerid, Button:btnid, strokeCol, buttonCol, textCol)
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- Buttons[_:btnid][btn_col_stroke] = strokeCol;
- Buttons[_:btnid][btn_col_bg] = buttonCol;
- Buttons[_:btnid][btn_col_txt] = textCol;
- TextDrawBoxColor(btn_td1[_:btnid][playerid], strokeCol);
- TextDrawBoxColor(btn_td2[_:btnid][playerid], buttonCol);
- TextDrawColor(btn_td3[_:btnid][playerid], textCol);
- return 1;
- }
- return 0;
- }
- stock IsValidButton(Button:btnid)
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return false;
- else return true;
- }
- return false;
- }
- stock UpdateButtonForPlayer(playerid, Button:btnid)
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- HideButtonForPlayer(playerid, btnid);
- ShowButtonForPlayer(playerid, btnid);
- return 1;
- }
- return 0;
- }
- stock GetButtonPos(Button:btnid, &Float:x, &Float:y)
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- x = Buttons[_:btnid][btn_x];
- y = Buttons[_:btnid][btn_x];
- return 1;
- }
- return 0;
- }
- stock GetButtonSize(Button:btnid, &Float:width, &Float:height)
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- width = Buttons[_:btnid][btn_w];
- height = Buttons[_:btnid][btn_h];
- return 1;
- }
- return 0;
- }
- stock GetButtonColors(Button:btnid, &strokeCol, &buttonCol, &textCol)
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(!Buttons[_:btnid][btn_created]) return 0;
- strokeCol = Buttons[_:btnid][btn_col_stroke];
- buttonCol = Buttons[_:btnid][btn_col_bg];
- textCol = Buttons[_:btnid][btn_col_txt];
- return 1;
- }
- return 0;
- }
- stock GetButtonText(Button:btnid)
- {
- if(btnid != INVALID_BUTTON_ID && Button:-1 < btnid < Button:MAX_BUTTONS)
- {
- if(Buttons[_:btnid][btn_created])
- return Buttons[_:btnid][btn_txt];
- }
- return 0;
- }
- public OnPlayerClickTextDraw(playerid, Text:clickedid)
- {
- for(new i; i <= MAX_BUTTONS; i++)
- {
- if(Buttons[i][btn_created])
- {
- if(clickedid == btn_td3[i][playerid])
- {
- OnPlayerClickButton(playerid, Button:i);
- }
- }
- }
- return CallLocalFunction("myinc_OnPlayerClickTextDraw", "ii", playerid, _:clickedid);
- }
- #if defined _ALS_OnPlayerClickTextDraw
- #undef OnPlayerClickTextDraw
- #else
- #define _ALS_OnPlayerClickTextDraw
- #endif
- #define OnPlayerClickTextDraw myinc_OnPlayerClickTextDraw
- forward myinc_OnPlayerClickTextDraw(playerid, Text:clickedid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement