Detecting ESC Key while Selecting Textdraws
#1

Is there a way I could detect when the player presses ESC key at selecting textdraws. Maybe a callback or something?
Reply
#2

I think it's not possible.
Reply
#3

It is but idk how
Reply
#4

Under the OnPlayerClickTextDraw callback

pawn Код:
if(clickedid == Text:INVALID_TEXT_DRAW) {
   //do stuff
}
Reply
#5

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.
Reply
#6

Doesn't work. It's not getting called. It should get called when I cancel the textdraw selection mode using ESC Key.
Reply
#7

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.
Reply
#8

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.
Reply
#9

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;
}
Reply
#10

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
-
Sorry.. i read it wrong.
Reply
#11

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?
Reply
#12

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.
Reply
#13

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.
Reply
#14

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.
Reply
#15

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.
Reply
#16

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.
Reply
#17

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)