[Include] Interactive clickable textdraw keypad system (Easy to use)
#1

Interactive Textdraw Keypad 1.1
by MP2
Introduction
Using the awesome new textdraw clicking system in SA:MP 0.3e, this simple include allows players to interact with a textdraw keypad with their mouse. It is also super easy to use, with only one function and callback.

Example Mode:
[ame]http://www.youtube.com/watch?v=PetpqU0TFCc[/ame]

NOTE: This is a new feature in 0.3e, which was recently released. Download the latest version HERE. It will NOT work on earlier versions.

Download
http://puu.sh/gWZ2W.inc << The include. This is what you NEED.
http://puu.sh/gWZ4W.pwn << An OPTIONAL example gamemode, so you can see how to use it. This is what you see in the video above.

Installation
Download the .inc file above.
Place it in your /pawno/include folder.
Add the following at the top of your script, under #include <a_samp>, NOT above it:

pawn Код:
#undef MAX_PLAYERS
#define MAX_PLAYERS 32 // How many ACTUAL slots you have. This saves memory.
#include <keypad>
Replace 32 with how many slots your server has. It must NOT be less than, but can be higher. This simply saves memory.

If you want to use a key longer than 10 numbers, alter the MAX_KEYPAD_KEY_LENGTH value in the .inc file.

Usage
To show a keypad, simply use the ShowPlayerKeypad() function.

ShowPlayerKeypad(playerid, keypadID, key[])

playerid - The player to show the keypad for
keypadID - Like dialogids, give every keypad it's unique ID to identify which keypad they are responding to. These are also seperate in different scripts, so no need to worry about clashes. A keypad with the ID 5 SHOULD NOT interfere with a keypad with ID 5 in another script. It uses CallLocalFunction(). Can not be 0.
key[] - A STRING of NUMBERS to use as the key*

* If you'd like to use an integer variable as the key, you must convert it to a string:

pawn Код:
new var = 1337;
new szKey[5]; // Above variable is 4 number, add one to this for the string array size (one 'null-terminating' character)
valstr(szKey, var); // Put the variable in to the string
ShowPlayerKeypad(playerid, keypadID, szKey);
This function returns values depending on success or failure:
pawn Код:
// Return codes for ShowPlayerKeypad
#define CREATEKEYPAD_RETURN_INVALID_ID 0 // ID must be 1+
#define CREATEKEYPAD_RETURN_NUM -1 // String is not a number sequence
#define CREATEKEYPAD_RETURN_INVALID_PLAYER -2 // 'playerid' not connected

When a player's input reaches the length of the key, the script checks if it is correct, then calls OnPlayerKeypadInput, passing the following arguments:

OnPlayerKeypadInput(playerid, keypadID, type, key)

playerid - The player that inputted a code
keypadID - The keypadID assigned in ShowPlayerKeypad()
type - The type of input:
pawn Код:
// Input types (for OnPlayerKeypadInput)
#define KEYPAD_INPUT_BAD 0 // Failed authorization
#define KEYPAD_INPUT_GOOD 1 // Successful authorization
#define KEYPAD_INPUT_CANCEL 2 // Called when ESC press to cancel keypad
key[] - The key that was entered

NOTE: GetPlayerKeypad will return 0 in this callback for the playerid, use the keypadID value.


Also added is GetPlayerKeypad, which returns the player's current keypad (0 if none or in OnPlayerKeypadInput).
The syntax is simply 'GetPlayerKeypad(playerid)'. For example:
pawn Код:
CMD:keypad(playerid, params[])
{
    new szString[24];
    format(szString, sizeof(szString), "Your keypad: %i", GetPlayerKeypad(playerid));
    SendClientMessage(playerid, -1, szString);
    return 1'
}

Download the example mode HERE, it will help you understand exactly how to use it.

Changelog
1.0
- Initial release

1.1 (7th of April 2012)
- Textdraws only created when needed (textdraws destroyed if no players have a keypad open), and not per-player (only ever creates 25 textdraws)
- Improved variable names
- Changed function names, if you used 1.0 you will need to replace CreateKeypad() with ShowPlayerKeypad().

Conclusion
Thank you for reading, and if you use this include, I hope you enjoy it! If you have a suggestion, or more importantly find a bug, please report it in this topic.
The code is also well commented, so you should be able to figure out exactly how it works.


Known Bugs
- Showing a keypad after a player enters a key, but before the keypad is closed (showing result) may cause problems - needs testing
If you find a bug please report it in this topic. Reputation will be given for bug reports.
Reply


Messages In This Thread
Interactive clickable textdraw keypad system (Easy to use) - v1.1 - UPDATED 7th MARCH - by MP2 - 27.03.2012, 07:53
Re: Interactive clickable textdraw keypad system (Easy to use) - by T0pAz - 27.03.2012, 07:55
Re: Interactive clickable textdraw keypad system (Easy to use) - by FireCat - 27.03.2012, 07:56
Re: Interactive clickable textdraw keypad system (Easy to use) - by IstuntmanI - 27.03.2012, 09:00
Re: Interactive clickable textdraw keypad system (Easy to use) - by SpiderWalk - 27.03.2012, 09:02
Re : Interactive clickable textdraw keypad system (Easy to use) - by Ultrascipter - 27.03.2012, 09:29
Re: Interactive clickable textdraw keypad system (Easy to use) - by System64 - 27.03.2012, 11:13
Re: Interactive clickable textdraw keypad system (Easy to use) - by TheArcher - 27.03.2012, 12:49
Re: Interactive clickable textdraw keypad system (Easy to use) - by Edvin - 27.03.2012, 12:54
Re : Interactive clickable textdraw keypad system (Easy to use) - by dydjyz - 27.03.2012, 14:38
Re : Interactive clickable textdraw keypad system (Easy to use) - by Vukilore - 27.03.2012, 14:54
Re: Interactive clickable textdraw keypad system (Easy to use) - by MP2 - 27.03.2012, 15:14
Re: Interactive clickable textdraw keypad system (Easy to use) - by vyper - 27.03.2012, 15:16
Re: Interactive clickable textdraw keypad system (Easy to use) - by Shadow_ - 27.03.2012, 15:44
Re: Interactive clickable textdraw keypad system (Easy to use) - by Nicholas. - 27.03.2012, 15:55
Re: Interactive clickable textdraw keypad system (Easy to use) - by AirKite - 27.03.2012, 15:56
Respuesta: Interactive clickable textdraw keypad system (Easy to use) - by LuisGraph - 27.03.2012, 17:00
Re: Respuesta: Interactive clickable textdraw keypad system (Easy to use) - by MP2 - 28.03.2012, 03:16
Re: Interactive clickable textdraw keypad system (Easy to use) - by Niko_boy - 28.03.2012, 03:29
Re: Interactive clickable textdraw keypad system (Easy to use) - by Avi57 - 28.03.2012, 06:46
Re: Interactive clickable textdraw keypad system (Easy to use) - by MP2 - 28.03.2012, 17:44
Re: Interactive clickable textdraw keypad system (Easy to use) - by xX60CentXx - 28.03.2012, 17:51
Re: Interactive clickable textdraw keypad system (Easy to use) - by MP2 - 28.03.2012, 21:09
Re: Interactive clickable textdraw keypad system (Easy to use) - by jamesbond007 - 29.03.2012, 23:34
Re: Interactive clickable textdraw keypad system (Easy to use) - by ikey07 - 30.03.2012, 11:41
Re: Interactive clickable textdraw keypad system (Easy to use) - by Angel.Why - 16.04.2012, 16:59
Re: Interactive clickable textdraw keypad system (Easy to use) - by vIBIENNYx - 22.05.2012, 13:36
Re: Interactive clickable textdraw keypad system (Easy to use) - by vIBIENNYx - 23.05.2012, 01:56
Re: Interactive clickable textdraw keypad system (Easy to use) - by Jake_Ramsay - 24.06.2012, 12:06
Re: Interactive clickable textdraw keypad system (Easy to use) - by MP2 - 24.06.2012, 12:40
Re: Interactive clickable textdraw keypad system (Easy to use) - by Kontrol - 21.04.2013, 23:36
Re: Interactive clickable textdraw keypad system (Easy to use) - by coloN - 01.07.2014, 16:25
Re: Interactive clickable textdraw keypad system (Easy to use) - by JonathanW - 01.07.2014, 16:32
Re: Interactive clickable textdraw keypad system (Easy to use) - by coloN - 01.07.2014, 16:33
Re: Interactive clickable textdraw keypad system (Easy to use) - by OKStyle - 27.09.2014, 06:24
Re: Interactive clickable textdraw keypad system (Easy to use) - by Leitoo - 29.10.2014, 13:29
Re: Interactive clickable textdraw keypad system (Easy to use) - by MP2 - 04.04.2015, 15:06
Re: Interactive clickable textdraw keypad system (Easy to use) - by Golf - 05.04.2015, 18:08
Re: Interactive clickable textdraw keypad system (Easy to use) - by Riccardomen - 14.04.2015, 18:00
Re: Interactive clickable textdraw keypad system (Easy to use) - by S3DOx - 14.07.2018, 01:15

Forum Jump:


Users browsing this thread: 4 Guest(s)