SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 27/03/2012, 07:53 AM   #1
MP2
Godfather
 
MP2's Avatar
 
Join Date: Jan 2011
Location: England
Posts: 6,203
Reputation: 975
Default Interactive clickable textdraw keypad system (Easy to use) - v1.1 - UPDATED 7th MARCH

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.*******.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 Code:
#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 Code:
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 Code:
// 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 Code:
// 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 Code:
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.
__________________
Click banner above for more info. View trailers here.

Last edited by MP2; 31/03/2015 at 11:21 PM.
MP2 is offline   Reply With Quote
Old 27/03/2012, 07:55 AM   #2
T0pAz
Guest
 
Posts: n/a
Default Re: Interactive clickable textdraw keypad system (Easy to use)

Pretty interesting stuff. Nice work.
  Reply With Quote
Old 27/03/2012, 07:56 AM   #3
FireCat
High-roller
 
FireCat's Avatar
 
Join Date: Jul 2010
Posts: 2,323
Reputation: 596
Default Re: Interactive clickable textdraw keypad system (Easy to use)

Looking nice (:
FireCat is offline   Reply With Quote
Old 27/03/2012, 09:00 AM   #4
IstuntmanI
High-roller
 
IstuntmanI's Avatar
 
Join Date: Mar 2009
Location: Romania
Posts: 1,832
Reputation: 375
Default Re: Interactive clickable textdraw keypad system (Easy to use)

Unique, advanced and very nice.
__________________


IstuntmanI is offline   Reply With Quote
Old 27/03/2012, 09:02 AM   #5
SpiderWalk
Gangsta
 
SpiderWalk's Avatar
 
Join Date: Apr 2010
Location: Serbia
Posts: 970
Reputation: 26
Default Re: Interactive clickable textdraw keypad system (Easy to use)

Nice Work man very nice!
SpiderWalk is offline   Reply With Quote
Old 27/03/2012, 09:29 AM   #6
Ultrascipter
Big Clucker
 
Join Date: Mar 2012
Posts: 58
Reputation: 2
Default Re : Interactive clickable textdraw keypad system (Easy to use)

Good job
Ultrascipter is offline   Reply With Quote
Old 27/03/2012, 11:13 AM   #7
System64
Gangsta
 
System64's Avatar
 
Join Date: May 2011
Location: Zadar, Croatia
Posts: 933
Reputation: 143
Default Re: Interactive clickable textdraw keypad system (Easy to use)

good job, I didn't knew this was added in 0.3e
__________________
All my works
I left SA:MP! Maybe once I start scripting again but now I'm based on web programming
Soon, I'll buy domain system32.com.hr but for now you can contact me on LogoOff or on my ******* channel!
System64 is offline   Reply With Quote
Old 27/03/2012, 12:49 PM   #8
TheArcher
High-roller
 
TheArcher's Avatar
 
Join Date: Dec 2009
Location: Home
Posts: 2,338
Reputation: 251
Default Re: Interactive clickable textdraw keypad system (Easy to use)

Amazing. The textdraws could be worked better. Still an awesome idea. +rep
__________________
TheArcher is offline   Reply With Quote
Old 27/03/2012, 12:54 PM   #9
Edvin
Gangsta
 
Edvin's Avatar
 
Join Date: Dec 2010
Posts: 859
Reputation: 71
Default Re: Interactive clickable textdraw keypad system (Easy to use)

Perfect
Edvin is offline   Reply With Quote
Old 27/03/2012, 02:38 PM   #10
dydjyz
Big Clucker
 
dydjyz's Avatar
 
Join Date: Apr 2010
Posts: 54
Reputation: 11
Default Re : Interactive clickable textdraw keypad system (Easy to use)

AMAZING !
dydjyz 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
An easy question, how to add a transparent background in a textdraw? CTCCoco Help Archive 2 29/06/2011 07:12 PM
Textdraw question (easy one) *IsBack Help Archive 5 30/12/2010 11:42 AM
[Solved] Clickable TextDraw troy52192 Help Archive 6 28/10/2009 06:43 AM
Interactive Textdraw Rome101 Help Archive 1 05/04/2009 05:39 AM


All times are GMT. The time now is 05:41 AM.


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