SHOW:
|
|
- or go back to the newest paste.
| 1 | /* SA-MP Include GetText-Functions | |
| 2 | * | |
| 3 | * (c) by Kaliber, 2015 | |
| 4 | * | |
| 5 | */ | |
| 6 | #if !defined _samp_included | |
| 7 | #include <a_samp> | |
| 8 | #endif | |
| 9 | #if defined _samp_getText | |
| 10 | #endinput | |
| 11 | #endif | |
| 12 | #define _samp_getText | |
| 13 | #if !defined MAX_BUFFER | |
| 14 | #define MAX_BUFFER (128) | |
| 15 | #endif | |
| 16 | #if !defined MAX_TEXT | |
| 17 | #define MAX_TEXT (MAX_BUFFER * 4) | |
| 18 | #endif | |
| 19 | #define A:: e_T_ | |
| 20 | #define db_free db_free_result | |
| 21 | #define e_T_DATABASE ("TextDraws.db")
| |
| 22 | #define dbe(%0,%1) format(string,sizeof string,%0,%1),db_free(db_query(A::DB,string)) | |
| 23 | /* | |
| 24 | native TextDrawGetText(Text:id); | |
| 25 | native PlayerTextDrawGetText(PlayerText:id); | |
| 26 | */ | |
| 27 | #if defined FILTERSCRIPT | |
| 28 | forward A::OnFilterScriptInit(); | |
| 29 | forward A::OnFilterScriptExit(); | |
| 30 | #else | |
| 31 | forward A::OnGameModeInit(); | |
| 32 | forward A::OnGameModeExit(); | |
| 33 | #endif | |
| 34 | native Text:A::TextDrawCreate(Float:x, Float:y, text[]) = TextDrawCreate; | |
| 35 | native A::TextDrawSetString(Text:text, string[]) = TextDrawSetString; | |
| 36 | native A::TextDrawDestroy(Text:text) = TextDrawDestroy; | |
| 37 | ||
| 38 | native PlayerText:A::CreatePlayerTextDraw(playerid,Float:x, Float:y, text[]) = CreatePlayerTextDraw; | |
| 39 | native A::PlayerTextDrawSetString(playerid, PlayerText:text, string[]) = PlayerTextDrawSetString; | |
| 40 | native A::PlayerTextDrawDestroy(playerid, PlayerText:text) = PlayerTextDrawDestroy; | |
| 41 | ||
| 42 | static DB:A::DB; | |
| 43 | ||
| 44 | stock TextDrawGetText(Text:id) {
| |
| 45 | static string[MAX_BUFFER] = "NaN",DBResult:result; | |
| 46 | format(string,MAX_BUFFER,"SELECT `text` FROM `TextDraw` WHERE `flag`='%d' AND `x`='0'",_:id); | |
| 47 | result = db_query(A::DB,string),db_get_field(result,0,string,MAX_BUFFER),db_free(result); | |
| 48 | return string; | |
| 49 | } | |
| 50 | stock PlayerTextDrawGetText(PlayerText:id) {
| |
| 51 | static string[MAX_BUFFER] = "NaN",DBResult:result; | |
| 52 | format(string,MAX_BUFFER,"SELECT `text` FROM `TextDraw` WHERE `flag`='%d' AND `x`='1'",_:id); | |
| 53 | result = db_query(A::DB,string),db_get_field(result,0,string,MAX_BUFFER),db_free(result); | |
| 54 | return string; | |
| 55 | } | |
| 56 | stock Text:_TextDrawCreate(Float:x, Float:y, text[]) {
| |
| 57 | new tmp = _:A::TextDrawCreate(x,y,text),string[MAX_TEXT]; | |
| 58 | dbe("INSERT INTO `TextDraw` ('flag','x','text') VALUES ('%d','0','%s')",tmp,text);
| |
| 59 | return Text:tmp; | |
| 60 | } | |
| 61 | #if defined _ALS_TextDrawCreate | |
| 62 | #undef TextDrawCreate | |
| 63 | #else | |
| 64 | #define _ALS_TextDrawCreate | |
| 65 | #endif | |
| 66 | #define TextDrawCreate _TextDrawCreate | |
| 67 | stock PlayerText:_CreatePlayerTextDraw(playerid, Float:x, Float:y, text[]) {
| |
| 68 | if(!IsPlayerConnected(playerid)) return PlayerText:INVALID_TEXT_DRAW; | |
| 69 | new tmp = _:A::CreatePlayerTextDraw(playerid,x,y,text),string[MAX_TEXT]; | |
| 70 | dbe("INSERT INTO `TextDraw` ('flag','x','text') VALUES ('%d','1','%s')",tmp,text);
| |
| 71 | return PlayerText:tmp; | |
| 72 | } | |
| 73 | #if defined _ALS_CreatePlayerTextDraw | |
| 74 | #undef CreatePlayerTextDraw | |
| 75 | #else | |
| 76 | #define _ALS_CreatePlayerTextDraw | |
| 77 | #endif | |
| 78 | #define CreatePlayerTextDraw _CreatePlayerTextDraw | |
| 79 | stock _TextDrawSetString(Text:text, tmp[]) {
| |
| 80 | static string[MAX_TEXT]; | |
| 81 | dbe("UPDATE `TextDraw` SET `text`='%s' WHERE `flag`='%d' AND `x`='0'",tmp,_:text);
| |
| 82 | return A::TextDrawSetString(text,tmp); | |
| 83 | } | |
| 84 | #if defined _ALS_TextDrawSetString | |
| 85 | #undef TextDrawSetString | |
| 86 | #else | |
| 87 | #define _ALS_TextDrawSetString | |
| 88 | #endif | |
| 89 | #define TextDrawSetString _TextDrawSetString | |
| 90 | stock _PlayerTextDrawSetString(playerid, PlayerText:text, tmp[]) {
| |
| 91 | static string[MAX_TEXT]; | |
| 92 | dbe("UPDATE `TextDraw` SET `text`='%s' WHERE `flag`='%d' AND `x`='1'",tmp,_:text);
| |
| 93 | return A::PlayerTextDrawSetString(playerid,text,tmp); | |
| 94 | } | |
| 95 | #if defined _ALS_PlayerTextDrawSetString | |
| 96 | #undef PlayerTextDrawSetString | |
| 97 | #else | |
| 98 | #define _ALS_PlayerTextDrawSetString | |
| 99 | #endif | |
| 100 | #define PlayerTextDrawSetString _PlayerTextDrawSetString | |
| 101 | stock _PlayerTextDrawDestroy(playerid, PlayerText:text) {
| |
| 102 | static string[MAX_BUFFER]; | |
| 103 | dbe("DELETE FROM `TextDraw` WHERE `flag`='%d' AND `x`='1'",_:text);
| |
| 104 | return A::PlayerTextDrawDestroy(playerid,text); | |
| 105 | } | |
| 106 | #if defined _ALS_PlayerTextDrawDestroy | |
| 107 | #undef PlayerTextDrawDestroy | |
| 108 | #else | |
| 109 | #define _ALS_PlayerTextDrawDestroy | |
| 110 | #endif | |
| 111 | #define PlayerTextDrawDestroy _PlayerTextDrawDestroy | |
| 112 | stock _TextDrawDestroy(Text:text) {
| |
| 113 | static string[MAX_BUFFER]; | |
| 114 | dbe("DELETE FROM `TextDraw` WHERE `flag`='%d' AND `x`='0'",_:text);
| |
| 115 | return A::TextDrawDestroy(text); | |
| 116 | } | |
| 117 | #if defined _ALS_TextDrawDestroy | |
| 118 | #undef TextDrawDestroy | |
| 119 | #else | |
| 120 | #define _ALS_TextDrawDestroy | |
| 121 | #endif | |
| 122 | #define TextDrawDestroy _TextDrawDestroy | |
| 123 | ||
| 124 | #if defined FILTERSCRIPT | |
| 125 | public OnFilterScriptInit() {
| |
| 126 | if(fexist(A::DATABASE)) fremove(A::DATABASE); | |
| 127 | A::DB = db_open(A::DATABASE); | |
| 128 | db_free(db_query(A::DB,"CREATE TABLE IF NOT EXISTS `TextDraw` (`flag`,`x`,`text`)")); | |
| 129 | return CallLocalFunction("e_T_OnFilterScriptInit","");
| |
| 130 | } | |
| 131 | #if defined _ALS_OnFilterScriptInit | |
| 132 | #undef OnFilterScriptInit | |
| 133 | #else | |
| 134 | #define _ALS_OnFilterScriptInit | |
| 135 | #endif | |
| 136 | #define OnFilterScriptInit e_T_OnFilterScriptInit | |
| 137 | public OnFilterScriptExit() {
| |
| 138 | db_close(A::DB); | |
| 139 | return CallLocalFunction("e_T_OnFilterScriptExit","");
| |
| 140 | } | |
| 141 | #if defined _ALS_OnFilterScriptExit | |
| 142 | #undef OnFilterScriptExit | |
| 143 | #else | |
| 144 | #define _ALS_OnFilterScriptExit | |
| 145 | #endif | |
| 146 | #define OnFilterScriptExit e_T_OnFilterScriptExit | |
| 147 | #else | |
| 148 | public OnGameModeInit() {
| |
| 149 | if(fexist(A::DATABASE)) fremove(A::DATABASE); | |
| 150 | A::DB = db_open(A::DATABASE); | |
| 151 | db_free(db_query(A::DB,"CREATE TABLE IF NOT EXISTS `TextDraw` (`flag`,`x`,`text`)")); | |
| 152 | return CallLocalFunction("e_T_OnGameModeInit","");
| |
| 153 | } | |
| 154 | #if defined _ALS_OnGameModeInit | |
| 155 | #undef OnGameModeInit | |
| 156 | #else | |
| 157 | #define _ALS_OnGameModeInit | |
| 158 | #endif | |
| 159 | #define OnGameModeInit e_T_OnGameModeInit | |
| 160 | public OnGameModeExit() {
| |
| 161 | db_close(A::DB); | |
| 162 | return CallLocalFunction("e_T_OnGameModeExit","");
| |
| 163 | } | |
| 164 | #if defined _ALS_OnGameModeExit | |
| 165 | #undef OnGameModeExit | |
| 166 | #else | |
| 167 | #define _ALS_OnGameModeExit | |
| 168 | #endif | |
| 169 | #define OnGameModeExit e_T_OnGameModeExit | |
| 170 | #endif |