forked from KoRrNiK/easter-egg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheaster_egg.sma
254 lines (183 loc) · 7.11 KB
/
easter_egg.sma
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#pragma semicolon 1
#include <amxmodx>
#include <reapi>
#include <engine>
#include <fvault>
new const NAME[] = "Easter Egg";
new const VERSION[] = "1.0";
new const AUTHOR[] = "KoRrNiK";
new const URL_AUTHOR[] = "https://github.com/KoRrNiK/";
new const F_VAULTFILE[] = "f_easter_egg";
#define LOAD_METOD
enum _:MODEL_ENUM {
EGG_MODEL,
EGG_CLASS
};
new const model_info[MODEL_ENUM][] = {
"models/egg.mdl",
"egg"
};
enum _:TOP_ENUM {
TOP_DATA[750],
TOP_NAME[450],
};
new data[TOP_ENUM];
#if defined LOAD_METOD
new motd_data[MAX_MOTD_LENGTH];
#endif
enum _:CVAR_ENUM {
cvar_percent_drop,
cvar_speed_drop,
Float:cvar_distance_pickup,
};
new egg_cvar[CVAR_ENUM];
enum _:DATA_ENUM {
PLAYER_NAME[33],
bool:PLAYER_LOADED,
PLAYER_EGGS,
};
new player_info[33][DATA_ENUM];
public plugin_precache()
precache_model(model_info[EGG_MODEL]);
public plugin_init() {
register_plugin(NAME, VERSION, AUTHOR, URL_AUTHOR);
#if defined LOAD_METOD
register_clcmd("say /top10jajek", "show_top");
create_top_eggs();
log_amx("LOAD TOP EGGS [SERVER]");
#else
register_clcmd("say /top10jajek", "create_top_eggs");
log_amx("LOAD TOP EGGS [CLIENT]");
#endif
RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed", 0);
register_logevent("round_start", 2, "1=Round_Start");
bind_pcvar_num(create_cvar("amxx4u_egg_drop_percent", "100"), egg_cvar[cvar_percent_drop]);
bind_pcvar_num(create_cvar("amxx4u_egg_speed_remove", "3"), egg_cvar[cvar_speed_drop]);
bind_pcvar_float(create_cvar("amxx4u_egg_distance_pickup", "40.0"), egg_cvar[cvar_distance_pickup]);
}
public client_disconnected(id)
save_data(id);
public client_connect(id){
get_user_name(id, player_info[id][PLAYER_NAME], charsmax(player_info[][PLAYER_NAME]));
player_info[id][PLAYER_EGGS] = 0;
player_info[id][PLAYER_LOADED] = false;
load_data(id);
}
public round_start()
remove_all_entity(model_info[EGG_CLASS]);
public CBasePlayer_Killed(victim, attacker){
if(victim == attacker || attacker == 0 || victim == 0) return;
if(attacker != victim){
if(random(100) < egg_cvar[cvar_percent_drop])
create_egg(victim);
}
}
public create_egg(id){
new Float:fOrigin[3];
get_entvar(id, var_origin, fOrigin);
new ent = rg_create_entity("info_target");
set_entvar(ent, var_classname, model_info[EGG_CLASS]);
set_entvar(ent, var_movetype, MOVETYPE_TOSS);
set_entvar(ent, var_solid, SOLID_SLIDEBOX);
entity_set_model(ent, model_info[EGG_MODEL]);
set_entvar(ent, var_iuser1, 255);
set_rendering(ent, kRenderFxGlowShell, 0,0,0, kRenderTransAlpha, get_entvar(ent, var_iuser1));
set_entvar(ent, var_origin, fOrigin);
drop_to_floor(ent);
set_task(0.1, "think_egg", ent);
}
public think_egg(ent){
if(!is_entity(ent) || ent == 0) return PLUGIN_CONTINUE;
new Float:fOrigin[3], Float:fOriginTarget[3];
get_entvar(ent, var_origin, fOrigin);
for(new i = 1; i <= MAX_PLAYERS; i ++){
if(!is_user_connected(i) || !is_user_alive(i)) continue;
get_entvar(i, var_origin, fOriginTarget);
if(get_distance_f(fOriginTarget, fOrigin) >= egg_cvar[cvar_distance_pickup]) continue;
player_info[i][PLAYER_EGGS] ++;
client_print_color(i, i, "^4[JAJKA]^1 Brawo podniosles jajko!^4 |^1 Sprawdz teraz ktory jestes^3 /top10jajek");
remove_entity(ent);
return PLUGIN_HANDLED_MAIN;
}
new alpha = get_entvar(ent, var_iuser1);
set_entvar(ent, var_iuser1, alpha - egg_cvar[cvar_speed_drop]);
set_rendering(ent, kRenderFxGlowShell, 0,0,0, kRenderTransAlpha, alpha);
if(!alpha) remove_entity(ent);
else set_task(0.1, "think_egg", ent);
return PLUGIN_CONTINUE;
}
public save_data(id){
if(!player_info[id][PLAYER_LOADED]) return;
new data_vault[64];
formatex(data_vault, charsmax(data_vault), "%d", player_info[id][PLAYER_EGGS]);
fvault_set_data(F_VAULTFILE, player_info[id][PLAYER_NAME], data_vault);
}
public load_data(id){
new data_vault[64];
if( fvault_get_data(F_VAULTFILE, player_info[id][PLAYER_NAME], data_vault, charsmax(data_vault)) ){
new eggs_parse[7];
parse(data_vault, eggs_parse, sizeof(eggs_parse));
player_info[id][PLAYER_EGGS] = str_to_num(eggs_parse);
}else{
player_info[id][PLAYER_EGGS] = 0;
}
player_info[id][PLAYER_LOADED] = true;
}
#if defined LOAD_METOD
public show_top(id)
show_motd(id, motd_data, "Top 10 Zebranych Jajek!");
public create_top_eggs(){
#else
public create_top_eggs(id){
#endif
static motd_len;
#if !defined LOAD_METOD
static motd_data[MAX_MOTD_LENGTH];
#endif
new Array:keys = ArrayCreate(450);
new Array:datas = ArrayCreate(750);
new Array:all = ArrayCreate(TOP_ENUM);
fvault_load(F_VAULTFILE, keys, datas);
new array_size = ArraySize(keys);
for( new i = 0; i < array_size; i++ ){
ArrayGetString(keys, i, data[TOP_NAME], charsmax(data[TOP_NAME]));
ArrayGetString(datas, i, data[TOP_DATA], charsmax(data[TOP_DATA]));
ArrayPushArray(all, data);
}
ArraySort(all, "sort_data");
new size = clamp(array_size, 0, 10);
static player_name[MAX_NAME_LENGTH];
motd_len = 0;
motd_len = formatex(motd_data[motd_len], charsmax(motd_data) - motd_len, "<body><meta charset='UTF-8'><link rel='stylesheet' href='https://amxx4u.pl/server/top-eggs.css'>");
motd_len += formatex(motd_data[motd_len], charsmax(motd_data) - motd_len, "<div><p>Top 10 Jajek!</p><table>");
motd_len += formatex(motd_data[motd_len], charsmax(motd_data) - motd_len, "<tr><td><b>#</b></td><td><b>Nazwa</b></td><td><b>Jajka</b></td></tr>");
for(new j = 0; j < size; j++ ) {
ArrayGetArray(all, j, data);
fvault_get_data(F_VAULTFILE, data[TOP_NAME], player_name, charsmax(player_name));
if(j+1 == 1) motd_len += formatex(motd_data[motd_len], charsmax(motd_data) - motd_len, "<tr><td id='f'>%d</td><td id='f'>%s</td><td id='f'>%s</td></tr>", j + 1, data[TOP_NAME], data[TOP_DATA]);
else if(j+1 == 2) motd_len += formatex(motd_data[motd_len], charsmax(motd_data) - motd_len, "<tr><td id='s'>%d</td><td id='s'>%s</td><td id='s'>%s</td></tr>", j + 1, data[TOP_NAME], data[TOP_DATA]);
else if(j+1 == 3) motd_len += formatex(motd_data[motd_len], charsmax(motd_data) - motd_len, "<tr><td id='t'>%d</td><td id='t'>%s</td><td id='t'>%s</td></tr>", j + 1, data[TOP_NAME], data[TOP_DATA]);
else motd_len += formatex(motd_data[motd_len], charsmax(motd_data) - motd_len, "<tr><td>%d</td><td>%s</td><td>%s</td></tr>", j + 1, data[TOP_NAME], data[TOP_DATA]);
}
motd_len += formatex(motd_data[motd_len], charsmax(motd_data) - motd_len, "</table></div></body>");
#if !defined LOAD_METOD
show_motd(id, motd_data, "Top 10 Zebranych Jajek!");
#endif
}
public sort_data( Array:array, item_1, item_2, data[], data_size ) {
new data_1[TOP_ENUM], data_2[TOP_ENUM];
ArrayGetArray(array, item_1, data_1);
ArrayGetArray(array, item_2, data_2);
new points_1[7], points_2[7];
parse(data_1[TOP_DATA], points_1, charsmax(points_1));
parse(data_2[TOP_DATA], points_2, charsmax(points_2));
new count_1 = str_to_num(points_1);
new count_2 = str_to_num(points_2);
return (count_1 > count_2) ? -1 : ((count_1 < count_2) ? 1 : 0);
}
public remove_all_entity(const class_name[]){
new ent = -1;
while ((ent = find_ent_by_class(ent, class_name))){
if (is_entity(ent)) remove_entity(ent);
}
}