· 4 years ago · Mar 27, 2021, 09:46 AM
1#include <amxmodx>
2#include <amxmisc>
3#include <fakemeta>
4#include <hamsandwich>
5#include <cstrike>
6#include <fakemeta_util>
7#include <fun>
8#include <engine>
9#include <sqlx>
10#include <csgo_skins>
11
12new const szTables[][] =
13{
14 "CREATE TABLE IF NOT EXISTS `player_data` (`player_id` varchar(64) COLLATE utf8_lithuanian_ci, `player_password` varchar(64) COLLATE utf8_lithuanian_ci, `player_name` varchar(64) COLLATE utf8_lithuanian_ci, `player_points` int(32), `player_keys` int(32), `player_money` int(32), `player_kills` int(16), `player_damage` varchar(64), PRIMARY KEY (`player_id`) )",
15 "CREATE TABLE IF NOT EXISTS `player_skins` (`id` int(8) AUTO_INCREMENT, `player_id` varchar(64) COLLATE utf8_lithuanian_ci, `skin_id` int(8), `rang_level` int(8), `is_active_t` int(2), `is_active_ct` int(2), PRIMARY KEY(`id`))",
16 "CREATE TABLE IF NOT EXISTS `player_chests` (`player_id` varchar(64) COLLATE utf8_lithuanian_ci, `chest_name` varchar(64), `chest_count` int(8), PRIMARY KEY (`player_id`, `chest_name`))"
17}
18
19new const column_active[][] = {"is_active_t", "is_active_ct"}
20
21enum _:settings
22{
23 KILLS_DROP_CHEST,
24 DAMAGE_DROP_KEY,
25 DROPPED_CHEST_PROTECTION,
26 ANNOUNCE_CHEST_DROP,
27 POINTS_PER_KILL,
28 MONEY_PER_KILL,
29 POINTS_PER_DEATH,
30 POINTS_PER_HEADSHOT,
31 MONEY_PER_HEADSHOT,
32 DAMAGE_BONUS_POINTS,
33 DAMAGE_BONUS_MONEY,
34 CHEST_GLOW_COLORS,
35 CHEST_GLOW_ENABLED,
36 CHEST_SPIN_ENABLED,
37 GIVE_CHEST_INSTANT
38}
39#define MAX_FLAGS 10
40enum _:privsettings { KILLS_FOR_CHEST, DAMAGE_FOR_KEY, CHEST_PROTECTION, POINTS_KILL, POINTS_DEATH, POINTS_HS, MONEY_KILL, MONEY_HS, POINTS_DMG, MONEY_DMG}
41new priv_settings[privsettings], priv_flags[privsettings][MAX_FLAGS][32], priv_bonus[privsettings][MAX_FLAGS]
42
43new bonus_chance_count, bonus_chance_flags[MAX_FLAGS][32], Float:bonus_chance[MAX_FLAGS];
44
45enum (+= 100)
46{
47 TASK_SPAWN_CHEST = 500
48}
49
50new pSaveType[33], bool:pCanLoad[33], loadedStatus[33];
51new mod_cvars[settings];
52new bool:isLoading[33]
53new chestsCount, skinsCount, rangsCount;
54new chestNames[MAX_CHESTS][64], Float:chestChances[MAX_CHESTS], chestModel[MAX_CHESTS][128], rangNames[MAX_RANGS][64], skinNames[MAX_SKINS][64], rangPoints[MAX_RANGS], skin_weapon_id[MAX_SKINS], skin_model[MAX_SKINS][128], Float:skin_chances[MAX_SKINS][MAX_CHESTS];
55new pChests[33][MAX_CHESTS], pSkins[33][MAX_SKINS], pSkinsRang[33][MAX_SKINS][MAX_EACH_SKIN], pUsingSkin[33][MAX_SKINS][2];
56new pPoints[33], pMoney[33], skin_parts[33][MAX_SKINS], materials[33][MAX_MATERIALS], material_names[MAX_MATERIALS][64], Float:material_drops[MAX_MATERIALS], Float:pDamageDone[33], pTempKills[33], pKeys[33], pPassword[33][64], passwordLoaded[33];
57new Handle:g_hTuple
58new bool:databaseEnabled = false;
59
60new keyPriceTotal, chestPriceTotal[MAX_CHESTS], skinPriceTotal[MAX_SKINS], skinPartPriceTotal[MAX_SKINS], keysBougt, chestsBought[MAX_CHESTS], skinsPartBought[MAX_SKINS], skinsBought[MAX_SKINS], materialPriceTotal[MAX_MATERIALS], materialsBought[MAX_MATERIALS];
61
62#define Sound "xpbox/get_item.wav"
63new const g_pickup[] = "umbrella/items/medkit_pickup.wav"
64new sprite_2, sprite_3
65
66new Array:g_aItems;
67new g_iTotalItems;
68new g_hSelectItemForward, gRegisterMenuEnterForward, gSQLConnectedForward, gSkinPartsChanged, gMaterialsChangedForward;
69
70new gPointsAdded, gMoneyAdded, gChestsAdded, gSkinPartsAdded, gMaterialsAdded, gKeysAdded, gSkinsAdded;
71new bool:eInList[50]
72enum _:ItemData
73{
74 ItemName[128]
75};
76
77new gConnectedForward, gResetForward, gLoadedPasswordForward, gPlayerLoadedForward;
78
79new const weapon_names[][] =
80{
81 "P228","Shield","Scout",
82 "Explosive Grenade","XM1014","C4",
83 "MAC10","AUG","Smoke Grenade",
84 "Dual Elites","Fiveseven","UMP-45",
85 "SG-550","Galil","Famas",
86 "USP","Glock-18","AWP",
87 "MP5 Navy","M249","M3 Shotgun",
88 "M4A1","TMP","G3SG1",
89 "Flashbang","Deagle","SG-552",
90 "AK47","Knife","P90"
91};
92
93#define ENT_CHEST_NAME "player_chest"
94#define MAX_MULTIPLIER 1000000000
95new bool:skinPartsLoaded = false;
96new bool:materialsLoaded = false;
97new bool:registerPluginLoaded = false;
98public plugin_init()
99{
100 register_plugin("CSGO SKINS: CORE", "1.5", "InvIs");
101
102 register_event("DeathMsg", "DeathEvent", "a");
103 register_touch(ENT_CHEST_NAME, "player", "FwdPlayerTouchEntity")
104 RegisterHam(Ham_TakeDamage, "player", "fw_PlayerTakeDamage", 1)
105 register_event("HLTV", "event_new_round", "a", "1=0", "2=0") // new round
106
107 g_aItems = ArrayCreate(ItemData);
108 g_hSelectItemForward = CreateMultiForward( "csgo_menuItemSelected", ET_IGNORE, FP_CELL, FP_CELL );
109 gConnectedForward = CreateMultiForward( "csgo_client_connected", ET_IGNORE, FP_CELL );
110 gResetForward = CreateMultiForward( "csgo_on_client_reset", ET_IGNORE, FP_CELL );
111 gLoadedPasswordForward = CreateMultiForward( "csgo_client_password_loaded", ET_IGNORE, FP_CELL, FP_STRING );
112 gPlayerLoadedForward = CreateMultiForward( "csgo_client_info_loaded", ET_IGNORE, FP_CELL );
113 gSQLConnectedForward = CreateMultiForward( "csgo_sql_connected", ET_IGNORE );
114 gSkinPartsChanged = CreateMultiForward( "csgo_on_skin_parts_changed", ET_IGNORE, FP_CELL, FP_CELL);
115 gMaterialsChangedForward = CreateMultiForward( "csgo_on_materials_changed", ET_IGNORE, FP_CELL, FP_CELL);
116 gRegisterMenuEnterForward = CreateMultiForward( "csgo_register_menu_enter", ET_IGNORE, FP_CELL, FP_STRING);
117
118 gPointsAdded = CreateMultiForward( "csgo_on_points_added", ET_IGNORE, FP_CELL, FP_CELL);
119 gMoneyAdded = CreateMultiForward( "csgo_on_money_added", ET_IGNORE, FP_CELL, FP_CELL);
120 gChestsAdded = CreateMultiForward( "csgo_on_chests_added", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL);
121 gSkinPartsAdded = CreateMultiForward( "csgo_on_skin_parts_added", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL);
122 gMaterialsAdded = CreateMultiForward( "csgo_on_materials_added", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL);
123 gKeysAdded = CreateMultiForward( "csgo_on_keys_added", ET_IGNORE, FP_CELL, FP_CELL);
124 gSkinsAdded = CreateMultiForward( "csgo_on_skins_added", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL);
125
126 mod_cvars[KILLS_DROP_CHEST] = register_cvar("csgo_kills_drop_chest", "10");
127 mod_cvars[DAMAGE_DROP_KEY] = register_cvar("csgo_damage_drop_key", "5000");
128 mod_cvars[DROPPED_CHEST_PROTECTION] = register_cvar("csgo_chest_protection_time", "7.0");
129 mod_cvars[ANNOUNCE_CHEST_DROP] = register_cvar("csgo_announce_chest_drop", "1");
130
131 mod_cvars[POINTS_PER_KILL] = register_cvar("csgo_points_per_kill", "1");
132 mod_cvars[MONEY_PER_KILL] = register_cvar("csgo_money_per_kill", "5");
133 mod_cvars[POINTS_PER_DEATH] = register_cvar("csgo_points_per_death", "-1");
134 mod_cvars[POINTS_PER_HEADSHOT] = register_cvar("csgo_points_per_hs", "1");
135 mod_cvars[MONEY_PER_HEADSHOT] = register_cvar("csgo_money_per_hs", "5");
136 mod_cvars[DAMAGE_BONUS_POINTS] = register_cvar("csgo_damage_bonus_points", "1");
137 mod_cvars[DAMAGE_BONUS_MONEY] = register_cvar("csgo_damage_bonus_money", "5");
138
139 mod_cvars[CHEST_GLOW_ENABLED] = register_cvar("csgo_chest_glow", "1");
140 mod_cvars[CHEST_GLOW_COLORS] = register_cvar("csgo_chest_glow_colors", "50 255 15");
141 mod_cvars[CHEST_SPIN_ENABLED] = register_cvar("csgo_chest_spin", "1");
142
143 mod_cvars[GIVE_CHEST_INSTANT] = register_cvar("csgo_give_chest_instantly", "1");
144
145
146 register_clcmd("say /menu", "showMainMenu");
147 register_clcmd("radio1", "showMainMenu");
148
149 set_task(0.5, "MySQLx_Init");
150 //register_clcmd("say /test", "test");
151}
152public test(id)
153{
154 client_connect(id);
155
156 return PLUGIN_HANDLED
157}
158public event_new_round() {
159 new ent = -1
160 while ((ent = engfunc(EngFunc_FindEntityByString, ent, "classname", ENT_CHEST_NAME))) // find ent entity id by ent unique classname
161 engfunc(EngFunc_RemoveEntity, ent) // remove ent entity
162}
163public csgo_skin_parts_loaded() skinPartsLoaded = true;
164public csgo_materials_loaded() materialsLoaded = true;
165public plugin_cfg()
166{
167 execConfiguration();
168 //set_task(0.5, "MySQLx_Init");
169 set_task(1.0, "loadMenuCustomization");
170 set_task(2.0, "storeMenuCustomization");
171}
172public execConfiguration()
173{
174 new configs_dir[128], configuration_file[128];
175 get_configsdir(configs_dir, charsmax(configs_dir));
176
177 format(configuration_file, charsmax(configuration_file), "%s/csgo", configs_dir);
178 if(!dir_exists(configuration_file)) mkdir(configuration_file);
179
180 format(configuration_file, charsmax(configuration_file), "%s/csgo/csgo_cvars.cfg", configs_dir);
181 if(file_exists(configuration_file))
182 {
183 server_cmd("exec %s", configuration_file)
184 server_exec()
185 }
186 else
187 {
188 write_file(configuration_file, "csgo_register_disable_ip ^"1^" // Disable IP option in register menu (NEEDS REGISTER PLUGIN)");
189 write_file(configuration_file, "csgo_register_disable_steam ^"1^" // Disable STEAM option in register menu (NEEDS REGISTER PLUGIN)");
190 write_file(configuration_file, "");
191 write_file(configuration_file, "csgo_skin_percent_to_announce ^"20^" // How rare a skin needs to be to announce to public when players gets it from chest");
192 write_file(configuration_file, "");
193 write_file(configuration_file, "csgo_parts_needed_to_connect ^"5^" // Parts needed to make a skin (NEEDS SKIN PARTS PLUGIN)");
194 write_file(configuration_file, "");
195 write_file(configuration_file, "csgo_contract_buy_amount ^"5^" // How many contracts a player will buy at once (0 - unlimited uses) (NEEDS CONTRACTS PLUGIN)");
196 write_file(configuration_file, "csgo_contract_cost ^"5000^" // How much contracts cost (NEEDS CONTRACTS PLUGIN)");
197 write_file(configuration_file, "csgo_contract_minimum_skins ^"5^" // Minimum amount of skins to make a contract (NEEDS CONTRACTS PLUGIN)");
198 write_file(configuration_file, "csgo_contract_maximum_skins ^"1000^" // Maximum amount of skins to make a contract (NEEDS CONTRACTS PLUGIN)");
199 write_file(configuration_file, "csgo_contract_percent_decrease ^"0.25^" // How many percents will decrease making a contract per skin (NEEDS CONTRACTS PLUGIN)");
200 write_file(configuration_file, "");
201 write_file(configuration_file, "csgo_presents_on_round ^"15^" // How many presents will spawn at a time (NEEDS PRESENTS PLUGIN)");
202 write_file(configuration_file, "csgo_presents_min_players ^"5^" // Minimum players to spawn presents (NEEDS PRESENTS PLUGIN)");
203 write_file(configuration_file, "csgo_presents_glow ^"255 0 0^" // Presents glow color in RGB (NEEDS PRESENTS PLUGIN)");
204 write_file(configuration_file, "csgo_presents_glow_enabled ^"1^" // Is glow enabled (NEEDS PRESENTS PLUGIN)");
205 write_file(configuration_file, "csgo_presents_spin ^"1^" // Is spin enabled (NEEDS PRESENTS PLUGIN)");
206 write_file(configuration_file, "csgo_presents_spawn_announce ^"1^" // Presents spawn announce (NEEDS PRESENTS PLUGIN)");
207 write_file(configuration_file, "");
208 write_file(configuration_file, "csgo_gamble_interval_seconds ^"60^" // Gambling event interval (NEEDS GAMBLE PLUGIN)");
209 write_file(configuration_file, "csgo_gamble_minimum_amount ^"100^" // Gambling minimum amount (NEEDS GAMBLE PLUGIN)");
210 write_file(configuration_file, "csgo_block_bets_seconds_left ^"10^" // Gambling block bets seconds left (NEEDS GAMBLE PLUGIN)");
211 write_file(configuration_file, "csgo_gambling_event_pause ^"10^" // How many seconds before new gambling event (NEEDS GAMBLE PLUGIN)");
212 write_file(configuration_file, "csgo_gamble_maximum_amount ^"99999999999999^" // Gambling maximum amount (NEEDS GAMBLE PLUGIN)");
213 write_file(configuration_file, "csgo_announce_win_amount ^"1000^" // Announce minimum win amount (NEEDS GAMBLE PLUGIN)");
214 write_file(configuration_file, "csgo_announce_lost_amount ^"1000^" // Announce minimum lost amount (NEEDS GAMBLE PLUGIN)");
215 }
216
217
218 format(configuration_file, charsmax(configuration_file), "%s/csgo/settings.cfg", configs_dir);
219 if(!file_exists(configuration_file))
220 {
221 write_file(configuration_file, ";Configuration settings");
222 write_file(configuration_file, "csgo_kills_drop_chest ^"10^"");
223 write_file(configuration_file, "csgo_damage_drop_key ^"5000^"");
224 write_file(configuration_file, "csgo_chest_protection_time ^"7.0^"");
225 write_file(configuration_file, "csgo_announce_chest_drop ^"1^"");
226 write_file(configuration_file, "csgo_points_per_kill ^"1^"");
227 write_file(configuration_file, "csgo_money_per_kill ^"5^"");
228 write_file(configuration_file, "csgo_points_per_death ^"-1^"");
229 write_file(configuration_file, "csgo_points_per_hs ^"1^"");
230 write_file(configuration_file, "csgo_money_per_hs ^"5^"");
231 write_file(configuration_file, "csgo_damage_bonus_points ^"1^"");
232 write_file(configuration_file, "csgo_damage_bonus_money ^"5^"");
233 write_file(configuration_file, "csgo_chest_glow ^"1^"");
234 write_file(configuration_file, "csgo_chest_glow_colors ^"50 255 15^"");
235 write_file(configuration_file, "csgo_chest_spin ^"1^"");
236 write_file(configuration_file, "csgo_give_chest_instantly ^"1^"");
237 }
238 else
239 {
240 server_cmd("exec %s", configuration_file)
241 server_exec()
242 }
243}
244public MySQLx_Init()
245{
246 new configs_dir[128], configuration_file[128];
247 get_configsdir(configs_dir, charsmax(configs_dir));
248
249 format(configuration_file, charsmax(configuration_file), "%s/csgo", configs_dir);
250 if(!dir_exists(configuration_file)) mkdir(configuration_file);
251
252 format(configuration_file, charsmax(configuration_file), "%s/csgo/csgo_sql_information.ini", configs_dir);
253 new szHost[64], szUser[64], szPass[64], szDB[64]
254 if( !file_exists( configuration_file ) )
255 {
256 write_file( configuration_file, ";Enter SQL information: ^"Host^" ^"User^" ^"Password^" ^"Database^"");
257 write_file( configuration_file, "^"localhost^" ^"root^" ^"^" ^"csgo_mod^"");
258 return;
259 }
260 else
261 {
262 new szData[256], iTextLength, iLine
263 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
264 {
265 if (szData[0] == ';' || !szData[0])
266 {
267 iLine++
268 continue
269 }
270 parse(szData, szHost, charsmax(szHost), szUser, charsmax(szUser), szPass, charsmax(szPass), szDB, charsmax(szDB))
271 databaseEnabled = true;
272 break
273 }
274 }
275
276 g_hTuple = SQL_MakeDbTuple( szHost, szUser, szPass, szDB );
277
278 new iReturn;
279 ExecuteForward(gSQLConnectedForward, iReturn);
280
281 for ( new i = 0; i < sizeof szTables; i++ )
282 {
283 SQL_ThreadQuery( g_hTuple, "QuerySetData", szTables[i])
284 }
285}
286public QuerySetData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
287{
288 if( iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED )
289 {
290 log_amx( "%s", szError );
291 return;
292 }
293}
294public FwdPlayerTouchEntity( iEntity, iPlayer, id )
295{
296 if(!is_user_alive(iPlayer))
297 return PLUGIN_HANDLED;
298
299 new i = pev(iEntity, pev_iuser4);
300 if(i != -1 && i != iPlayer) return PLUGIN_HANDLED;
301 if ( pev_valid(iEntity) )
302 {
303 new chest_id = pev(iEntity, pev_iuser3);
304
305 if(!get_pcvar_num(mod_cvars[GIVE_CHEST_INSTANT]))
306 {
307 pChests[iPlayer][chest_id]++;
308 client_printcolor(iPlayer, "/y[/ctrCSGO/y] You picked a /g%s /ychest!", chestNames[chest_id]);
309 saveChest(iPlayer, chest_id);
310
311 new iReturn;
312 ExecuteForward(gChestsAdded, iReturn, iPlayer, chest_id, 1);
313 }
314
315
316 if(skinPartsLoaded)
317 {
318 new part_id = pickRandomSkinPart(id, chest_id);
319 if(part_id != -1)
320 {
321 client_printcolor(iPlayer, "/y[/ctrCSGO/y] You found /g%s /y(/g%s/y) /yskin part!", skinNames[part_id], weapon_names[skin_weapon_id[part_id]-1]);
322
323 native_set_skin_parts(iPlayer, part_id, skin_parts[iPlayer][part_id]+1);
324 }
325 }
326
327 if(materialsLoaded)
328 {
329 new material_id = pickRandomMaterial(id);
330 if(material_id != -1)
331 {
332 client_printcolor(iPlayer, "/y[/ctrCSGO/y] You found /g%s /ymaterial!", material_names[material_id]);
333
334 native_set_materials(iPlayer, material_id, materials[iPlayer][material_id]+1);
335 }
336 }
337
338
339
340 Screen_Fade(iPlayer)
341 get_effect(iPlayer)
342 emit_sound(iPlayer, CHAN_ITEM, g_pickup, 1.0, ATTN_NORM, 0, PITCH_NORM);
343 remove_entity(iEntity)
344 }
345 return PLUGIN_CONTINUE;
346}
347public Screen_Fade(id)
348{
349 message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
350 write_short(1<<12)
351 write_short(1<<10)
352 write_short(0x0000)
353 write_byte(255)
354 write_byte(140)
355 write_byte(0)
356 write_byte(200)
357 message_end()
358}
359public get_effect(id) {
360 effect_1(id)
361 effect_2(id)
362
363 engfunc(EngFunc_EmitSound, id, CHAN_WEAPON, Sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
364}
365public effect_1(id)
366{
367 new origin[3]
368
369 get_user_origin(id, origin)
370 message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
371 write_byte(TE_SPRITE)
372 write_coord(origin[0])
373 write_coord(origin[1])
374 write_coord(origin[2])
375 write_short(sprite_2)
376 write_byte(20)
377 write_byte(255)
378 message_end()
379}
380
381public effect_2(id)
382{
383 new g_origin[3]
384
385 get_user_origin(id,g_origin)
386
387 message_begin(MSG_ALL,SVC_TEMPENTITY,{0,0,0},id)
388 write_byte(TE_SPRITETRAIL)
389 write_coord(g_origin[0])
390 write_coord(g_origin[1])
391 write_coord(g_origin[2]+20)
392 write_coord(g_origin[0])
393 write_coord(g_origin[1])
394 write_coord(g_origin[2]+80)
395 write_short(sprite_3)
396 write_byte(20)
397 write_byte(20)
398 write_byte(4)
399 write_byte(20)
400 write_byte(10)
401 message_end()
402}
403public plugin_precache()
404{
405 loadConfiguration();
406 loadSettings();
407
408 engfunc(EngFunc_PrecacheSound, g_pickup);
409 precache_sound(Sound)
410 sprite_3 = precache_model("sprites/xpbox/acid_pou.spr")
411 sprite_2 = precache_model("sprites/xpbox/green.spr")
412}
413public csgo_register_plugin_loaded() registerPluginLoaded = true;
414public client_connect(id)
415{
416 pSaveType[id] = SAVE_TYPE_IP;
417 pCanLoad[id] = true;
418 isLoading[id] = false;
419 loadedStatus[id] = STATUS_NOT_LOADED;
420 client_reset(id);
421
422 new iReturn;
423 ExecuteForward(gConnectedForward, iReturn, id);
424 if(!registerPluginLoaded)
425 {
426 loadPlayer(id);
427 }
428}
429public client_reset(id)
430{
431 new i;
432 pPoints[id] = 0;
433 pDamageDone[id] = 0.0;
434 pTempKills[id] = 0;
435 pKeys[id] = 0;
436 pMoney[id] = 0;
437 for(i = 0; i < MAX_SKINS; i++) skin_parts[id][i] = 0;
438 for(i = 0; i < MAX_MATERIALS; i++) materials[id][i] = 0
439 for(i = 0; i < MAX_CHESTS; i++) pChests[id][i] = 0;
440 passwordLoaded[id] = STATUS_NOT_LOADED
441 for(i = 0; i < MAX_SKINS; i++)
442 {
443 pSkins[id][i] = 0;
444 for(new j; j < MAX_EACH_SKIN; j++) pSkinsRang[id][i][j] = 0;
445 }
446
447 new iReturn;
448 ExecuteForward(gResetForward, iReturn, id);
449}
450public DeathEvent(victim, attacker)
451{
452 new attacker = read_data(1);
453 new victim = read_data(2);
454 new hs = read_data(3);
455 if(1 <= victim <= 32 && 1 <= attacker <= 32 && victim != attacker)
456 {
457 new points_attacker, points_victim, money_attacker;
458
459 pTempKills[attacker]++;
460
461 points_attacker += get_pcvar_num(mod_cvars[POINTS_PER_KILL]);
462 money_attacker += get_pcvar_num(mod_cvars[MONEY_PER_KILL]);
463
464 points_attacker += getBonus(attacker, POINTS_KILL);
465 money_attacker += getBonus(attacker, MONEY_KILL);
466 if(hs)
467 {
468 points_attacker += get_pcvar_num(mod_cvars[POINTS_PER_HEADSHOT]);
469 money_attacker += get_pcvar_num(mod_cvars[MONEY_PER_HEADSHOT]);
470
471 points_attacker += getBonus(attacker, POINTS_HS);
472 money_attacker += getBonus(attacker, MONEY_HS);
473 }
474
475 new need_kills = get_pcvar_num(mod_cvars[KILLS_DROP_CHEST]);
476 need_kills -= getBonus(attacker, KILLS_FOR_CHEST);
477
478 if(pTempKills[attacker] >= need_kills)
479 {
480 pTempKills[attacker] = 0;
481 new chest = pickRandomChest(attacker);
482 if(chest != -1)
483 {
484 new gParams[2];
485 gParams[0] = victim;
486 gParams[1] = chest;
487
488 set_task(0.1, "dropChestFromPlayer", attacker, gParams, sizeof(gParams));
489 }
490 }
491
492 points_victim += get_pcvar_num(mod_cvars[POINTS_PER_DEATH]);
493 points_victim += getBonus(victim, POINTS_DEATH);
494
495 pPoints[victim] += points_victim;
496 pMoney[attacker] += money_attacker;
497 pPoints[attacker] += points_attacker;
498
499 if(pPoints[victim] < 0) pPoints[victim] = 0;
500 if(pPoints[attacker] < 0) pPoints[attacker] = 0;
501
502 new iReturn;
503 if(points_attacker > 0) ExecuteForward(gPointsAdded, iReturn, attacker, points_attacker);
504 if(money_attacker > 0) ExecuteForward(gMoneyAdded, iReturn, attacker, money_attacker);
505 if(points_victim > 0) ExecuteForward(gPointsAdded, iReturn, victim, points_victim);
506
507 set_hudmessage(0, 255, 50, 0.50, 0.33, 0, 1.0, 1.0);
508 // show_hudmessage(attacker, "+%i & +$%d", points_attacker, money_attacker);
509 client_printcolor(attacker, "/y[/ctrCSGO/y] For kill you received /ctr+%i points /yand /ctr+%d money/y.", points_attacker, money_attacker);
510
511 savePlayer(attacker);
512 savePlayer(victim);
513 }
514}
515
516public fw_PlayerTakeDamage(Victim, Inflictor, Attacker, Float:Damage, DamageBits)
517{
518 if(!(1 <= Attacker <= 32) || !(1 <= Victim <= 32)) return HAM_HANDLED
519
520 if(Victim == Attacker)
521 return HAM_HANDLED
522
523 if(get_user_team(Attacker) != get_user_team(Victim))
524 {
525 pDamageDone[Attacker] += Damage;
526
527 new Float:Ddone = get_pcvar_float(mod_cvars[DAMAGE_DROP_KEY]);
528 Ddone -= float(getBonus(Attacker, DAMAGE_FOR_KEY));
529 while(pDamageDone[Attacker] >= Ddone)
530 {
531 pDamageDone[Attacker] -= Ddone;
532 givePlayerKey(Attacker);
533 client_printcolor(Attacker, "/y[/ctrCSGO/y] You got a key!");
534
535 new bonus = get_pcvar_num(mod_cvars[DAMAGE_BONUS_POINTS])
536 bonus += getBonus(Attacker, POINTS_DMG);
537 new bonus_money = get_pcvar_num(mod_cvars[DAMAGE_BONUS_MONEY])
538 bonus_money += getBonus(Attacker, MONEY_DMG);
539 if(bonus > 0 || bonus_money > 0)
540 {
541 pPoints[Attacker] += bonus;
542 pMoney[Attacker] += bonus_money;
543 set_hudmessage(0, 40, 255, 0.50, 0.33, 1, 2.0, 2.0);
544 // show_hudmessage(Attacker, "+%i +$%d", bonus, bonus_money);
545 client_printcolor(Attacker, "/y[/ctrCSGO/y] You got a BONUS /ctr+%i points /yand /ctr+%d money/y.", bonus, bonus_money);
546 savePlayer(Attacker);
547 }
548 }
549
550 }
551
552 return HAM_HANDLED
553}
554public savePlayer(id)
555{
556 if(loadedStatus[id] != STATUS_LOADED)
557 return;
558
559 static szQuery[512];
560
561 new name[64];
562 get_user_name(id, name, charsmax(name));
563
564 formatex( szQuery, charsmax(szQuery), "REPLACE INTO `player_data` (`player_id`, `player_name`, `player_password`, `player_points`, `player_keys`, `player_money`, `player_kills`, `player_damage`) VALUES ('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%f');", GetSecureString(GetSecureId(id)), GetSecureString(name), GetSecureString(pPassword[id]), pPoints[id], pKeys[id], pMoney[id], pTempKills[id], pDamageDone[id]);
565
566 SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
567
568}
569public saveChest(id, chest)
570{
571 if(loadedStatus[id] != STATUS_LOADED)
572 return;
573
574 static szQuery[ 256 ];
575
576 formatex( szQuery, 255, "REPLACE INTO `player_chests` (`player_id`, `chest_name`, `chest_count`) VALUES ('%s', '%s', '%d');", GetSecureString(GetSecureId(id)), chestNames[chest], pChests[id][chest]);
577
578 SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
579}
580public saveSkin(id, skin, which, action)
581{
582 if(loadedStatus[id] != STATUS_LOADED)
583 return;
584
585 static szQuery[ 256 ];
586
587 new team = get_user_team(id);
588 if(!(1 <= team <= 2)) team = 1;
589
590 switch(action)
591 {
592 case ACTION_UPDATE:
593 {
594 formatex( szQuery, 255, "UPDATE `player_skins` SET `rang_level` = '%d' WHERE `player_id` = '%s' AND `skin_id` = '%d' LIMIT 1;", pSkinsRang[id][skin][which], GetSecureString(GetSecureId(id)), skin);
595 }
596 case ACTION_INSERT:
597 {
598 formatex( szQuery, 255, "INSERT INTO `player_skins` (`player_id`, `skin_id`, `rang_level`, `%s`) VALUES ('%s', '%d', '%d', '%d');", column_active[team-1], GetSecureString(GetSecureId(id)), skin, pSkinsRang[id][skin][which], pUsingSkin[id][skin][team-1]);
599 }
600 case ACTION_DELETE:
601 {
602 formatex( szQuery, 255, "DELETE FROM `player_skins` WHERE `rang_level` = '%d' AND `player_id` = '%s' AND `skin_id` = '%d' LIMIT 1;", pSkinsRang[id][skin][which], GetSecureString(GetSecureId(id)), skin);
603 }
604 }
605 SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
606}
607public updateUsingStatus(id, skin, bool:status)
608{
609 if(loadedStatus[id] != STATUS_LOADED)
610 return;
611
612 static szQuery[ 256 ];
613
614 new team = get_user_team(id);
615 if(!(1 <= team <= 2)) team = 1;
616
617 formatex( szQuery, 255, "UPDATE `player_skins` SET `%s` = '%d' WHERE `player_id` = '%s' AND `skin_id` = '%d';", column_active[team-1], status, GetSecureString(GetSecureId(id)), skin);
618
619 SQL_ThreadQuery( g_hTuple, "QuerySetData", szQuery);
620}
621public loadPassword(id)
622{
623 static szQuery[ 256 ];
624
625 formatex( szQuery, 255, "SELECT `player_password` FROM `player_data` WHERE `player_id` = '%s';", GetSecureString(GetSecureId(id)));
626
627 new iData[1];
628 iData[ 0 ] = id;
629 SQL_ThreadQuery( g_hTuple, "QuerySelecPlayerPassword", szQuery, iData, 1 );
630}
631public QuerySelecPlayerPassword( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
632{
633 if( iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED )
634 {
635 log_amx( "%s", szError );
636 return;
637 }
638 else
639 {
640 new id = iData[0];
641
642 new col_password = SQL_FieldNameToNum(hQuery, "player_password");
643
644 if(SQL_MoreResults(hQuery))
645 {
646 SQL_ReadResult(hQuery, col_password, pPassword[id], charsmax(pPassword[]));
647
648 //SQL_NextRow(hQuery)
649 }
650 else formatex(pPassword[id], charsmax(pPassword[]), "");
651
652 new iReturn;
653 ExecuteForward(gLoadedPasswordForward, iReturn, id, pPassword[id]);
654 }
655}
656public loadPlayer(id)
657{
658 if(!pCanLoad[id] || isLoading[id] || !databaseEnabled) return;
659
660 client_reset(id);
661
662 static szQuery[ 256 ];
663
664 formatex( szQuery, 255, "SELECT * FROM `player_data` WHERE `player_id` = '%s';", GetSecureString(GetSecureId(id)));
665 isLoading[id] = true;
666 new iData[1];
667 iData[ 0 ] = id;
668 SQL_ThreadQuery( g_hTuple, "QuerySelecPlayerData", szQuery, iData, 1 );
669}
670public QuerySelecPlayerData( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
671{
672 if( iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED )
673 {
674 log_amx( "%s", szError );
675 return;
676 }
677 else
678 {
679 new id = iData[0];
680
681 new col_password = SQL_FieldNameToNum(hQuery, "player_password")
682 new col_points = SQL_FieldNameToNum(hQuery, "player_points")
683 new col_keys = SQL_FieldNameToNum(hQuery, "player_keys")
684 new col_money = SQL_FieldNameToNum(hQuery, "player_money")
685 new col_kills = SQL_FieldNameToNum(hQuery, "player_kills")
686 new col_damage = SQL_FieldNameToNum(hQuery, "player_damage")
687
688 while (SQL_MoreResults(hQuery) && isLoading[id])
689 {
690 SQL_ReadResult(hQuery, col_password, pPassword[id], charsmax(pPassword[]));
691 pPoints[id] = SQL_ReadResult(hQuery, col_points);
692 pKeys[id] = SQL_ReadResult(hQuery, col_keys);
693 pMoney[id] = SQL_ReadResult(hQuery, col_money);
694 pTempKills[id] = SQL_ReadResult(hQuery, col_kills);
695 SQL_ReadResult(hQuery, col_damage, pDamageDone[id]);
696
697 SQL_NextRow(hQuery)
698 }
699 if(isLoading[id]) loadPlayerChests(id);
700 }
701}
702public loadPlayerChests(id)
703{
704 if(!pCanLoad[id] || !isLoading[id]) return;
705
706 static szQuery[ 256 ];
707
708 formatex( szQuery, 255, "SELECT * FROM `player_chests` WHERE `player_id` = '%s';", GetSecureString(GetSecureId(id)));
709
710 new iData[1];
711 iData[ 0 ] = id;
712 SQL_ThreadQuery( g_hTuple, "QuerySelecPlayerChests", szQuery, iData, 1 );
713}
714public QuerySelecPlayerChests( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
715{
716 if( iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED )
717 {
718 log_amx( "%s", szError );
719 return;
720 }
721 else
722 {
723 new id = iData[0];
724
725 new col_chest_name = SQL_FieldNameToNum(hQuery, "chest_name")
726 new col_chest_count = SQL_FieldNameToNum(hQuery, "chest_count")
727 new chest_name[64];
728 while (SQL_MoreResults(hQuery) && isLoading[id])
729 {
730 SQL_ReadResult(hQuery, col_chest_name, chest_name, charsmax(chest_name));
731 for(new i; i < chestsCount; i++)
732 {
733 if(equal(chest_name, chestNames[i]))
734 {
735 pChests[id][i] = SQL_ReadResult(hQuery, col_chest_count);
736 break;
737 }
738 }
739
740 SQL_NextRow(hQuery)
741 }
742 if(isLoading[id]) loadPlayerSkins(id);
743 }
744}
745public loadPlayerSkins(id)
746{
747 if(!pCanLoad[id] || !isLoading[id]) return;
748
749 static szQuery[ 256 ];
750
751 formatex( szQuery, 255, "SELECT * FROM `player_skins` WHERE `player_id` = '%s';", GetSecureString(GetSecureId(id)));
752
753 new iData[1];
754 iData[ 0 ] = id;
755 SQL_ThreadQuery( g_hTuple, "QuerySelecPlayerSkins", szQuery, iData, 1 );
756}
757public QuerySelecPlayerSkins( iFailState, Handle:hQuery, szError[ ], iError, iData[ ], iDataSize, Float:fQueueTime )
758{
759 if( iFailState == TQUERY_CONNECT_FAILED || iFailState == TQUERY_QUERY_FAILED )
760 {
761 log_amx( "%s", szError );
762 return;
763 }
764 else
765 {
766 new id = iData[0];
767
768 new col_skin_id = SQL_FieldNameToNum(hQuery, "skin_id");
769 new col_rang_level = SQL_FieldNameToNum(hQuery, "rang_level");
770 new col_is_active_t = SQL_FieldNameToNum(hQuery, "is_active_t");
771 new col_is_active_ct = SQL_FieldNameToNum(hQuery, "is_active_ct");
772 new skin;
773 while (SQL_MoreResults(hQuery) && isLoading[id])
774 {
775 skin = SQL_ReadResult(hQuery, col_skin_id);
776
777 if(pSkins[id][skin] >= MAX_CHESTS) break;
778
779 pSkinsRang[id][skin][pSkins[id][skin]] = SQL_ReadResult(hQuery, col_rang_level);
780 pUsingSkin[id][skin][0] = SQL_ReadResult(hQuery, col_is_active_t);
781 pUsingSkin[id][skin][1] = SQL_ReadResult(hQuery, col_is_active_ct);
782 pSkins[id][skin]++;
783
784 SQL_NextRow(hQuery);
785 }
786 if(isLoading[id]) loadedStatus[id] = STATUS_LOADED;
787 isLoading[id] = false;
788 new iReturn;
789 ExecuteForward(gPlayerLoadedForward, iReturn, id);
790 }
791}
792public loadSettings()
793{
794 new configs_dir[128], configuration_file[128];
795 get_configsdir(configs_dir, charsmax(configs_dir));
796
797 format(configuration_file, charsmax(configuration_file), "%s/csgo", configs_dir);
798 if(!dir_exists(configuration_file)) mkdir(configuration_file);
799
800 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges", configs_dir);
801 if(!dir_exists(configuration_file)) mkdir(configuration_file);
802
803 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/chances", configs_dir);
804 if(!dir_exists(configuration_file)) mkdir(configuration_file);
805
806 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/chances/chances.ini", configs_dir);
807 if(!file_exists(configuration_file))
808 {
809 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
810 write_file(configuration_file, ";Flags | How many percent less for everything");
811 write_file(configuration_file, "^"bit^" 3");
812 write_file(configuration_file, "^"STEAM^" 2");
813
814 bonus_chance[0] = 3.0;
815 bonus_chance[1] = 2.0;
816 formatex(bonus_chance_flags[0], charsmax(bonus_chance_flags[]), "bit");
817 formatex(bonus_chance_flags[1], charsmax(bonus_chance_flags[]), "STEAM");
818 bonus_chance_count = 2;
819 }
820 else
821 {
822 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
823 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
824 {
825 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
826 {
827 iLine++;
828 continue;
829 }
830 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
831
832 bonus_chance[bonus_chance_count] = str_to_float(szBonus);
833 formatex(bonus_chance_flags[bonus_chance_count], charsmax(bonus_chance_flags[]), szFlags);
834
835 bonus_chance_count++;
836 iLine++;
837 }
838 }
839
840 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/chest_kills.ini", configs_dir);
841 if(!file_exists(configuration_file))
842 {
843 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
844 write_file(configuration_file, ";Flags | How many kills less to receive a chest");
845 write_file(configuration_file, ";Example: default kills cvar is set to 5, so player with ^"bit^" flags will need 4 kills");
846 write_file(configuration_file, ";And player with ^"bit^" flags who is also STEAM will need 3 kills (everything sums up)");
847 write_file(configuration_file, ";And player who doesn't have ^"bit^" flags but is a STEAM will need 4 kills");
848 write_file(configuration_file, "^"bit^" 1");
849 write_file(configuration_file, "^"STEAM^" 1");
850
851 priv_bonus[KILLS_FOR_CHEST][0] = 1;
852 priv_bonus[KILLS_FOR_CHEST][1] = 1;
853 formatex(priv_flags[KILLS_FOR_CHEST][0], charsmax(priv_flags[][]), "bit");
854 formatex(priv_flags[KILLS_FOR_CHEST][1], charsmax(priv_flags[][]), "STEAM");
855 priv_settings[KILLS_FOR_CHEST] = 2;
856 }
857 else
858 {
859 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
860 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
861 {
862 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
863 {
864 iLine++;
865 continue;
866 }
867 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
868
869 priv_bonus[KILLS_FOR_CHEST][priv_settings[KILLS_FOR_CHEST]] = str_to_num(szBonus);
870 formatex(priv_flags[KILLS_FOR_CHEST][priv_settings[KILLS_FOR_CHEST]], charsmax(priv_flags[][]), szFlags);
871
872 priv_settings[KILLS_FOR_CHEST]++;
873 iLine++;
874 }
875 }
876
877 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/keys_damage.ini", configs_dir);
878 if(!file_exists(configuration_file))
879 {
880 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
881 write_file(configuration_file, ";Flags | How many damage less to receive a key");
882 write_file(configuration_file, ";Example: default damage cvar is set to 5000, so player with ^"bit^" flags will need 4000 damage");
883 write_file(configuration_file, ";And player with ^"bit^" flags who is also STEAM will need 3000 damage (everything sums up)");
884 write_file(configuration_file, ";And player who doesn't have ^"bit^" flags but is a STEAM will need 4000 damage");
885 write_file(configuration_file, "^"bit^" 1000");
886 write_file(configuration_file, "^"STEAM^" 1000");
887
888 priv_bonus[DAMAGE_FOR_KEY][0] = 1000;
889 priv_bonus[DAMAGE_FOR_KEY][1] = 1000;
890 formatex(priv_flags[DAMAGE_FOR_KEY][0], charsmax(priv_flags[][]), "bit");
891 formatex(priv_flags[DAMAGE_FOR_KEY][1], charsmax(priv_flags[][]), "STEAM");
892 priv_settings[DAMAGE_FOR_KEY] = 2;
893 }
894 else
895 {
896 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
897 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
898 {
899 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
900 {
901 iLine++;
902 continue;
903 }
904 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
905
906 priv_bonus[DAMAGE_FOR_KEY][priv_settings[DAMAGE_FOR_KEY]] = str_to_num(szBonus);
907 formatex(priv_flags[DAMAGE_FOR_KEY][priv_settings[DAMAGE_FOR_KEY]], charsmax(priv_flags[][]), szFlags);
908
909 priv_settings[DAMAGE_FOR_KEY]++;
910 iLine++;
911 }
912 }
913
914 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/points_kill.ini", configs_dir);
915 if(!file_exists(configuration_file))
916 {
917 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
918 write_file(configuration_file, ";Flags | How many points per kill");
919 write_file(configuration_file, ";Example: default points per kill cvar is set to 10, so player with ^"bit^" flags will receive 12 points");
920 write_file(configuration_file, ";And player with ^"bit^" flags who is also STEAM will receive 15 points (everything sums up)");
921 write_file(configuration_file, ";And player who doesn't have ^"bit^" flags but is a STEAM will receive 13 points");
922 write_file(configuration_file, "^"bit^" 2");
923 write_file(configuration_file, "^"STEAM^" 3");
924
925 priv_bonus[POINTS_KILL][0] = 2;
926 priv_bonus[POINTS_KILL][1] = 3;
927 formatex(priv_flags[POINTS_KILL][0], charsmax(priv_flags[][]), "bit");
928 formatex(priv_flags[POINTS_KILL][1], charsmax(priv_flags[][]), "STEAM");
929 priv_settings[POINTS_KILL] = 2;
930 }
931 else
932 {
933 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
934 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
935 {
936 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
937 {
938 iLine++;
939 continue;
940 }
941 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
942
943 priv_bonus[POINTS_KILL][priv_settings[POINTS_KILL]] = str_to_num(szBonus);
944 formatex(priv_flags[POINTS_KILL][priv_settings[POINTS_KILL]], charsmax(priv_flags[][]), szFlags);
945
946 priv_settings[POINTS_KILL]++;
947 iLine++;
948 }
949 }
950
951 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/points_death.ini", configs_dir);
952 if(!file_exists(configuration_file))
953 {
954 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
955 write_file(configuration_file, ";Flags | How many points per death");
956 write_file(configuration_file, ";Example: default points per death cvar is set to -1, so player with ^"bit^" flags will loose 0 points ( -1 + 1 = 0 )");
957 write_file(configuration_file, "^"bit^" 1");
958
959 priv_bonus[POINTS_DEATH][0] = 1;
960 formatex(priv_flags[POINTS_DEATH][0], charsmax(priv_flags[][]), "bit");
961 priv_settings[POINTS_DEATH] = 1;
962 }
963 else
964 {
965 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
966 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
967 {
968 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
969 {
970 iLine++;
971 continue;
972 }
973 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
974
975 priv_bonus[POINTS_DEATH][priv_settings[POINTS_DEATH]] = str_to_num(szBonus);
976 formatex(priv_flags[POINTS_DEATH][priv_settings[POINTS_DEATH]], charsmax(priv_flags[][]), szFlags);
977
978 priv_settings[POINTS_DEATH]++;
979 iLine++;
980 }
981 }
982
983 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/points_headshot.ini", configs_dir);
984 if(!file_exists(configuration_file))
985 {
986 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
987 write_file(configuration_file, ";Flags | How many EXTRA points for headshot");
988 write_file(configuration_file, "^"bit^" 1");
989
990 priv_bonus[POINTS_HS][0] = 1;
991 formatex(priv_flags[POINTS_HS][0], charsmax(priv_flags[][]), "bit");
992 priv_settings[POINTS_HS] = 1;
993 }
994 else
995 {
996 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
997 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
998 {
999 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
1000 {
1001 iLine++;
1002 continue;
1003 }
1004 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
1005
1006 priv_bonus[POINTS_HS][priv_settings[POINTS_HS]] = str_to_num(szBonus);
1007 formatex(priv_flags[POINTS_HS][priv_settings[POINTS_HS]], charsmax(priv_flags[][]), szFlags);
1008
1009 priv_settings[POINTS_HS]++;
1010 iLine++;
1011 }
1012 }
1013
1014 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/money_kill.ini", configs_dir);
1015 if(!file_exists(configuration_file))
1016 {
1017 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
1018 write_file(configuration_file, ";Flags | How much money per kill");
1019 write_file(configuration_file, ";Example: default money per kill cvar is set to 10, so player with ^"bit^" flags will receive 12$");
1020 write_file(configuration_file, ";And player with ^"bit^" flags who is also STEAM will receive 15$ (everything sums up)");
1021 write_file(configuration_file, ";And player who doesn't have ^"bit^" flags but is a STEAM will receive 13$ ");
1022 write_file(configuration_file, "^"bit^" 2");
1023 write_file(configuration_file, "^"STEAM^" 3");
1024
1025 priv_bonus[MONEY_KILL][0] = 2;
1026 priv_bonus[MONEY_KILL][1] = 3;
1027 formatex(priv_flags[MONEY_KILL][0], charsmax(priv_flags[][]), "bit");
1028 formatex(priv_flags[MONEY_KILL][1], charsmax(priv_flags[][]), "STEAM");
1029 priv_settings[MONEY_KILL] = 2;
1030 }
1031 else
1032 {
1033 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
1034 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
1035 {
1036 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
1037 {
1038 iLine++;
1039 continue;
1040 }
1041 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
1042
1043 priv_bonus[MONEY_KILL][priv_settings[MONEY_KILL]] = str_to_num(szBonus);
1044 formatex(priv_flags[MONEY_KILL][priv_settings[MONEY_KILL]], charsmax(priv_flags[][]), szFlags);
1045
1046 priv_settings[MONEY_KILL]++;
1047 iLine++;
1048 }
1049 }
1050
1051 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/money_headshot.ini", configs_dir);
1052 if(!file_exists(configuration_file))
1053 {
1054 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
1055 write_file(configuration_file, ";Flags | How much EXTRA money for headshot");
1056 write_file(configuration_file, "^"bit^" 1");
1057 write_file(configuration_file, "^"STEAM^" 1");
1058
1059 priv_bonus[MONEY_HS][0] = 1;
1060 priv_bonus[MONEY_HS][1] = 1;
1061 formatex(priv_flags[MONEY_HS][0], charsmax(priv_flags[][]), "bit");
1062 formatex(priv_flags[MONEY_HS][1], charsmax(priv_flags[][]), "STEAM");
1063 priv_settings[MONEY_HS] = 2;
1064 }
1065 else
1066 {
1067 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
1068 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
1069 {
1070 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
1071 {
1072 iLine++;
1073 continue;
1074 }
1075 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
1076
1077 priv_bonus[MONEY_HS][priv_settings[MONEY_HS]] = str_to_num(szBonus);
1078 formatex(priv_flags[MONEY_HS][priv_settings[MONEY_HS]], charsmax(priv_flags[][]), szFlags);
1079
1080 priv_settings[MONEY_HS]++;
1081 iLine++;
1082 }
1083 }
1084
1085 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/points_damage.ini", configs_dir);
1086 if(!file_exists(configuration_file))
1087 {
1088 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
1089 write_file(configuration_file, ";Flags | How many EXTRA points for damage bonus (when a key is received)");
1090 write_file(configuration_file, "^"bit^" 1");
1091 write_file(configuration_file, "^"STEAM^" 1");
1092
1093 priv_bonus[POINTS_DMG][0] = 1;
1094 priv_bonus[POINTS_DMG][1] = 1;
1095 formatex(priv_flags[POINTS_DMG][0], charsmax(priv_flags[][]), "bit");
1096 formatex(priv_flags[POINTS_DMG][1], charsmax(priv_flags[][]), "STEAM");
1097 priv_settings[POINTS_DMG] = 2;
1098 }
1099 else
1100 {
1101 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
1102 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
1103 {
1104 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
1105 {
1106 iLine++;
1107 continue;
1108 }
1109 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
1110
1111 priv_bonus[POINTS_DMG][priv_settings[POINTS_DMG]] = str_to_num(szBonus);
1112 formatex(priv_flags[POINTS_DMG][priv_settings[POINTS_DMG]], charsmax(priv_flags[][]), szFlags);
1113
1114 priv_settings[POINTS_DMG]++;
1115 iLine++;
1116 }
1117 }
1118
1119 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/money_damage.ini", configs_dir);
1120 if(!file_exists(configuration_file))
1121 {
1122 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
1123 write_file(configuration_file, ";Flags | How much EXTRA money for damage bonus (when a key is received)");
1124 write_file(configuration_file, "^"bit^" 1");
1125 write_file(configuration_file, "^"STEAM^" 1");
1126
1127 priv_bonus[MONEY_DMG][0] = 1;
1128 priv_bonus[MONEY_DMG][1] = 1;
1129 formatex(priv_flags[MONEY_DMG][0], charsmax(priv_flags[][]), "bit");
1130 formatex(priv_flags[MONEY_DMG][1], charsmax(priv_flags[][]), "STEAM");
1131 priv_settings[MONEY_DMG] = 2;
1132 }
1133 else
1134 {
1135 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
1136 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
1137 {
1138 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
1139 {
1140 iLine++;
1141 continue;
1142 }
1143 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
1144
1145 priv_bonus[MONEY_DMG][priv_settings[MONEY_DMG]] = str_to_num(szBonus);
1146 formatex(priv_flags[MONEY_DMG][priv_settings[MONEY_DMG]], charsmax(priv_flags[][]), szFlags);
1147
1148 priv_settings[MONEY_DMG]++;
1149 iLine++;
1150 }
1151 }
1152
1153 format(configuration_file, charsmax(configuration_file), "%s/csgo/privileges/chest_protection.ini", configs_dir);
1154 if(!file_exists(configuration_file))
1155 {
1156 write_file(configuration_file, ";If a player has multiple flags, every line sums up");
1157 write_file(configuration_file, ";Flags | How many extra seconds to protect a dropped chest");
1158 write_file(configuration_file, "^"bit^" 1");
1159 write_file(configuration_file, "^"STEAM^" 1");
1160
1161 priv_bonus[CHEST_PROTECTION][0] = 1;
1162 priv_bonus[CHEST_PROTECTION][1] = 1;
1163 formatex(priv_flags[CHEST_PROTECTION][0], charsmax(priv_flags[][]), "bit");
1164 formatex(priv_flags[CHEST_PROTECTION][1], charsmax(priv_flags[][]), "STEAM");
1165 priv_settings[CHEST_PROTECTION] = 2;
1166 }
1167 else
1168 {
1169 new szData[256], szFlags[32], szBonus[16], iTextLength, iLine;
1170 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
1171 {
1172 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
1173 {
1174 iLine++;
1175 continue;
1176 }
1177 parse(szData, szFlags, charsmax(szFlags), szBonus, charsmax(szBonus));
1178
1179 priv_bonus[CHEST_PROTECTION][priv_settings[CHEST_PROTECTION]] = str_to_num(szBonus);
1180 formatex(priv_flags[CHEST_PROTECTION][priv_settings[CHEST_PROTECTION]], charsmax(priv_flags[][]), szFlags);
1181
1182 priv_settings[CHEST_PROTECTION]++;
1183 iLine++;
1184 }
1185 }
1186}
1187public loadConfiguration()
1188{
1189 new configs_dir[128], configuration_file[128];
1190 get_configsdir(configs_dir, charsmax(configs_dir));
1191
1192 format(configuration_file, charsmax(configuration_file), "%s/csgo", configs_dir);
1193 if(!dir_exists(configuration_file)) mkdir(configuration_file);
1194
1195 format(configuration_file, charsmax(configuration_file), "%s/csgo/chests.ini", configs_dir);
1196 if(!file_exists(configuration_file))
1197 {
1198 write_file(configuration_file, ";Chest name | Chance % | Model");
1199 write_file(configuration_file, "^"Example chest^" 0.001 ^"models/csgo/chests/example.mdl^"");
1200 write_file(configuration_file, "^"Example chest #2^" 50 ^"models/csgo/chests/example.mdl^"");
1201
1202 formatex(chestNames[0], charsmax(chestNames[]), "Example chest");
1203 formatex(chestNames[1], charsmax(chestNames[]), "Example chest #2");
1204
1205 chestChances[0] = 0.001;
1206 chestChances[1] = 50.0;
1207
1208 formatex(chestModel[0], charsmax(chestModel[]), "models/csgo/chests/example.mdl");
1209 formatex(chestModel[1], charsmax(chestModel[]), "models/csgo/chests/example.mdl");
1210
1211 precache_model(chestModel[0]);
1212 precache_model(chestModel[1]);
1213
1214 chestsCount = 2;
1215 }
1216 else
1217 {
1218 new szData[256], szCommand[64], szChance[64], szModel[128], iTextLength, iLine;
1219 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
1220 {
1221 if(MAX_CHESTS <= chestsCount) break;
1222 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
1223 {
1224 iLine++;
1225 continue;
1226 }
1227 parse(szData, szCommand, charsmax(szCommand), szChance, charsmax(szChance), szModel, charsmax(szModel));
1228
1229 formatex(chestNames[chestsCount], charsmax(chestNames[]), "%s", szCommand);
1230
1231 chestChances[chestsCount] = str_to_float(szChance);
1232 formatex(chestModel[chestsCount], charsmax(chestModel[]), szModel);
1233
1234 if(strlen(chestModel[chestsCount]) > 5) precache_model(chestModel[chestsCount]);
1235
1236 chestsCount++;
1237 iLine++;
1238 }
1239 }
1240
1241 format(configuration_file, charsmax(configuration_file), "%s/csgo/rangs.ini", configs_dir);
1242 if(!file_exists(configuration_file))
1243 {
1244 write_file(configuration_file, ";Write all your rangs and rang points needed here");
1245 write_file(configuration_file, "^"[Rang #1] ^" 0");
1246 write_file(configuration_file, "^"[Rang #2] ^" 10");
1247
1248 formatex(rangNames[0], charsmax(rangNames[]), "Rang #1");
1249 formatex(rangNames[1], charsmax(rangNames[]), "Rang #2");
1250 rangsCount = 2;
1251 }
1252 else
1253 {
1254 new szData[256], szCommand[64], szParam[64], iTextLength, iLine;
1255 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
1256 {
1257 if(MAX_RANGS <= rangsCount) break;
1258 if (szData[0] == ';' || !szData[0] || strlen(szData) < 5 || szData[0] == '/')
1259 {
1260 iLine++;
1261 continue;
1262 }
1263 parse(szData, szCommand, charsmax(szCommand), szParam, charsmax(szParam));
1264
1265 formatex(rangNames[rangsCount], charsmax(rangNames[]), "%s", szCommand);
1266 rangPoints[rangsCount] = str_to_num(szParam);
1267 rangsCount++;
1268 iLine++;
1269 }
1270 }
1271
1272 format(configuration_file, charsmax(configuration_file), "%s/csgo/skins.cfg", configs_dir);
1273 if(!file_exists(configuration_file))
1274 {
1275 write_file(configuration_file, ";Weapon id | Weapon name | Model v_ directory | Chances % (How many chests that many numbers. 0 - means that skin wont drop from that chest)");
1276
1277 new szText[256], szLine[256];
1278 formatex(szText, charsmax(szText), "^"");
1279 for(new i; i < chestsCount; i++)
1280 {
1281 new Float:chance = random_float(0.0001, 100.0);
1282 formatex(szText, charsmax(szText), "%s%f ", szText, chance);
1283
1284 skin_chances[0][i] = chance;
1285 skin_chances[1][i] = chance;
1286 }
1287 formatex(szText, charsmax(szText), "%s^"", szText);
1288
1289 formatex(szLine, charsmax(szLine), "^"28^" ^"Example | AK47^" ^"models/v_ak47.mdl^" %s", szText);
1290 write_file(configuration_file, szLine);
1291
1292 formatex(szLine, charsmax(szLine), "^"29^" ^"Example | Knife^" ^"models/v_knife.mdl^" %s", szText);
1293 write_file(configuration_file, szLine);
1294
1295 formatex(skinNames[0], charsmax(skinNames[]), "Example | AK47");
1296 formatex(skin_model[0], charsmax(skin_model[]), "models/v_ak47.mdl");
1297 skin_weapon_id[0] = 28;
1298
1299 formatex(skinNames[1], charsmax(skinNames[]), "Example | Knife");
1300 formatex(skin_model[1], charsmax(skin_model[]), "models/v_knife.mdl");
1301 skin_weapon_id[1] = 29;
1302
1303 precache_model(skin_model[0]);
1304 precache_model(skin_model[1]);
1305
1306 skinsCount = 2;
1307 }
1308 else
1309 {
1310 new szData[256], Data[7][128], iTextLength, iLine;
1311 while (read_file(configuration_file, iLine, szData, charsmax(szData), iTextLength) != 0)
1312 {
1313 if(MAX_SKINS <= skinsCount) break;
1314 if (szData[0] == ';' || !szData[0] || szData[0] == '/' || strlen(szData) < 5)
1315 {
1316 iLine++;
1317 continue;
1318 }
1319 parse(szData, Data[0], charsmax(Data[]), Data[1], charsmax(Data[]), Data[2], charsmax(Data[]), Data[3], charsmax(Data[]));
1320
1321 formatex(skinNames[skinsCount], charsmax(skinNames[]), Data[1]);
1322 formatex(skin_model[skinsCount], charsmax(skin_model[]), Data[2]);
1323 skin_weapon_id[skinsCount] = str_to_num(Data[0]);
1324 precache_model(skin_model[skinsCount]);
1325
1326 new tempString[MAX_CHESTS][8];
1327 ExplodeString(tempString, MAX_CHESTS, charsmax(tempString[]), Data[3], ' ');
1328
1329 for(new i; i < chestsCount; i++)
1330 {
1331 skin_chances[skinsCount][i] = str_to_float(tempString[i]);
1332 }
1333
1334 skinsCount++;
1335 iLine++;
1336 }
1337 }
1338}