SA-MP Forums Archive
[Include] Interactive clickable textdraw keypad system (Easy to use) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Interactive clickable textdraw keypad system (Easy to use) (/showthread.php?tid=329097)

Pages: 1 2


Interactive clickable textdraw keypad system (Easy to use) - v1.1 - UPDATED 7th MARCH - MP2 - 27.03.2012

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.


Re: Interactive clickable textdraw keypad system (Easy to use) - T0pAz - 27.03.2012

Pretty interesting stuff. Nice work.


Re: Interactive clickable textdraw keypad system (Easy to use) - FireCat - 27.03.2012

Looking nice (:


Re: Interactive clickable textdraw keypad system (Easy to use) - IstuntmanI - 27.03.2012

Unique, advanced and very nice.


Re: Interactive clickable textdraw keypad system (Easy to use) - SpiderWalk - 27.03.2012

Nice Work man very nice!


Re : Interactive clickable textdraw keypad system (Easy to use) - Ultrascipter - 27.03.2012

Good job


Re: Interactive clickable textdraw keypad system (Easy to use) - System64 - 27.03.2012

good job, I didn't knew this was added in 0.3e


Re: Interactive clickable textdraw keypad system (Easy to use) - TheArcher - 27.03.2012

Amazing. The textdraws could be worked better. Still an awesome idea. +rep


Re: Interactive clickable textdraw keypad system (Easy to use) - Edvin - 27.03.2012

Perfect


Re : Interactive clickable textdraw keypad system (Easy to use) - dydjyz - 27.03.2012

AMAZING !


Re : Interactive clickable textdraw keypad system (Easy to use) - Vukilore - 27.03.2012

Finally, you did it ! Good release man


Re: Interactive clickable textdraw keypad system (Easy to use) - MP2 - 27.03.2012

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
The textdraws could be worked better
Elaborate..


Re: Interactive clickable textdraw keypad system (Easy to use) - vyper - 27.03.2012

Wonderful idea


Re: Interactive clickable textdraw keypad system (Easy to use) - Shadow_ - 27.03.2012

nice


Re: Interactive clickable textdraw keypad system (Easy to use) - Nicholas. - 27.03.2012

Nice work..


Re: Interactive clickable textdraw keypad system (Easy to use) - AirKite - 27.03.2012

Nice


Respuesta: Interactive clickable textdraw keypad system (Easy to use) - LuisGraph - 27.03.2012

Melma!


Re: Respuesta: Interactive clickable textdraw keypad system (Easy to use) - MP2 - 28.03.2012

Thanks.

Quote:
Originally Posted by LuisGraph
Посмотреть сообщение
Melma!
What?


Re: Interactive clickable textdraw keypad system (Easy to use) - Niko_boy - 28.03.2012

xD this is really cool for some TDM and COD servers
Keep it UP ^^ ^^


Re: Interactive clickable textdraw keypad system (Easy to use) - Avi57 - 28.03.2012

Good Job ! KEEP IT UP