Detecting ESC Key while Selecting Textdraws -
||123|| - 15.11.2013
Is there a way I could detect when the player presses ESC key at selecting textdraws. Maybe a callback or something?
Re: Detecting ESC Key while Selecting Textdraws -
Nourdin - 15.11.2013
I think it's not possible.
Re: Detecting ESC Key while Selecting Textdraws -
newbie scripter - 15.11.2013
It is but idk how
Re: Detecting ESC Key while Selecting Textdraws -
InfiniTy. - 15.11.2013
Under the OnPlayerClickTextDraw callback
pawn Код:
if(clickedid == Text:INVALID_TEXT_DRAW) {
//do stuff
}
Re: Detecting ESC Key while Selecting Textdraws -
Threshold - 15.11.2013
OnPlayerClickTextDraw
If this callback returns INVALID_TEXT_DRAW.
For example, lets say you open textdraw 1 for selection:
pawn Код:
SelectTextDraw(playerid, 0xFF0000FF);
PlayerInTDSelection[playerid] = true; //An example
pawn Код:
public OnPlayerClickTextDraw(playerid, Text:clickedid)
{
if(PlayerInTDSelection[playerid] == true)
{
if(clickedid == INVALID_TEXT_DRAW)
{
SendClientMessage(playerid, 0xFF0000FF, "You pressed ESC/Cancelled the textdraw selection");
return 0;
}
//rest here
}
return 1;
}
This is just an example, and I wouldn't recommend using this code in its entirety in your script. As it may not function as you desire, as it is not a full code.
Re: Detecting ESC Key while Selecting Textdraws -
||123|| - 15.11.2013
Doesn't work. It's not getting called. It should get called when I cancel the textdraw selection mode using ESC Key.
Re: Detecting ESC Key while Selecting Textdraws -
||123|| - 15.11.2013
Sorry for double posting, but I figured and read that it's not being called because I'm using PlayerTextdraws. And OnPlayerClickPlayerTextdraw doesn't gets called when you cancel the click mode using Player Textdraws. Please help me find a workaround on this.
Re: Detecting ESC Key while Selecting Textdraws -
InfiniTy. - 15.11.2013
Quote:
Originally Posted by ||123||
Sorry for double posting, but I figured and read that it's not being called because I'm using PlayerTextdraws. And OnPlayerClickPlayerTextdraw doesn't gets called when you cancel the click mode using Player Textdraws. Please help me find a workaround on this.
|
Nvm..
OnPlayerClickTextdraw should be called when you press ESC..
Код:
This callback is called when a player clicks on a player-textdraw. It is not called when player cancels the select mode (ESC) - however, OnPlayerClickTextDraw is.
Re: Detecting ESC Key while Selecting Textdraws -
Konstantinos - 15.11.2013
Quote:
Originally Posted by InfiniTy.
Under the OnPlayerClickTextDraw callback
pawn Код:
if(clickedid == Text:INVALID_TEXT_DRAW) { //do stuff }
|
It's still correct, both global and per-player textdraws call OnPlayerClickTextDraw for the ESC detection.
pawn Код:
public OnPlayerClickTextDraw( playerid, Text: clickedid )
{
if( clickedid == Text: INVALID_TEXT_DRAW )
{
PlayerTextDrawHide( playerid, ... );
// code..
return 1;
}
return 0;
}
public OnPlayerClickPlayerTextDraw( playerid, PlayerText: playertextid )
{
if( playertextid == ... )
{
// code..
CancelSelectTextDraw( playerid );
}
return 0;
}
Re: Detecting ESC Key while Selecting Textdraws -
InfiniTy. - 15.11.2013
Quote:
Originally Posted by Konstantinos
-
|
Sorry.. i read it wrong.
Re: Detecting ESC Key while Selecting Textdraws -
||123|| - 15.11.2013
Quote:
Originally Posted by Konstantinos
It's still correct, both global and per-player textdraws call OnPlayerClickTextDraw for the ESC detection.
pawn Код:
public OnPlayerClickTextDraw( playerid, Text: clickedid ) { if( clickedid == Text: INVALID_TEXT_DRAW ) { PlayerTextDrawHide( playerid, ... ); // code.. return 1; } return 0; }
public OnPlayerClickPlayerTextDraw( playerid, PlayerText: playertextid ) { if( playertextid == ... ) { // code.. CancelSelectTextDraw( playerid ); } return 0; }
|
So how do I get it working. Can you please give me an example script. From what I understood from you, I'll have to use OnPlayerClickTextdraw under OnPlayerclickplayertextdraw in order to get it working?
Re: Detecting ESC Key while Selecting Textdraws -
Konstantinos - 15.11.2013
Quote:
Originally Posted by InfiniTy.
Sorry.. i read it wrong.
|
I read your post before editing it and we both said the same thing in different ways.
Quote:
Originally Posted by ||123||
So how do I get it working. Can you please give me an example script. From what I understood from you, I'll have to use OnPlayerClickTextdraw under OnPlayerclickplayertextdraw in order to get it working?
|
My above post contains an example. OnPlayerClickPlayerTextDraw will be called if the textdraw is A, you do the code and you call CancelSelectTextDraw function. That will call OnPlayerClickTextDraw callback with clickedid as INVALID_TEXT_DRAW. Then you check if the clickedid is equal to INVALID_TEXT_DRAW and that's when a player presses ESC with the textdraws. So you hide all the per-player textdraws you want.
Re: Detecting ESC Key while Selecting Textdraws -
||123|| - 15.11.2013
I'll have to make a command like /canceltextdraw for them to call the function then. But why would someone type /canceltextdraw if they can just press ESC key to exit textdraw. Any way to overcome this? Perhaps disable ESC key or something temporarily.
Re: Detecting ESC Key while Selecting Textdraws -
Pottus - 15.11.2013
You can make ESC re-open the textdraw, but then you need would need to set a variable to indicate that a player clicked the close textdraw.
Re: Detecting ESC Key while Selecting Textdraws -
||123|| - 16.11.2013
Quote:
Originally Posted by [uL]Pottus
You can make ESC re-open the textdraw, but then you need would need to set a variable to indicate that a player clicked the close textdraw.
|
When I try to use my textdraw variable on OnPlayerClickTextdraw callback, it says tag mismatch because my textdraw variable is playertext and not text. Can you please give me a script I can learn from, or make a short working code that does the same please? Thank you.
Re: Detecting ESC Key while Selecting Textdraws -
Pottus - 16.11.2013
Well first step is you need a control module which is very simple.
pawn Код:
// Textdraw control module
#define TEXTDRAW_NONE 0
new bool:TextDrawOpen[MAX_PLAYERS];
new CurrTextDraw[MAX_PLAYERS];
#define IsTextDrawOpen(%0) TextDrawOpen[%0]
#define SetCurrTextDraw(%0,%1) CurrTextDraw[%0] = %1
#define GetCurrTextDraw(%0) CurrTextDraw[%0]
hook OnPlayerDisconnect(playerid, reason)
{
SetCurrTextDraw(playerid, TEXTDRAW_NONE);
TextDrawOpen[playerid] = false;
return 1;
}
hook OnPlayerDisconnect(playerid, reason)
{
TextDrawOpen[playerid] = false;
return 1;
}
Here is the second part it basically a skeletal structure for your textdraws
pawn Код:
// Some textdraw
#include <YSI\y_hooks>
// We set a unique type this can be useful for checking what is open to
// prevent conflicts
#define TEXTDRAW_SOMETEXTDRAW 1
static Close[MAX_PLAYERS];
// Hooking callbacks is the easiest way to do this
hook OnPlayerClickTextDraw(playerid, Text:clickedid)
{
// Check if the textdraw is open
if(GetCurrTextDraw(playerid) == TEXTDRAW_SOMETEXTDRAW)
{
if(clickedid == INVALID_TEXTDRAW)
{
// Try and close by escape, select the textdraw
if(!Close[playerid]) SelectTextDraw(playerid, 0x00FF00FF);
// We can close the textdraw down now
else
{
// Clean up
Close[playerid] = false;
HideTextDraws(playerid);
// Textdraws are no longer open and there is no current textdraw
TextDrawOpen[playerid] = false;
SetCurrTextDraw(playerid, TEXTDRAW_NONE);
}
}
// Player clicked close
else if(clickedid == ClickClose)
{
Close[playerid] = true;
CancelSelectTextDraw(playerid);
}
}
return 1;
}
// Player clicked a player textdraw
hook OnPlayerClickTextDraw(playerid, Text:clickedid)
{
if(GetCurrTextDraw(playerid) == TEXTDRAW_SOMETEXTDRAW)
{
}
return 1;
}
// Create any normal textdraws here
hook OnGameModeInit(playerid)
{
return 1;
}
// Create any player textdraws here
hook OnPlayerConnect(playerid)
{
// Make sure close is set to false
Close[playerid] = false;
return 1;
}
// Hide any textdraws
static HideTextDraws(playerid)
{
return 1;
}
// Show any textdraws
static ShowTextDraws(playerid)
{
return 1;
}
// Command to open textdraw
CMD:opentd(playerid, arg[])
{
// Don't open textdraw if they are open
if(IsTextDrawOpen(playerid)) return 1;
TextDrawOpen[playerid] = true;
SetCurrTextDraw(playerid, TEXTDRAW_SOMETEXTDRAW);
return 1;
}
There is a few reason why we want to do it this way.
1.) Textdraws will never overlap which is so often the case with a lot of systems
2.) We have a modular approach here which is completely extensible for integrating any number of textdraw systems
3.) Includes order matters this creates a hierarchy where successive textdraws overlap previously created ones this gives us complete control over how textdraws interact with one another which is really ever so important.
4.) We've established some guidelines to go by which means two modules might do completely different tasks but the fundamental design never changes only the content of the design.
Re: Detecting ESC Key while Selecting Textdraws -
||123|| - 16.11.2013
Thanks alot Plottus. Although I didn't use your control module, I still learned a way of overcoming the problem. You deserve a rep, thanks.
EDIT: Tried to rep you but it says spread some reputation around before giving a rep to Pottus again :/ Sorry.