15.11.2013, 11:40
Is there a way I could detect when the player presses ESC key at selecting textdraws. Maybe a callback or something?
if(clickedid == Text:INVALID_TEXT_DRAW) {
//do stuff
}
SelectTextDraw(playerid, 0xFF0000FF);
PlayerInTDSelection[playerid] = true; //An example
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;
}
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.
|
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.
Under the OnPlayerClickTextDraw callback
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;
}
It's still correct, both global and per-player textdraws call OnPlayerClickTextDraw for the ESC detection.
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;
}
// 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;
}