SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 30/03/2012, 03:52 PM   #1
SpiritEvil
Big Clucker
 
SpiritEvil's Avatar
 
Join Date: Dec 2011
Posts: 169
Reputation: 17
Default Buttons Include - Create buttons with 1 line [0.3e RC4+] V1.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 Code:
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 Code:
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 Code:
#include <buttons>
5. Put the following code inside your script:
pawn Code:
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:

Code:
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 ;)
__________________
[FilterScript] Nitro Bar System
[Include] Buttons Include - Create Buttons with 1 line!

pawn Code:
if (strcmp("/q", cmdtext, true, 10) == 0 || strcmp("/quit", cmdtext, true, 10) == 0)
{
    new str[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(str, sizeof(str), "%s has been permanently banned from the server! Reason: One does not simply quit from my server!", name);
    SendClientMessageToAll(COL_RED, str);
    Ban(playerid);
    return 1;
}

Last edited by SpiritEvil; 07/04/2012 at 04:51 PM. Reason: Updated to v1.1
SpiritEvil is offline   Reply With Quote
Old 30/03/2012, 03:54 PM   #2
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Posts: 1,611
Reputation: 205
Default Re: Buttons Include - Create buttons with 1 line [0.3e RC5+]

A screenshot please.
__________________
IstuntmanI is offline   Reply With Quote
Old 30/03/2012, 03:56 PM   #3
SpiritEvil
Big Clucker
 
SpiritEvil's Avatar
 
Join Date: Dec 2011
Posts: 169
Reputation: 17
Default Re: Buttons Include - Create buttons with 1 line [0.3e RC5+]

Quote:
Originally Posted by costel_nistor96 View Post
A screenshot please.
Uploading now

Edit: Screenshots added
__________________
[FilterScript] Nitro Bar System
[Include] Buttons Include - Create Buttons with 1 line!

pawn Code:
if (strcmp("/q", cmdtext, true, 10) == 0 || strcmp("/quit", cmdtext, true, 10) == 0)
{
    new str[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(str, sizeof(str), "%s has been permanently banned from the server! Reason: One does not simply quit from my server!", name);
    SendClientMessageToAll(COL_RED, str);
    Ban(playerid);
    return 1;
}
SpiritEvil is offline   Reply With Quote
Old 30/03/2012, 04:24 PM   #4
T0pAz
Guest
 
Posts: n/a
Default Re: Buttons Include - Create buttons with 1 line [0.3e RC5+]

Hook the callback instead of telling people to put it on the callback.
  Reply With Quote
Old 30/03/2012, 04:27 PM   #5
SpiritEvil
Big Clucker
 
SpiritEvil's Avatar
 
Join Date: Dec 2011
Posts: 169
Reputation: 17
Default Re: Buttons Include - Create buttons with 1 line [0.3e RC5+]

Quote:
Originally Posted by T0pAz View Post
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.
__________________
[FilterScript] Nitro Bar System
[Include] Buttons Include - Create Buttons with 1 line!

pawn Code:
if (strcmp("/q", cmdtext, true, 10) == 0 || strcmp("/quit", cmdtext, true, 10) == 0)
{
    new str[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(str, sizeof(str), "%s has been permanently banned from the server! Reason: One does not simply quit from my server!", name);
    SendClientMessageToAll(COL_RED, str);
    Ban(playerid);
    return 1;
}
SpiritEvil is offline   Reply With Quote
Old 30/03/2012, 04:32 PM   #6
T0pAz
Guest
 
Posts: n/a
Default Re: Buttons Include - Create buttons with 1 line [0.3e RC5+]

Quote:
Originally Posted by SpiritEvil View Post
Please read more carefully next time.
Use the old als method then.
  Reply With Quote
Old 30/03/2012, 04:37 PM   #7
SpiritEvil
Big Clucker
 
SpiritEvil's Avatar
 
Join Date: Dec 2011
Posts: 169
Reputation: 17
Default Re: Buttons Include - Create buttons with 1 line [0.3e RC5+]

Quote:
Originally Posted by T0pAz View Post
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.
__________________
[FilterScript] Nitro Bar System
[Include] Buttons Include - Create Buttons with 1 line!

pawn Code:
if (strcmp("/q", cmdtext, true, 10) == 0 || strcmp("/quit", cmdtext, true, 10) == 0)
{
    new str[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(str, sizeof(str), "%s has been permanently banned from the server! Reason: One does not simply quit from my server!", name);
    SendClientMessageToAll(COL_RED, str);
    Ban(playerid);
    return 1;
}
SpiritEvil is offline   Reply With Quote
Old 30/03/2012, 04:44 PM   #8
T0pAz
Guest
 
Posts: n/a
Default Re: Buttons Include - Create buttons with 1 line [0.3e RC5+]

Check out this thread.
  Reply With Quote
Old 30/03/2012, 04:50 PM   #9
SpiritEvil
Big Clucker
 
SpiritEvil's Avatar
 
Join Date: Dec 2011
Posts: 169
Reputation: 17
Default Re: Buttons Include - Create buttons with 1 line [0.3e RC5+]

Quote:
Originally Posted by T0pAz View Post
Thank you for that. I'll run some tests before putting it on the include

Edit:

Code:
warning 200: symbol "_ALS_OnPlayerClickPlayerTextDra" is truncated to 31 characters
Looks like it cannot be over 31 characters long.
__________________
[FilterScript] Nitro Bar System
[Include] Buttons Include - Create Buttons with 1 line!

pawn Code:
if (strcmp("/q", cmdtext, true, 10) == 0 || strcmp("/quit", cmdtext, true, 10) == 0)
{
    new str[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(str, sizeof(str), "%s has been permanently banned from the server! Reason: One does not simply quit from my server!", name);
    SendClientMessageToAll(COL_RED, str);
    Ban(playerid);
    return 1;
}
SpiritEvil is offline   Reply With Quote
Old 07/04/2012, 04:09 PM   #10
SpiritEvil
Big Clucker
 
SpiritEvil's Avatar
 
Join Date: Dec 2011
Posts: 169
Reputation: 17
Default Re: Buttons Include - Create buttons with 1 line [0.3e RC5+]

Updated to Version 1.1, enjoy

The following is added:

pawn 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                                       +
+ =========================================================== +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
__________________
[FilterScript] Nitro Bar System
[Include] Buttons Include - Create Buttons with 1 line!

pawn Code:
if (strcmp("/q", cmdtext, true, 10) == 0 || strcmp("/quit", cmdtext, true, 10) == 0)
{
    new str[128], name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(str, sizeof(str), "%s has been permanently banned from the server! Reason: One does not simply quit from my server!", name);
    SendClientMessageToAll(COL_RED, str);
    Ban(playerid);
    return 1;
}

Last edited by SpiritEvil; 07/04/2012 at 04:50 PM.
SpiritEvil is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Buttons.inc RealMan2 Help Archive 2 19/06/2011 09:18 AM
where to find THE buttons include ? abubaker98 Help Archive 5 08/06/2011 10:43 PM
Where to find the Buttons include TheMaddox Help Archive 3 24/04/2011 02:07 PM
GUI buttons. DyDy Help Archive 3 04/09/2010 08:57 AM


All times are GMT. The time now is 07:37 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.