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