#include #include #include #include #include #define LIBRARY_NEMESIS "zp50_class_nemesis" #include #define LIBRARY_SURVIVOR "zp50_class_survivor" #include #define LIBRARY_SNIPER "zp50_class_sniper" #include #define LIBRARY_ASSASSIN "zp50_class_assassin" #include new Handle:Connect; new SayText; new iKillZombie[32], iKillHuman[32]; new iInfections[32], iInfected[32]; new iAntidoted[32]; new iDeath[32]; new iLastZombie[32], iLastHuman[32]; new iNemesis[32], iAssassin[32]; new iSurvivor[32], iSniper[32]; new iFirstZombie[32]; new iLZInfect[32]; public plugin_init() { register_plugin("[ZP] Rank", "1.0", "Szapko"); register_event("DeathMsg", "DeathEvent", "a"); register_logevent("newround",2,"1=Round_Start"); SayText = get_user_msgid("SayText"); Connect = SQL_MakeDbTuple("", "", "", ""); } public plugin_natives() { set_module_filter("module_filter"); set_native_filter("native_filter"); } public module_filter(const module[]) { if (equal(module, LIBRARY_NEMESIS) || equal(module, LIBRARY_SURVIVOR) || equal(module, LIBRARY_SNIPER) || equal(module, LIBRARY_ASSASSIN)) return PLUGIN_HANDLED; return PLUGIN_CONTINUE; } public native_filter(const name[], index, trap) { if (!trap) return PLUGIN_HANDLED; return PLUGIN_CONTINUE; } check_rank(id) { new DataID[1]; new qCommand[512], PlayerID[32]; DataID[0] = id; get_user_name(id, PlayerID, charsmax(PlayerID)); format(qCommand, sizeof qCommand-1, "SELECT * FROM `zp_rank` WHERE `zp_nick`=^"%s^"", PlayerID); SQL_ThreadQuery(Connect, "handler_check", qCommand, DataID, 1); } update_rank(id) { new DataID[1]; new PlayerID[32]; new qCommand[512], qCommand2[512]; DataID[0] = id; get_user_name(id, PlayerID, charsmax(PlayerID)); format(qCommand, sizeof qCommand-1, "UPDATE `zp_rank` SET `zp_kill_zombie`='%i', `zp_kill_human`='%i', `zp_death`='%i', `zp_infections`='%i', `zp_infected`='%i', `zp_antidoted`='%i', `zp_last_zombie`='%i', `zp_last_human`='%i', `zp_first_zombie`='%i' WHERE `zp_nick`=^"%s^"", iKillZombie[id], iKillHuman[id], iDeath[id], iInfections[id], iInfected[id], iAntidoted[id], iLastZombie[id], iLastHuman[id], iFirstZombie[id], PlayerID); SQL_ThreadQuery(Connect, "handler_update", qCommand, DataID, 1); format(qCommand2, sizeof qCommand2-1, "UPDATE `zp_rank` SET `zp_nemesis`='%i', `zp_assassin`='%i', `zp_survivor`='%i', `zp_sniper`='%i' WHERE `zp_nick`=^"%s^"", iNemesis[id], iAssassin[id], iSurvivor[id], iSniper[id], PlayerID); SQL_ThreadQuery(Connect, "handler_update", qCommand2, DataID, 1); } save_rank(id) { new DataID[1]; new qCommand[512], PlayerID[32]; DataID[0] = id; get_user_name(id, PlayerID, charsmax(PlayerID)); format(qCommand, sizeof qCommand-1, "INSERT INTO `zp_rank` VALUES ( '', ^"%s^", %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i, %i);", PlayerID, iKillZombie[id], iKillHuman[id], iDeath[id], iInfections[id], iInfected[id], iAntidoted[id], iLastZombie[id], iLastHuman[id], iFirstZombie[id], iNemesis[id], iAssassin[id] ,iSurvivor[id] ,iSniper[id]); SQL_ThreadQuery(Connect, "handler_save", qCommand, DataID, 1); } remove_all(id) { iKillZombie[id] = 0; iKillHuman[id] = 0; iDeath[id] = 0; iInfections[id] = 0; iInfected[id] = 0; iAntidoted[id] = 0; iLastZombie[id] = 0; iLastHuman[id] = 0; iFirstZombie[id] = 0; iNemesis[id] = 0; iAssassin[id] = 0; iSurvivor[id] = 0; iSniper[id] = 0; } public client_disconnect(id) { update_rank(id); remove_all(id); } public client_putinserver(id) { remove_all(id); check_rank(id); } public plugin_end() { SQL_FreeHandle(Connect); } public newround(id) { client_print(id, print_chat, "[RANK] iLZInfect - %i", iLZInfect[id]) iLZInfect[id] = 0; } public zp_fw_gamemodes_start(game_mode_id) { new Players[32], Num; get_players(Players, Num); for (new i = 0; i 0) { iLastHuman[id] += 1; } return PLUGIN_CONTINUE; } public handler_save(FailState, Handle:Query, Error[], Errorcode, Data[], DataSize) { new id = Data[0]; if (Errorcode) { log_amx("[save_rank] Blad w zapytaniu: %s", Error); } if (FailState == TQUERY_CONNECT_FAILED) { log_amx("[save_rank] Nie mozna podlaczyc sie do bazy danych"); return PLUGIN_CONTINUE; } else if(FailState == TQUERY_QUERY_FAILED) { log_amx("[save_rank] Zapytanie anulowane"); return PLUGIN_CONTINUE; } return PLUGIN_CONTINUE; } public handler_check(FailState, Handle:Query, Error[], Errorcode, Data[], DataSize) { new id = Data[0]; if (Errorcode) { } if (FailState == TQUERY_CONNECT_FAILED) { return PLUGIN_CONTINUE; } else if(FailState == TQUERY_QUERY_FAILED) { return PLUGIN_CONTINUE; } if (!SQL_MoreResults(Query)) { save_rank(id); } else { iKillZombie[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_kill_zombie")); iKillHuman[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_kill_human")); iDeath[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_death")); iInfections[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_infections")); iInfected[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_infected")); iAntidoted[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_antidoted")); iLastZombie[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_last_zombie")); iLastHuman[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_last_human")); iFirstZombie[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_first_zombie")); iNemesis[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_nemesis")); iAssassin[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_assassin")); iSurvivor[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_survivor")); iSniper[id] = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "zp_sniper")); } return PLUGIN_CONTINUE; } public handler_update(FailState, Handle:Query, Error[], Errorcode, Data[], DataSize) { new id = Data[0]; if (Errorcode) { } else { } if (FailState == TQUERY_CONNECT_FAILED) { return PLUGIN_CONTINUE; } else if(FailState == TQUERY_QUERY_FAILED) { return PLUGIN_CONTINUE; } return PLUGIN_CONTINUE; } stock client_printcolor(const id, const input[], any:...) { new count = 1, players[32]; static msg[191]; vformat(msg, 190, input, 3); replace_all(msg, 190, "!g", "^4"); // Green Color replace_all(msg, 190, "!y", "^1"); // Default Color replace_all(msg, 190, "!t", "^3"); // Team Color if (id) players[0] = id; else get_players(players, count, "ch") { for (new i = 0; i < count; i++) { if (is_user_connected(players[i])) { message_begin(MSG_ONE_UNRELIABLE, SayText, _, players[i]); write_byte(players[i]); write_string(msg); message_end(); } } } }