16.11.2013, 00:50
Well first step is you need a control module which is very simple.
Here is the second part it basically a skeletal structure for your textdraws
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.
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;
}
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;
}
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.