27.03.2012, 07:53
(
Последний раз редактировалось MP2; 31.03.2015 в 23:21.
)
Interactive Textdraw Keypad 1.1
by MP2
Introductionby MP2
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>
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);
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
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.