AMXX-BG.INFO colorstatus.inc Raw include

colorstatus.inc

Original include source with line numbers.

Back Download .inc
1 /* ColorStatus
2 *
3 * by DarkGL
4 *
5 * This file is provided as is (no warranties).
6 */
7
8 #define STATUS_TASK 486784986
9 #define STATUS_TASK2 471231345
10 #define TO_NAME "%"
11
12 enum COLOR_STATUS{
13 RED_STATUS,
14 BLUE_STATUS,
15 YELLOW_STATUS,
16 GREY_STATUS
17 }
18
19
20 new msgStatusText;
21 new msgStatusValue;
22 new msgSayText;
23
24 //prefix _colorStatus_
25
26 new oldName[33][64],oldTeam[33],MSG_TYPE[33],bool:bChangedNick[33],Float:fTimeColor[33];
27
28 stock initColorStatus(){
29 register_forward(FM_ClientUserInfoChanged,"fw_ColorUserInfoChanged");
30
31 msgStatusText = get_user_msgid("StatusText");
32 msgStatusValue = get_user_msgid("StatusValue");
33 msgSayText = get_user_msgid("SayText");
34
35 register_message(get_user_msgid("StatusText"),"ColorStatusText");
36 register_message(get_user_msgid("StatusValue"),"ColorStatusValue");
37 }
38
39 public ColorStatusText(msgID, msgDest,msgEnt){
40 if(!msgEnt || msgDest == MSG_ALL){
41
42 new Float:fTime,szRet[256];
43
44 get_msg_arg_string(2,szRet,charsmax(szRet));
45
46 for(new i = 1;i<33;i++){
47 if(!is_user_connected(i)) continue;
48
49 fTime = fTimeColor[i] > fTimeColor[0] ? fTimeColor[i] : fTimeColor[0];
50
51 if(fTime >= get_gametime() || fTime == -1.0) continue;
52
53 message_begin(MSG_ONE,msgStatusText,_,i);
54 write_byte(0);
55 write_string(szRet);
56 message_end();
57 }
58
59 return PLUGIN_HANDLED;
60 }
61 else if(is_user_connected(msgEnt)){
62 if(fTimeColor[msgEnt] >= get_gametime() || fTimeColor[msgEnt] == -1.0) return PLUGIN_HANDLED;
63 }
64
65 return PLUGIN_CONTINUE;
66 }
67
68 public ColorStatusValue(msgID, msgDest,msgEnt){
69 if(!msgEnt || msgDest == MSG_ALL){
70
71 new Float:fTime,szRet[256];
72
73 get_msg_arg_string(2,szRet,charsmax(szRet));
74
75 for(new i = 1;i<33;i++){
76 if(!is_user_connected(i)) continue;
77
78 fTime = fTimeColor[i] > fTimeColor[0] ? fTimeColor[i] : fTimeColor[0];
79
80 if(fTime >= get_gametime() || fTime == -1.0) continue;
81
82 message_begin(MSG_ONE,msgStatusValue,_,i);
83 write_byte(get_msg_arg_int(1));
84 write_short(get_msg_arg_int(2));
85 message_end();
86 }
87
88 return PLUGIN_HANDLED;
89 }
90 else if(is_user_connected(msgEnt)){
91 if(fTimeColor[msgEnt] >= get_gametime() || fTimeColor[msgEnt] == -1.0) return PLUGIN_HANDLED;
92 }
93
94 return PLUGIN_CONTINUE;
95 }
96
97 public fw_ColorUserInfoChanged(id){
98 if(bChangedNick[id]){
99 set_msg_block(msgSayText, BLOCK_ONCE);
100 set_user_info(id, "name", TO_NAME) ;
101 }
102 }
103
104 stock makeStatusText(id,COLOR_STATUS:color,Float:fTime = 0.0,const szText[] = "",any:...){
105 new szTextFormated[197];
106
107 vformat(szTextFormated, charsmax(szTextFormated), szText, 5);
108
109
110 if(id)
111 {
112 MSG_TYPE[id] = MSG_ONE;
113 fTimeColor[id] = !fTime ? -1.0 : get_gametime() + fTime;
114 } else {
115 id = FindPlayerStatus();
116 MSG_TYPE[id] = MSG_ALL;
117
118 if(id == -1) return ;
119
120 fTimeColor[0] = !fTime ? -1.0 : get_gametime() + fTime;
121
122 }
123
124 if(color == YELLOW_STATUS){
125 message_begin(MSG_TYPE[id],msgStatusText,_,id);
126 write_byte(0);
127 write_string(szTextFormated);
128 message_end();
129
130 return ;
131 }
132
133 get_user_name(id,oldName[id],charsmax(oldName));
134
135 format(szTextFormated, charsmax(szTextFormated),"%s%s","%p2",szTextFormated);
136
137 set_msg_block(msgSayText, BLOCK_ONCE);
138 set_user_info(id, "name", TO_NAME);
139 bChangedNick[id] = true;
140
141 message_begin(MSG_TYPE[id],msgStatusText,_,id);
142 write_byte(0);
143 write_string(szTextFormated);
144 message_end();
145
146 oldTeam[id] = get_user_team(id);
147
148 setTeamMessage(id,color == RED_STATUS ? 1 : color == BLUE_STATUS ? 2 : 3,MSG_TYPE[id]);
149
150 message_begin(MSG_TYPE[id],msgStatusValue,_,id);
151 write_byte(2);
152 write_short(id);
153 message_end();
154
155 remove_task(id+STATUS_TASK);
156 remove_task(id+STATUS_TASK2);
157
158 set_task(0.1,"returnToStatus",id+STATUS_TASK);
159 if(fTime != 0.0) set_task(fTime,"deleteStatus",MSG_TYPE[id] == MSG_ALL ? STATUS_TASK2 : id+STATUS_TASK2);
160 }
161
162 public deleteStatus(id){
163 id-=STATUS_TASK2;
164
165 new Float:fTime;
166
167 if(!id){
168 for(new i = 1;i<33;i++){
169 if(!is_user_connected(i)) continue;
170
171 fTime = fTimeColor[i] > fTimeColor[0] ? fTimeColor[i] : fTimeColor[0];
172
173 if(fTime >= get_gametime() || fTime == -1.0) continue;
174
175 message_begin(MSG_ONE,msgStatusText,_,i);
176 write_byte(0);
177 write_string("");
178 message_end();
179
180 message_begin(MSG_ONE,msgStatusValue,_,i);
181 write_byte(1);
182 write_short(0);
183 message_end();
184
185 message_begin(MSG_ONE,msgStatusValue,_,i);
186 write_byte(2);
187 write_short(0);
188 message_end();
189
190 message_begin(MSG_ONE,msgStatusValue,_,i);
191 write_byte(3);
192 write_short(0);
193 message_end();
194 }
195 }
196 else if(is_user_connected(id)){
197 fTime = fTimeColor[id] > fTimeColor[0] ? fTimeColor[id] : fTimeColor[0];
198
199 if(fTime >= get_gametime() || fTime == -1.0) return ;
200
201 message_begin(MSG_ONE,msgStatusText,_,id);
202 write_byte(0);
203 write_string("");
204 message_end();
205
206 message_begin(MSG_ONE,msgStatusValue,_,id);
207 write_byte(1);
208 write_short(0);
209 message_end();
210
211 message_begin(MSG_ONE,msgStatusValue,_,id);
212 write_byte(2);
213 write_short(0);
214 message_end();
215
216 message_begin(MSG_ONE,msgStatusValue,_,id);
217 write_byte(3);
218 write_short(0);
219 message_end();
220 }
221 }
222
223 public returnToStatus(id){
224 id-=STATUS_TASK;
225
226 bChangedNick[id] = false;
227
228 set_msg_block(msgSayText, BLOCK_ONCE);
229 set_user_info(id,"name",oldName[id]);
230
231 setTeamMessage(id,oldTeam[id],MSG_TYPE[id]);
232 }
233
234 stock setTeamMessage(id, team,type){
235 static msgTeamInfo;
236
237 if(!msgTeamInfo) msgTeamInfo = get_user_msgid("TeamInfo");
238
239 static TeamName[][] =
240 {
241 "",
242 "TERRORIST",
243 "CT",
244 "SPECTATOR"
245 };
246
247 message_begin(type, msgTeamInfo, _, id);
248 write_byte(id);
249 write_string(TeamName[team]);
250 message_end();
251 }
252
253 stock FindPlayerStatus()
254 {
255 static maxPlayers;
256 static i;
257 i = -1;
258
259 if(!maxPlayers) maxPlayers = get_maxplayers();
260
261 while(i <= maxPlayers)
262 {
263 if(is_user_connected(++i))
264 {
265 return i;
266 }
267 }
268
269 return -1;
270 }
271