|
| 1 | +
|
| 2 | +
|
| 3 | +/* |
| 4 | +
|
| 5 | + ooooo ooo .o. ooooooooooooo ooooo oooooo oooo .o. .oooooo..o |
| 6 | + `888b. `8' .888. 8' 888 `8 `888' `888. .8' .888. d8P' `Y8 |
| 7 | + 8 `88b. 8 .8"888. 888 888 `888. .8' .8"888. Y88bo. |
| 8 | + 8 `88b. 8 .8' `888. 888 888 `888. .8' .8' `888. `"Y8888o. |
| 9 | + 8 `88b.8 .88ooo8888. 888 888 `888.8' .88ooo8888. `"Y88b |
| 10 | + 8 `888 .8' `888. 888 888 `888' .8' `888. oo .d8P |
| 11 | + o8o `8 o88o o8888o o888o o888o `8' o88o o8888o 8""88888P' |
| 12 | +
|
| 13 | +
|
| 14 | + native CreatePlayerCircleProgress(playerid, Float:pos_x, Float:pos_y, color = 0xFF0000FF, background_COLOR = 0x000000FF, Float:size = 10.0, Float:thickness = 0.2, polygons = DEFAULT_CIRCLE_POLYGONS); |
| 15 | + native UpdatePlayerCircleProgress(playerid, id, value); |
| 16 | + native DestroyPlayerCircleProgress(playerid, id); |
| 17 | + native DestroyPlayerCircleProgressAll(playerid); |
| 18 | + |
| 19 | +*/ |
| 20 | +
|
| 21 | +
|
| 22 | + // Definers |
| 23 | +#define DEFAULT_CIRCLE_POLYGONS (15.0) // If you want quality, use 3.0. |
| 24 | +#define MAX_CIRCLES_POLYGONS (120) |
| 25 | +#define MAX_CIRCLES_DRAW (10) |
| 26 | +// The smaller the number, the more defined the circle will be. I recommend using 15.0 to support more circles and textdraws without exceeding the limit imposed by SAMP. |
| 27 | +
|
| 28 | + // Includes |
| 29 | +#include <YSI_Coding\y_hooks> |
| 30 | +#include <YSI_Data\y_iterate> |
| 31 | +
|
| 32 | +static enum CIRCLE_ENUM { |
| 33 | +
|
| 34 | + // Config |
| 35 | + Float:E_CIRCLEDRAW_POSITION[2], |
| 36 | + Float:E_CIRCLEDRAW_THICKNESS, |
| 37 | + Float:E_CIRCLEDRAW_SIZE, |
| 38 | + Float:E_CIRCLEDRAW_VALUE, |
| 39 | + Float:E_CIRCLEDRAW_POLYGONS, |
| 40 | +
|
| 41 | + // Colors |
| 42 | + E_CIRCLEDRAW_COLOR, |
| 43 | + E_CIRCLEDRAW_BACKGROUND, |
| 44 | +
|
| 45 | + // Draws |
| 46 | + PlayerText:E_CIRCLEDRAW_POINTS[MAX_CIRCLES_POLYGONS + 1] |
| 47 | +}; |
| 48 | +
|
| 49 | +static |
| 50 | + Iterator:Circles[MAX_PLAYERS]<MAX_CIRCLES_DRAW>, |
| 51 | + Iterator:CirclesPointers[MAX_PLAYERS]<MAX_CIRCLES_DRAW, MAX_CIRCLES_POLYGONS>; |
| 52 | +
|
| 53 | +static |
| 54 | + e_CircleDraw[MAX_PLAYERS][MAX_CIRCLES_DRAW][CIRCLE_ENUM]; |
| 55 | +
|
| 56 | +
|
| 57 | +
|
| 58 | +/* |
| 59 | +
|
| 60 | + ooooooooo. ooooo ooo oooooooooo. ooooo ooooo .oooooo. |
| 61 | + `888 `Y88. `888' `8' `888' `Y8b `888' `888' d8P' `Y8b |
| 62 | + 888 .d88' 888 8 888 888 888 888 888 |
| 63 | + 888ooo88P' 888 8 888oooo888' 888 888 888 |
| 64 | + 888 888 8 888 `88b 888 888 888 |
| 65 | + 888 `88. .8' 888 .88P 888 o 888 `88b ooo |
| 66 | + o888o `YbodP' o888bood8P' o888ooooood8 o888o `Y8bood8P' |
| 67 | +
|
| 68 | +*/ |
| 69 | +
|
| 70 | +hook OnPlayerDisconnect(playerid, reason) { |
| 71 | +
|
| 72 | + DestroyPlayerCircleProgressAll(playerid); // Invalid All [Not Required if you use Streamertextdraw :)] |
| 73 | + return Y_HOOKS_CONTINUE_RETURN_1; |
| 74 | +} |
| 75 | +
|
| 76 | +
|
| 77 | +
|
| 78 | +/* |
| 79 | +
|
| 80 | + .oooooo..o ooooooooooooo .oooooo. .oooooo. oooo oooo .oooooo..o |
| 81 | + d8P' `Y8 8' 888 `8 d8P' `Y8b d8P' `Y8b `888 .8P' d8P' `Y8 |
| 82 | + Y88bo. 888 888 888 888 888 d8' Y88bo. |
| 83 | + `"Y8888o. 888 888 888 888 88888[ `"Y8888o. |
| 84 | + `"Y88b 888 888 888 888 888`88b. `"Y88b |
| 85 | + oo .d8P 888 `88b d88' `88b ooo 888 `88b. oo .d8P |
| 86 | + 8""88888P' o888o `Y8bood8P' `Y8bood8P' o888o o888o 8""88888P' |
| 87 | +
|
| 88 | +*/ |
| 89 | +
|
| 90 | +stock ctd(Float:angle, Float:distance, Float:sx, Float:sy, &Float:x, &Float:y) { |
| 91 | + x = sx + (distance * floatsin(-angle, degrees)); |
| 92 | + y = sy + (distance * floatcos(angle, degrees)); |
| 93 | + return true; |
| 94 | +} |
| 95 | +
|
| 96 | +stock DestroyPlayerCircleProgressAll(playerid) { |
| 97 | +
|
| 98 | + foreach(new i: Circles[playerid]) |
| 99 | + DestroyPlayerCircleProgress(playerid, i); |
| 100 | +
|
| 101 | + return true; |
| 102 | +} |
| 103 | +
|
| 104 | +stock DestroyPlayerCircleProgress(playerid, id) { |
| 105 | + |
| 106 | + if(!Iter_Contains(Circles[playerid], id)) |
| 107 | + return false; |
| 108 | +
|
| 109 | + foreach(new i: CirclesPointers[playerid]<id>) { |
| 110 | + PlayerTextDrawDestroy(playerid, e_CircleDraw[playerid][id][E_CIRCLEDRAW_POINTS][i]); |
| 111 | + e_CircleDraw[playerid][id][E_CIRCLEDRAW_POINTS][i] = PlayerText:INVALID_TEXT_DRAW; |
| 112 | +
|
| 113 | + Iter_Remove(CirclesPointers[playerid]<id>, i); |
| 114 | + } |
| 115 | +
|
| 116 | + Iter_Remove(Circles[playerid], id); |
| 117 | +
|
| 118 | + new dsadsa[CIRCLE_ENUM]; |
| 119 | + e_CircleDraw[playerid][id] = dsadsa; |
| 120 | + return true; |
| 121 | +} |
| 122 | +
|
| 123 | +stock CreatePlayerCircleProgress(playerid, Float:pos_x, Float:pos_y, color = 0xFF0000FF, background_COLOR = 0x000000FF, Float:size = 10.0, Float:thickness = 0.2, Float:polygons = DEFAULT_CIRCLE_POLYGONS) { |
| 124 | + |
| 125 | + new index = Iter_Free(Circles[playerid]); |
| 126 | + if(index == -1) return -1; |
| 127 | +
|
| 128 | + /* Config */ |
| 129 | + e_CircleDraw[playerid][index][E_CIRCLEDRAW_THICKNESS] = thickness; |
| 130 | + e_CircleDraw[playerid][index][E_CIRCLEDRAW_COLOR] = color; |
| 131 | + e_CircleDraw[playerid][index][E_CIRCLEDRAW_BACKGROUND] = background_COLOR; |
| 132 | + e_CircleDraw[playerid][index][E_CIRCLEDRAW_SIZE] = size; |
| 133 | + e_CircleDraw[playerid][index][E_CIRCLEDRAW_POSITION][0] = pos_x; |
| 134 | + e_CircleDraw[playerid][index][E_CIRCLEDRAW_POSITION][1] = pos_y; |
| 135 | + e_CircleDraw[playerid][index][E_CIRCLEDRAW_VALUE] = -1.0; // Prevent Bugs |
| 136 | + e_CircleDraw[playerid][index][E_CIRCLEDRAW_POLYGONS] = polygons; |
| 137 | +
|
| 138 | + Iter_Add(Circles[playerid], index); |
| 139 | + UpdatePlayerCircleProgress(playerid, index, 100); |
| 140 | + return index; |
| 141 | +} |
| 142 | +
|
| 143 | +stock UpdatePlayerCircleProgress(playerid, id, value) { |
| 144 | + |
| 145 | + if(e_CircleDraw[playerid][id][E_CIRCLEDRAW_VALUE] == value) |
| 146 | + return true; |
| 147 | +
|
| 148 | + new |
| 149 | + Float:preValue = e_CircleDraw[playerid][id][E_CIRCLEDRAW_POLYGONS], |
| 150 | + Float:x, |
| 151 | + Float:y, |
| 152 | + preDraws, |
| 153 | + percent, |
| 154 | + index; |
| 155 | +
|
| 156 | + for(new Float:v = 0.0; v < 360.0; v += preValue) |
| 157 | + preDraws++; |
| 158 | +
|
| 159 | + /* Prevent and Fix Values */ |
| 160 | + value = value < 0 ? 0 : value; |
| 161 | + value = value > 100 ? 100 : value; |
| 162 | +
|
| 163 | + /* Color Fade? */ |
| 164 | + percent = (preDraws * value) / 100; |
| 165 | +
|
| 166 | + /* Update and Create Points */ |
| 167 | + for(new Float:v = 0.0; v < 360.0; v += preValue) { |
| 168 | + ctd(v + 180.0, e_CircleDraw[playerid][id][E_CIRCLEDRAW_SIZE], e_CircleDraw[playerid][id][E_CIRCLEDRAW_POSITION][0], e_CircleDraw[playerid][id][E_CIRCLEDRAW_POSITION][1], x, y); |
| 169 | +
|
| 170 | + if(!Iter_Contains(CirclesPointers[playerid]<id>, index)) { |
| 171 | + e_CircleDraw[playerid][id][E_CIRCLEDRAW_POINTS][index] = CreatePlayerTextDraw(playerid, x, y, "."); |
| 172 | + PlayerTextDrawAlignment(playerid, e_CircleDraw[playerid][id][E_CIRCLEDRAW_POINTS][index], 2); |
| 173 | + PlayerTextDrawLetterSize(playerid, e_CircleDraw[playerid][id][E_CIRCLEDRAW_POINTS][index], e_CircleDraw[playerid][id][E_CIRCLEDRAW_THICKNESS], e_CircleDraw[playerid][id][E_CIRCLEDRAW_THICKNESS] + (e_CircleDraw[playerid][id][E_CIRCLEDRAW_THICKNESS] * 2)); |
| 174 | + PlayerTextDrawSetShadow(playerid, e_CircleDraw[playerid][id][E_CIRCLEDRAW_POINTS][index], 0); |
| 175 | +
|
| 176 | + Iter_Add(CirclesPointers[playerid]<id>, index); |
| 177 | + } |
| 178 | +
|
| 179 | + PlayerTextDrawColor(playerid, e_CircleDraw[playerid][id][E_CIRCLEDRAW_POINTS][index], percent <= index ? (e_CircleDraw[playerid][id][E_CIRCLEDRAW_BACKGROUND]) : (e_CircleDraw[playerid][id][E_CIRCLEDRAW_COLOR])); |
| 180 | + index++; |
| 181 | + } |
| 182 | +
|
| 183 | + /* Security Update */ |
| 184 | + e_CircleDraw[playerid][id][E_CIRCLEDRAW_VALUE] = value; |
| 185 | + |
| 186 | + /* Update */ |
| 187 | + foreach(new i: CirclesPointers[playerid]<id>) |
| 188 | + PlayerTextDrawShow(playerid, e_CircleDraw[playerid][id][E_CIRCLEDRAW_POINTS][i]); |
| 189 | + |
| 190 | + return true; |
| 191 | +} |
0 commit comments