SHOW:
|
|
- or go back to the newest paste.
| 1 | - | /*VISITE NOSSO SITE: http://www.sampknd.com/ |
| 1 | + | /*VISITE NOSSO SITE: www.total-samp.com.br/ |
| 2 | - | SAMP KND MELHOR BLOG DE SAMP DO BRASIL |
| 2 | + | TOTAL SAMP MELHOR BLOG DE SAMP DO BRASIL |
| 3 | */ | |
| 4 | ||
| 5 | #if defined _progress_included | |
| 6 | #endinput | |
| 7 | #endif | |
| 8 | ||
| 9 | #if !defined _samp_included | |
| 10 | #tryinclude <a_samp> | |
| 11 | #if !defined _samp_included | |
| 12 | #error could not locate a_samp.inc file, please check your server includes | |
| 13 | #endif | |
| 14 | #endif | |
| 15 | ||
| 16 | #tryinclude <foreach> | |
| 17 | ||
| 18 | #define _progress_included | |
| 19 | #define _progress_version 0x1310 | |
| 20 | ||
| 21 | #define MAX_BARS (MAX_TEXT_DRAWS / 3) | |
| 22 | #define INVALID_BAR_VALUE (Float:0xFFFFFFFF) | |
| 23 | #define INVALID_BAR_ID (Bar:-1) | |
| 24 | #define pb_percent(%1,%2,%3,%4) ((%1 - 6.0) + ((((%1 + 6.0 + %2 - 2.0) - %1) / %3) * %4)) | |
| 25 | //pb_percent(x, width, max, value) | |
| 26 | ||
| 27 | /* Pawno/Infernus Pawn Editor function list | |
| 28 | native Bar:CreateProgressBar(Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0); | |
| 29 | native DestroyProgressBar(Bar:barid); | |
| 30 | native ShowProgressBarForPlayer(playerid, Bar:barid); | |
| 31 | native HideProgressBarForPlayer(playerid, Bar:barid); | |
| 32 | native ShowProgressBarForAll(Bar:barid); | |
| 33 | native HideProgressBarForAll(Bar:barid); | |
| 34 | native SetProgressBarValue(Bar:barid, Float:value); | |
| 35 | native Float:GetProgressBarValue(Bar:barid); | |
| 36 | native SetProgressBarMaxValue(Bar:barid, Float:max); | |
| 37 | native SetProgressBarColor(Bar:barid, color); | |
| 38 | native UpdateProgressBar(Bar:barid, playerid=INVALID_PLAYER_ID); | |
| 39 | */ | |
| 40 | ||
| 41 | forward Bar:CreateProgressBar(Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0); | |
| 42 | forward Float:GetProgressBarValue(Bar:barid); | |
| 43 | ||
| 44 | enum e_bar | |
| 45 | {
| |
| 46 | Float:pb_x, | |
| 47 | Float:pb_y, | |
| 48 | Float:pb_w, | |
| 49 | Float:pb_h, | |
| 50 | Float:pb_m, | |
| 51 | Float:pb_v, | |
| 52 | Text:pb_t1, | |
| 53 | Text:pb_t2, | |
| 54 | Text:pb_t3, | |
| 55 | pb_color, | |
| 56 | bool:pb_created | |
| 57 | } | |
| 58 | ||
| 59 | static Bars[MAX_BARS][e_bar]; | |
| 60 | ||
| 61 | stock Bar:CreateProgressBar(Float:x, Float:y, Float:width=55.5, Float:height=3.2, color, Float:max=100.0) | |
| 62 | {
| |
| 63 | new | |
| 64 | barid; | |
| 65 | ||
| 66 | for(barid = 0; barid < sizeof Bars; ++barid) | |
| 67 | if(!Bars[barid][pb_created]) break; | |
| 68 | ||
| 69 | if(Bars[barid][pb_created] || barid == sizeof Bars) | |
| 70 | return INVALID_BAR_ID; | |
| 71 | ||
| 72 | new Text:in_t = Bars[barid][pb_t1] = TextDrawCreate(x, y, "_"); | |
| 73 | TextDrawUseBox (in_t, 1); | |
| 74 | TextDrawTextSize (in_t, x + width, 0.0); | |
| 75 | TextDrawLetterSize (in_t, 1.0, height / 10); | |
| 76 | TextDrawBoxColor (in_t, 0x00000000 | (color & 0x000000FF)); | |
| 77 | ||
| 78 | in_t = Bars[barid][pb_t2] = TextDrawCreate(x + 1.2, y + 2.15, "_"); | |
| 79 | TextDrawUseBox (in_t, 1); | |
| 80 | TextDrawTextSize (in_t, x + width - 2.0, 0.0); | |
| 81 | TextDrawLetterSize (in_t, 1.0, height / 10 - 0.35); | |
| 82 | TextDrawBoxColor (in_t, (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2))); | |
| 83 | ||
| 84 | in_t = Bars[barid][pb_t3] = TextDrawCreate(x + 1.2, y + 2.15, "_"); | |
| 85 | TextDrawTextSize (in_t, pb_percent(x, width, max, 1.0), 0.0); | |
| 86 | TextDrawLetterSize (in_t, 1.0, height / 10 - 0.35); | |
| 87 | TextDrawBoxColor (in_t, color); | |
| 88 | ||
| 89 | Bars[barid][pb_x] = x; | |
| 90 | Bars[barid][pb_y] = y; | |
| 91 | Bars[barid][pb_w] = width; | |
| 92 | Bars[barid][pb_h] = height; | |
| 93 | Bars[barid][pb_m] = max; | |
| 94 | Bars[barid][pb_color] = color; | |
| 95 | Bars[barid][pb_created] = true; | |
| 96 | return Bar:barid; | |
| 97 | } | |
| 98 | ||
| 99 | stock DestroyProgressBar(Bar:barid) | |
| 100 | {
| |
| 101 | if(barid != INVALID_BAR_ID && Bar:-1 < barid < Bar:MAX_BARS) | |
| 102 | {
| |
| 103 | if(!Bars[_:barid][pb_created]) | |
| 104 | return 0; | |
| 105 | ||
| 106 | TextDrawDestroy(Bars[_:barid][pb_t1]); | |
| 107 | TextDrawDestroy(Bars[_:barid][pb_t2]); | |
| 108 | TextDrawDestroy(Bars[_:barid][pb_t3]); | |
| 109 | ||
| 110 | Bars[_:barid][pb_t1] = Text:0; | |
| 111 | Bars[_:barid][pb_t2] = Text:0; | |
| 112 | Bars[_:barid][pb_t3] = Text:0; | |
| 113 | Bars[_:barid][pb_x] = 0.0; | |
| 114 | Bars[_:barid][pb_y] = 0.0; | |
| 115 | Bars[_:barid][pb_w] = 0.0; | |
| 116 | Bars[_:barid][pb_h] = 0.0; | |
| 117 | Bars[_:barid][pb_m] = 0.0; | |
| 118 | Bars[_:barid][pb_v] = 0.0; | |
| 119 | Bars[_:barid][pb_color] = 0; | |
| 120 | Bars[_:barid][pb_created] = false; | |
| 121 | return 1; | |
| 122 | } | |
| 123 | return 0; | |
| 124 | } | |
| 125 | ||
| 126 | stock ShowProgressBarForPlayer(playerid, Bar:barid) | |
| 127 | {
| |
| 128 | if(IsPlayerConnected(playerid) && barid != INVALID_BAR_ID && Bar:-1 < barid < Bar:MAX_BARS) | |
| 129 | {
| |
| 130 | if(!Bars[_:barid][pb_created]) | |
| 131 | return 0; | |
| 132 | ||
| 133 | TextDrawShowForPlayer(playerid, Bars[_:barid][pb_t1]); | |
| 134 | TextDrawShowForPlayer(playerid, Bars[_:barid][pb_t2]); | |
| 135 | TextDrawShowForPlayer(playerid, Bars[_:barid][pb_t3]); | |
| 136 | return 1; | |
| 137 | } | |
| 138 | return 0; | |
| 139 | } | |
| 140 | ||
| 141 | stock HideProgressBarForPlayer(playerid, Bar:barid) | |
| 142 | {
| |
| 143 | if(IsPlayerConnected(playerid) && barid != INVALID_BAR_ID && Bar:-1 < barid < Bar:MAX_BARS) | |
| 144 | {
| |
| 145 | if(!Bars[_:barid][pb_created]) | |
| 146 | return 0; | |
| 147 | ||
| 148 | TextDrawHideForPlayer(playerid, Bars[_:barid][pb_t1]); | |
| 149 | TextDrawHideForPlayer(playerid, Bars[_:barid][pb_t2]); | |
| 150 | TextDrawHideForPlayer(playerid, Bars[_:barid][pb_t3]); | |
| 151 | return 1; | |
| 152 | } | |
| 153 | return 0; | |
| 154 | } | |
| 155 | ||
| 156 | stock SetProgressBarValue(Bar:barid, Float:value) | |
| 157 | {
| |
| 158 | if(barid == INVALID_BAR_ID || Bar:MAX_BARS < barid < Bar:-1) | |
| 159 | return 0; | |
| 160 | ||
| 161 | if(Bars[_:barid][pb_created]) | |
| 162 | {
| |
| 163 | value = | |
| 164 | (value < 0.0) ? (0.0) : (value > Bars[_:barid][pb_m]) ? (Bars[_:barid][pb_m]) : (value); | |
| 165 | ||
| 166 | TextDrawUseBox(Bars[_:barid][pb_t3], value > 0.0); | |
| 167 | ||
| 168 | Bars[_:barid][pb_v] = value; | |
| 169 | ||
| 170 | TextDrawTextSize(Bars[_:barid][pb_t3], | |
| 171 | pb_percent(Bars[_:barid][pb_x], Bars[_:barid][pb_w], Bars[_:barid][pb_m], value), 0.0); | |
| 172 | ||
| 173 | return 1; | |
| 174 | } | |
| 175 | return 0; | |
| 176 | } | |
| 177 | ||
| 178 | stock Float:GetProgressBarValue(Bar:barid) | |
| 179 | {
| |
| 180 | if(barid == INVALID_BAR_ID || Bar:MAX_BARS < barid < Bar:-1) | |
| 181 | return INVALID_BAR_VALUE; | |
| 182 | ||
| 183 | if(Bars[_:barid][pb_created]) | |
| 184 | return Bars[_:barid][pb_v]; | |
| 185 | ||
| 186 | return INVALID_BAR_VALUE; | |
| 187 | } | |
| 188 | ||
| 189 | stock SetProgressBarMaxValue(Bar:barid, Float:max) | |
| 190 | {
| |
| 191 | if(barid == INVALID_BAR_ID || Bar:MAX_BARS < barid < Bar:-1) | |
| 192 | return 0; | |
| 193 | ||
| 194 | if(Bars[_:barid][pb_created]) | |
| 195 | {
| |
| 196 | Bars[_:barid][pb_m] = max; | |
| 197 | SetProgressBarValue(barid, Bars[_:barid][pb_v]); | |
| 198 | return 1; | |
| 199 | } | |
| 200 | return 0; | |
| 201 | } | |
| 202 | ||
| 203 | stock SetProgressBarColor(Bar:barid, color) | |
| 204 | {
| |
| 205 | if(barid == INVALID_BAR_ID || Bar:MAX_BARS < barid < Bar:-1) | |
| 206 | return 0; | |
| 207 | ||
| 208 | if(Bars[_:barid][pb_created]) | |
| 209 | {
| |
| 210 | Bars[_:barid][pb_color] = color; | |
| 211 | TextDrawBoxColor(Bars[_:barid][pb_t1], 0x00000000 | (color & 0x000000FF)); | |
| 212 | ||
| 213 | TextDrawBoxColor(Bars[_:barid][pb_t2], | |
| 214 | (color & 0xFFFFFF00) | (0x66 & ((color & 0x000000FF) / 2))); | |
| 215 | ||
| 216 | TextDrawBoxColor(Bars[_:barid][pb_t3], color); | |
| 217 | return 1; | |
| 218 | } | |
| 219 | return 0; | |
| 220 | } | |
| 221 | ||
| 222 | stock ShowProgressBarForAll(Bar:barid) | |
| 223 | {
| |
| 224 | #if defined _foreach_included | |
| 225 | foreach(Player, i) | |
| 226 | #else | |
| 227 | for(new i = 0; i < MAX_PLAYERS; ++i) | |
| 228 | if(IsPlayerConnected(i)) | |
| 229 | #endif | |
| 230 | #if defined IsPlayerNPC | |
| 231 | if(!IsPlayerNPC(i)) | |
| 232 | #endif | |
| 233 | {
| |
| 234 | ShowProgressBarForPlayer(i, barid); | |
| 235 | } | |
| 236 | return 1; | |
| 237 | } | |
| 238 | ||
| 239 | stock HideProgressBarForAll(Bar:barid) | |
| 240 | {
| |
| 241 | #if defined _foreach_included | |
| 242 | foreach(Player, i) | |
| 243 | #else | |
| 244 | for(new i = 0; i < MAX_PLAYERS; ++i) | |
| 245 | if(IsPlayerConnected(i)) | |
| 246 | #endif | |
| 247 | #if defined IsPlayerNPC | |
| 248 | if(!IsPlayerNPC(i)) | |
| 249 | #endif | |
| 250 | {
| |
| 251 | HideProgressBarForPlayer(i, barid); | |
| 252 | } | |
| 253 | return 1; | |
| 254 | } | |
| 255 | ||
| 256 | stock UpdateProgressBar(Bar:barid, playerid=INVALID_PLAYER_ID) | |
| 257 | {
| |
| 258 | if(playerid == INVALID_PLAYER_ID) | |
| 259 | {
| |
| 260 | return ShowProgressBarForAll(barid); | |
| 261 | } else {
| |
| 262 | return ShowProgressBarForPlayer(playerid, barid); | |
| 263 | } |