[Include] Buttons Include - Create buttons with 1 line [0.3e RC5+]
#1

-Introduction:

Since the new functions and possibilities to click textdraws came out with 0.3e there's a lot of things you can do with textdraws now. One of the most basic things you can think of when looking at these functions are buttons. Even though basic, it may take 2, 3 or even more textdraws to create just ONE button and for scripts which require a lot of buttons it is a real pain in the you know what to create all those buttons manually one by one. This is the reason I created this include. With this include you can create (almost) fully customizable buttons with just ONE line of code. At first I created this just for personal use, but then I thought it might be useful for other people too, so I decided to release it. I know you guys don't like reading too much so let's get straight into the functions and features.


-Functions:

pawn Код:
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)l
native UpdateButtonForPlayer(playerid, Button:btnid);
forward OnPlayerClickButton(playerid, Button:btnid);
//============================  Added in v1.1 ================================//
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);
Let's explain what they do one by one:

pawn Код:
stock Button:CreateButtonForPlayer(playerid, text[200], Float:x, Float:y, Float:width = 72.0, Float:height = 23.0)
{
    /*
    Will create a button for the specified player will the specified params and the default colors (black, red, white... you can change them later).

    playerid -> The player to create the button for.
    text[] -> The string with the text of the button.
    Float:x -> The x coordinate of the button.
    Float:y -> The y coordinate of the button.
    Float:width -> The width of the button.
    Float:height -> The height of the button.

    Returns the ID of the button created with the "Button:" prefix.
    */

}

stock ShowButtonForPlayer(playerid, Button:btnid)
{
    /*
    Will show the specified button for the specified.

    playerid -> The player to show the button to.
    Button:btnid -> The button to show to the player.

    Returns 1 on success and 0 on failure.
    */

}

stock DestroyButton(Button:btnid)
{
    /*
    Will destroy the specified button for everyone.

    Button:btnid -> The button to destroy.

    Returns 1 on success and 0 on failure.
    */

}

stock DestroyButtonForPlayer(playerid, Button:btnid)
{
    /*
    Will destroy the specified button for the specified player.

    playerid -> The player to destroy the button for.
    Button:btnid -> The button to destroy.

    Returns 1 on success and 0 on failure.
    */

}

stock HideButtonForPlayer(playerid, Button:btnid)
{
    /*
    Will hide the specified button for the specified player.

    playerid -> The player to hide the button for.
    Button:btnid -> The button to hide.

    Returns 1 on success and 0 on failure.
    */

}

stock SetButtonTextForPlayer(playerid, Button:btnid, text[])
{
    /*
    Will change the specified button's text for the specified player.

    playerid -> The player of whose button's text you want to change.
    Button:btnid -> The button whose text you want to change.
    text[] -> the string that contais the new text of the button.

    Returns 1 on success and 0 on failure.
    */

}

stock ChangeButtonColorsForPlayer(playerid, Button:btnid, strokeCol, buttonCol, textCol)
{
    /*
    Will change the specified button's color for the specified player (Supports transparency too).

    playerid -> The player whose button's color you want to change.
    Button:btnid -> The button whose colors you want to change.
    strokeCol -> The color of the line around the BUTTON (Black by default).
    buttonCol -> The color of the inner part of the button (Red by default).
    textCol -> The color of the text's button (White by default).

    Returns 1 on success and 0 on failure.
    */

}

stock IsValidButton(Button:btnid)
{
    /*
    Checks if the specified button is created or not.

    Button:btnid -> The button to check for.

    Returns true if is valid and false if it's not.
    */

}

stock UpdateButtonForPlayer(playerid, Button:btnid)
{
    /*
    Update the specified button with the changes made (must be used after each colors change that has been made).

    playerid -> The player to update the button for.
    Button:btnid -> The button to change the colors to.

    Returns 1 on success and 0 on failure.
    */

}

public OnPlayerClickButton(playerid, Button:btnid)
{
    /*
    Will be called everytime a player click on a button (Created with CreateButtonForPlayer).

    playerid -> The player that has clicked on the button.
    Button:btnid -> the button that has been clicked.
    */

}

//============================  Added in v1.1 ================================//

stock GetButtonPos(Button:btnid, &Float:x, &Float:y)
{
    /*
    Gets the position of the specified button.
   
    Button:btnid -> The id of the button to get the position of.
    &Float:x -> The Float variable to store the X position of the button.
    &Float:y -> The Float variable to store the Y position of the button.
   
    Returns 1 on success and 0 on failure.
    */

}

stock GetButtonSize(Button:btnid, &Float:width, &Float:height)
{
    /*
    Gets the position of the specified button.

    Button:btnid -> The id of the button to get the position of.
    &Float:width -> The Float variable to store the width of the button.
    &Float:height -> The Float variable to store the height of the button.
   
    Returns 1 on success and 0 on failure.
    */

}

stock GetButtonColors(Button:btnid, &strokeCol, &buttonCol, &textCol)
{
    /*
    Gets the position of the specified button.

    Button:btnid -> The id of the button to get the position of.
    &strokeCol -> The variable to store the button's stroke color.
    &buttonCol -> The variable to store the button's inner color.
    &textCol -> The variable to store the button's text color.

    Returns 1 on success and 0 on failure.
    */

}

stock GetButtonText(Button:btnid)
{
    /*
    Gets the position of the specified button.

    Button:btnid -> The id of the button to get the position of.

    Returns The text String of the Button on Success and 0 on Failure.
    */

}
Every function is explained with the comments.


-Features:
  • Allows you to add buttons with just one line of code.
  • Ability to modify the button's text color and position.
  • Ability to move the WHOLE button without moving each textdraw.
  • Response on each button click.
  • Ability to add your own code when a button is pressed.

-How to use:

In order to be able to use this include you have to follow these simple steps:

1. Download the file below.
2. Extract the buttons.inc file into your "\pawno\include" directory.
3. Extract the .amx and .pwn file of the test Filterscript in your "filterscripts" directory (optional).
4. Add the following line on top of your scripts with the other includes:
pawn Код:
#include <buttons>
5. Put the following code inside your script:
pawn Код:
public OnPlayerClickButton(playerid, Button:i)
{
      return 1;
}
6. If you are going to use the test filterscript open server.cfg and put "TestButtons" in the "filterscripts" line.
7. You are DONE and ready to use all the functions.


-Known Bugs:

I'm not aware of any bugs bugs at the moment but it is possible to find bugs because I haven't worked much with textdraws before and the script isn't fully tested. If you find any feel free to report it below and I'll try to fix them with the next update.



-Example:

Version 1.1:



Version 1.0:




-Download:

Version 1.1:




Version 1.0:




-Notes:
  • In order for this include to work you must have sa-mp 0.3e RC4 or any later version and all its includes updated (Get it here)
  • You must have the "OnPlayerClickButton" public on your script whether you use it or not (to avoid errors).
  • You must use "UpdateButtonForPlayer" every time you update the button's colors.

-Screenshots:







-ChangeLog:

Код:
V1.0:
Initial Release

V1.1:
-Added GetButtonpos Function
-Added GetButtonSize Function
-Added GetButtonColors Function
-Added GetButtonText Function
-Hooked OnPlayerClickTextdraw so you don't need to add anything else on your code beside OnPlayerClickButton
-Makes usage of Global Textdraws instead of Player TDs (to avoid bugs with the Hooked function)
-Small bug fixes with DestroyButton and DestroyButtonForPlayer
Any Suggestion, feedback and comment is welcome as always ;)
Reply
#2

A screenshot please.
Reply
#3

Quote:
Originally Posted by costel_nistor96
Посмотреть сообщение
A screenshot please.
Uploading now

Edit: Screenshots added
Reply
#4

Hook the callback instead of telling people to put it on the callback.
Reply
#5

Quote:
Originally Posted by T0pAz
Посмотреть сообщение
Hook the callback instead of telling people to put it on the callback.
Quote:

(I tried using y_hooks but it didn't work)

Please read more carefully next time.
Reply
#6

Quote:
Originally Posted by SpiritEvil
Посмотреть сообщение
Please read more carefully next time.
Use the old als method then.
Reply
#7

Quote:
Originally Posted by T0pAz
Посмотреть сообщение
Use the old als method then.
I never really understood how it works. If you can give me an example I'd be glad to put it on the include and give you credits for that.
Reply
#8

Check out this thread.
Reply
#9

Quote:
Originally Posted by T0pAz
Посмотреть сообщение
Thank you for that. I'll run some tests before putting it on the include

Edit:

Код:
warning 200: symbol "_ALS_OnPlayerClickPlayerTextDra" is truncated to 31 characters
Looks like it cannot be over 31 characters long.
Reply
#10

Updated to Version 1.1, enjoy

The following is added:

pawn Код:
/*      
+++++++++++++++++++++++ | 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                                       +
+ =========================================================== +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
Reply
#11

I knew someone would have make such an include, it's so obvious. Which is, very useful! Good job, SpiritEvil.
Reply
#12

Quote:
Originally Posted by Toreno
Посмотреть сообщение
I knew someone would have make such an include, it's so obvious. Which is, very useful! Good job, SpiritEvil.
Thank you, I appreciate that I'm glad to be the first to make something like this though
Reply
#13

Are the Button Clickable Btw its a Awesome Include i Will surely Use it If the Button's Are Clickable
Reply
#14

Dialog is a bit pointless, surely 'don't save' and 'cancel' have the same result? Bad example.
Nice FS though, well done.
Reply
#15

Wow, I thought it would be like Sothclaws one! I was wrong, nice made anyway!
Reply
#16

Quote:
Originally Posted by Phyrunx
Посмотреть сообщение
Are the Button Clickable Btw its a Awesome Include i Will surely Use it If the Button's Are Clickable
Of course they are clickable, why else would I made them xD

Quote:
Originally Posted by MP2
Dialog is a bit pointless, surely 'don't save' and 'cancel' have the same result? Bad example.
Nice FS though, well done.
It is just a demonstration on how you can use the functions, and 'don't save' and 'cancel' do not have the same result. Don't save will just send a Client message to the player saying "The file will not be saved" while 'cancel' will close the dialog.

Anyway, thanks for the comment

Quote:
Originally Posted by justsomeguy
Wow, I thought it would be like Sothclaws one! I was wrong, nice made anyway!
Thank you
Reply
#17

Nice include!
Reply
#18

Looks nice, sir. ;P

Reply
#19

Good Job.
Reply
#20

Quote:
Originally Posted by Twisted_Insane
Посмотреть сообщение
Nice include!
Thanks mate

Quote:
Originally Posted by costel_nistor96
Looks nice, sir. ;P
I am grateful to you, sir!

Quote:
Originally Posted by Juninho_Oakley
Good Job.
Thanks

P.S Nice boobs on the pic
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)