Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.50 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <cstrike>
  3. #include <hamsandwich>
  4. #include <nvault>
  5. #include <csgomod>
  6.  
  7. #define PLUGIN "CS:GO Operations"
  8. #define VERSION "1.1"
  9. #define AUTHOR "O'Zone"
  10.  
  11. #define get_bit(%2,%1) (%1 & (1<<(%2&31)))
  12. #define set_bit(%2,%1) (%1 |= (1<<(%2&31)))
  13. #define rem_bit(%2,%1) (%1 &= ~(1 <<(%2&31)))
  14.  
  15. new operationDescription[][] = {
  16.     "Brak operacji %i",
  17.     "Musisz zabic jeszcze %i osob",
  18.     "Musisz zabic jeszcze %i osob headshotem",
  19.     "Musisz podlozyc/rozbroic bombe jeszcze %i razy",
  20.     "Musisz zadac jeszcze %i obrazen"
  21. };
  22.  
  23. enum _:operationType { TYPE_NONE, TYPE_KILL, TYPE_HEADSHOT, TYPE_BOMB, TYPE_DAMAGE };
  24. enum _:playerInfo { PLAYER_ID, PLAYER_TYPE, PLAYER_ADDITIONAL, PLAYER_PROGRESS, PLAYER_NAME[32] };
  25. enum _:operationsInfo { OPERATION_AMOUNT, OPERATION_TYPE, OPERATION_REWARD };
  26.  
  27. new const commandQuest[][] = { "say /operacja", "say_team /operacja", "say /misja", "say_team /misja", "say /misje", "say_team /misje", "say /operacje", "say_team /operacje", "misje" };
  28. new const commandProgress[][] = { "say /progress", "say_team /progress", "say /progres", "say_team /progres", "say /postep", "say_team /postep", "postep" };
  29. new const commandEnd[][] = { "say /koniec", "say_team /koniec", "say /zakoncz", "say_team /zakoncz", "zakoncz", "say_team /przerwij", "say /przerwij", "przerwij" };
  30.  
  31. new playerData[MAX_PLAYERS + 1][playerInfo], Array:operationList, minPlayers, operations, loaded;
  32.  
  33. public plugin_init()
  34. {
  35.     register_plugin(PLUGIN, VERSION, AUTHOR);
  36.  
  37.     bind_pcvar_num(register_cvar("csgo_operations_min_players", "4"), minPlayers);
  38.  
  39.     for(new i; i < sizeof commandQuest; i++) register_clcmd(commandQuest[i], "operation_menu");
  40.     for(new i; i < sizeof commandProgress; i++) register_clcmd(commandProgress[i], "check_operation");
  41.     for(new i; i < sizeof commandEnd; i++) register_clcmd(commandEnd[i], "reset_operation");
  42.  
  43.     RegisterHam(Ham_TakeDamage, "player", "player_take_damage_post", 1);
  44.  
  45.     register_logevent("log_event_operation", 3, "1=triggered");
  46.  
  47.     operations = nvault_open("csgo_operations");
  48.  
  49.     if (operations == INVALID_HANDLE) set_fail_state("Nie mozna otworzyc pliku csgo_operations.vault");
  50.  
  51.     operationList = ArrayCreate(operationsInfo);
  52. }
  53.  
  54. public plugin_natives()
  55. {
  56.     register_native("csgo_get_user_operation", "_csgo_get_user_operation", 1);
  57.     register_native("csgo_get_user_operation_text", "_csgo_get_user_operation_text", 1);
  58.     register_native("csgo_get_user_operation_progress", "_csgo_get_user_operation_progress", 1);
  59.     register_native("csgo_get_user_operation_need", "_csgo_get_user_operation_need", 1);
  60. }
  61.  
  62. public plugin_cfg()
  63. {
  64.     new filePath[64];
  65.  
  66.     get_localinfo("amxx_configsdir", filePath, charsmax(filePath));
  67.     format(filePath, charsmax(filePath), "%s/csgo_operations.ini", filePath);
  68.  
  69.     if (!file_exists(filePath)) {
  70.         new error[128];
  71.  
  72.         formatex(error, charsmax(error), "[CS:GO] Nie mozna znalezc pliku csgo_operations.ini w lokalizacji %s", filePath);
  73.  
  74.         set_fail_state(error);
  75.     }
  76.  
  77.     new lineData[128], operationData[4][16], operationInfo[operationsInfo], file = fopen(filePath, "r");
  78.  
  79.     ArrayPushArray(operationList, operationInfo);
  80.  
  81.     while (!feof(file)) {
  82.         fgets(file, lineData, charsmax(lineData));
  83.  
  84.         if (lineData[0] == ';' || lineData[0] == '^0') continue;
  85.  
  86.         parse(lineData, operationData[0], charsmax(operationData[]), operationData[1], charsmax(operationData[]), operationData[2], charsmax(operationData[]));
  87.  
  88.         operationInfo[OPERATION_AMOUNT] = str_to_num(operationData[0]);
  89.         operationInfo[OPERATION_TYPE] = str_to_num(operationData[1]);
  90.         operationInfo[OPERATION_REWARD] = str_to_num(operationData[2]);
  91.  
  92.         ArrayPushArray(operationList, operationInfo);
  93.     }
  94.  
  95.     fclose(file);
  96. }
  97.  
  98. public plugin_end()
  99.     nvault_close(operations);
  100.  
  101. public client_disconnected(id)
  102.     rem_bit(id, loaded);
  103.  
  104. public client_putinserver(id)
  105. {
  106.     reset_operation(id, 1, 1);
  107.  
  108.     if (is_user_bot(id) || is_user_hltv(id)) return PLUGIN_HANDLED;
  109.  
  110.     get_user_name(id, playerData[id][PLAYER_NAME], charsmax(playerData[][PLAYER_NAME]));
  111.  
  112.     load_operation(id);
  113.  
  114.     return PLUGIN_HANDLED;
  115. }
  116.  
  117. public operation_menu(id)
  118. {
  119.     if (!csgo_check_account(id)) return PLUGIN_HANDLED;
  120.  
  121.     new menu = menu_create("\yMenu \rOperacji\w:", "operation_menu_handle"), callback = menu_makecallback("operation_menu_callback");
  122.  
  123.     menu_additem(menu, "Wybierz \yOperacje", _, _, callback);
  124.     menu_additem(menu, "Przerwij \yOperacje", _, _, callback);
  125.     menu_additem(menu, "Postep \yOperacji", _, _, callback);
  126.  
  127.     menu_addtext(menu, "^n\wPo ukonczeniu \yoperacji\w zostaniesz wynagrodzony \rpieniedzmi\w.", 0);
  128.     menu_addtext(menu, "\wMozesz \ywielokrotnie\w wykonywac ta sama operacje.", 0);
  129.  
  130.     menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
  131.  
  132.     menu_display(id, menu);
  133.  
  134.     return PLUGIN_HANDLED;
  135. }
  136.  
  137. public operation_menu_handle(id, menu, item)
  138. {
  139.     if (!is_user_connected(id)) return PLUGIN_HANDLED;
  140.  
  141.     if (item == MENU_EXIT) {
  142.         menu_destroy(menu);
  143.  
  144.         return PLUGIN_HANDLED;
  145.     }
  146.  
  147.     switch(item) {
  148.         case 0: select_operation(id);
  149.         case 1: reset_operation(id, 0, 0);
  150.         case 2: check_operation(id);
  151.     }
  152.  
  153.     return PLUGIN_HANDLED;
  154. }
  155.  
  156. public operation_menu_callback(id, menu, item)
  157. {
  158.     switch(item) {
  159.         case 0: if (playerData[id][PLAYER_TYPE]) return ITEM_DISABLED;
  160.         case 1, 2: if (!playerData[id][PLAYER_TYPE]) return ITEM_DISABLED;
  161.     }
  162.  
  163.     return ITEM_ENABLED;
  164. }
  165.  
  166. public select_operation(id)
  167. {
  168.     if (!is_user_connected(id)) return PLUGIN_HANDLED;
  169.  
  170.     if (playerData[id][PLAYER_TYPE]) {
  171.         client_print_color(id, id, "^x04[CS:GO]^x01 Najpierw dokoncz lub zrezygnuj z obecnej^x03 operacji^x01.");
  172.  
  173.         return PLUGIN_HANDLED;
  174.     }
  175.  
  176.     new menuData[128], operationId[3], operationInfo[operationsInfo], menu = menu_create("\yWybierz \rMisje\w:", "select_operation_handle");
  177.  
  178.     for (new i = 0; i < ArraySize(operationList); i++) {
  179.         ArrayGetArray(operationList, i, operationInfo);
  180.  
  181.         switch(operationInfo[OPERATION_TYPE]) {
  182.             case TYPE_KILL: formatex(menuData, charsmax(menuData), "Zabij %i osob \y(Nagroda: %i Euro)", operationInfo[OPERATION_AMOUNT], operationInfo[OPERATION_REWARD]);
  183.             case TYPE_HEADSHOT: formatex(menuData, charsmax(menuData), "Zabij %i osob z HS \y(Nagroda: %i Euro)",  operationInfo[OPERATION_AMOUNT], operationInfo[OPERATION_REWARD]);
  184.             case TYPE_BOMB: formatex(menuData, charsmax(menuData), "Podloz/Rozbroj %i bomb \y(Nagroda: %i Euro)",  operationInfo[OPERATION_AMOUNT], operationInfo[OPERATION_REWARD]);
  185.             case TYPE_DAMAGE: formatex(menuData, charsmax(menuData), "Zadaj %i obrazen \y(Nagroda: %i Euro)",  operationInfo[OPERATION_AMOUNT], operationInfo[OPERATION_REWARD]);
  186.             case TYPE_NONE: continue;
  187.         }
  188.  
  189.         num_to_str(i, operationId, charsmax(operationId));
  190.  
  191.         menu_additem(menu, menuData, operationId);
  192.     }
  193.  
  194.     menu_setprop(menu, MPROP_EXITNAME, "Wyjscie");
  195.  
  196.     menu_display(id, menu);
  197.  
  198.     return PLUGIN_HANDLED;
  199. }
  200.  
  201. public select_operation_handle(id, menu, item)
  202. {
  203.     if (!is_user_connected(id)) return PLUGIN_HANDLED;
  204.  
  205.     if (item == MENU_EXIT) {
  206.         menu_destroy(menu);
  207.  
  208.         return PLUGIN_HANDLED;
  209.     }
  210.  
  211.     new operationId[3], itemAccess, itemCallback;
  212.  
  213.     menu_item_getinfo(menu, item, itemAccess, operationId, charsmax(operationId), _, _, itemCallback);
  214.  
  215.     reset_operation(id, 1, 1);
  216.  
  217.     playerData[id][PLAYER_ID] = str_to_num(operationId);
  218.     playerData[id][PLAYER_TYPE] = get_operation_info(playerData[id][PLAYER_ID], OPERATION_TYPE);
  219.  
  220.     save_operation(id);
  221.  
  222.     client_print_color(id, id, "^x04[CS:GO]^x01 Rozpoczales nowa^x03 operacje^x01. Powodzenia!");
  223.  
  224.     menu_destroy(menu);
  225.  
  226.     return PLUGIN_HANDLED;
  227. }
  228.  
  229. public client_death(killer, victim, weaponId, hitPlace, teamKill)
  230. {
  231.     if (!is_user_connected(killer) || !is_user_connected(victim) || !is_user_alive(killer) || get_user_team(victim) == get_user_team(killer)) return PLUGIN_CONTINUE;
  232.  
  233.     switch(playerData[killer][PLAYER_TYPE]) {
  234.         case TYPE_KILL: add_progress(killer);
  235.         case TYPE_HEADSHOT: if (hitPlace == HIT_HEAD) add_progress(killer);
  236.     }
  237.  
  238.     return HAM_IGNORED;
  239. }
  240.  
  241. public player_take_damage_post(victim, inflictor, attacker, Float:damage, damageBits)
  242. {
  243.     if (!is_user_connected(attacker) || !is_user_connected(victim) || get_user_team(victim) == get_user_team(attacker)) return HAM_IGNORED;
  244.  
  245.     if (playerData[attacker][PLAYER_TYPE] == TYPE_DAMAGE) add_progress(attacker, floatround(damage));
  246.  
  247.     return HAM_IGNORED;
  248. }
  249.  
  250. public log_event_operation()
  251. {
  252.     new userLog[80], userAction[64], userName[32];
  253.  
  254.     read_logargv(0, userLog, charsmax(userLog));
  255.     read_logargv(2, userAction, charsmax(userAction));
  256.     parse_loguser(userLog, userName, charsmax(userName));
  257.  
  258.     new id = get_user_index(userName);
  259.  
  260.     if (!is_user_connected(id) || playerData[id][PLAYER_TYPE] == TYPE_NONE) return PLUGIN_HANDLED;
  261.  
  262.     if ((equal(userAction, "Planted_The_Bomb") || equal(userAction, "Defused_The_Bomb")) && playerData[id][PLAYER_TYPE] == TYPE_BOMB) add_progress(id);
  263.  
  264.     return PLUGIN_HANDLED;
  265. }
  266.  
  267. public give_reward(id)
  268. {
  269.     if (!is_user_connected(id)) return PLUGIN_HANDLED;
  270.  
  271.     new reward = get_operation_info(playerData[id][PLAYER_ID], OPERATION_REWARD);
  272.  
  273.     csgo_add_money(id, float(reward));
  274.  
  275.     reset_operation(id, 0, 1);
  276.  
  277.     client_print_color(id, id, "^x04[CS:GO]^x01 Gratulacje! Ukonczyles operacje - w nagrode otrzymujesz^x03 %i Euro^x01.", reward);
  278.  
  279.     return PLUGIN_HANDLED;
  280. }
  281.  
  282. public check_operation(id)
  283. {
  284.     if (!playerData[id][PLAYER_TYPE]) client_print_color(id, id, "^x04[CS:GO]^x01 Nie jestes w trakcie wykonywania zadnej operacji.");
  285.     else {
  286.         new message[128];
  287.  
  288.         formatex(message, charsmax(message), operationDescription[playerData[id][PLAYER_TYPE]], (get_progress_need(id) - get_progress(id)));
  289.  
  290.         client_print_color(id, id, "^x04[CS:GO]^x01 Postep operacji:^x03 %s^x01.", message);
  291.     }
  292.  
  293.     return PLUGIN_HANDLED;
  294. }
  295.  
  296. public save_operation(id)
  297. {
  298.     if (!get_bit(id, loaded)) return PLUGIN_HANDLED;
  299.  
  300.     new vaultKey[64], vaultData[64];
  301.  
  302.     formatex(vaultKey, charsmax(vaultKey), "%s", playerData[id][PLAYER_NAME]);
  303.     formatex(vaultData, charsmax(vaultData), "%i %i %i %i", playerData[id][PLAYER_ID], playerData[id][PLAYER_TYPE], playerData[id][PLAYER_ADDITIONAL], playerData[id][PLAYER_PROGRESS]);
  304.  
  305.     nvault_set(operations, vaultKey, vaultData);
  306.  
  307.     return PLUGIN_HANDLED;
  308. }
  309.  
  310. public load_operation(id)
  311. {
  312.     new vaultKey[64], vaultData[64], operationData[4][16], operationParam[4];
  313.  
  314.     formatex(vaultKey, charsmax(vaultKey), "%s", playerData[id][PLAYER_NAME]);
  315.  
  316.     if (nvault_get(operations, vaultKey, vaultData, charsmax(vaultData))) {
  317.         parse(vaultData, operationData[0], charsmax(operationData[]), operationData[1], charsmax(operationData[]), operationData[2], charsmax(operationData[]), operationData[3], charsmax(operationData[]));
  318.  
  319.         for (new i = 0; i < sizeof operationParam; i++) operationParam[i] = str_to_num(operationData[i]);
  320.  
  321.         if (operationParam[0] > -1) {
  322.             playerData[id][PLAYER_ID] = operationParam[0];
  323.             playerData[id][PLAYER_TYPE] = operationParam[1];
  324.             playerData[id][PLAYER_ADDITIONAL] = operationParam[2];
  325.             playerData[id][PLAYER_PROGRESS] = operationParam[3];
  326.         }
  327.     }
  328.  
  329.     set_bit(id, loaded);
  330.  
  331.     return PLUGIN_HANDLED;
  332. }
  333.  
  334. public reset_operation(id, data, silent)
  335. {
  336.     playerData[id][PLAYER_TYPE] = TYPE_NONE;
  337.     playerData[id][PLAYER_ID] = -1;
  338.     playerData[id][PLAYER_PROGRESS] = 0;
  339.  
  340.     if (!data) save_operation(id);
  341.  
  342.     if (!silent) client_print_color(id, id, "^x04[CS:GO]^x01 Zrezygnowales z wykonywania rozpoczetej przez ciebie^x03 operacji^x01.");
  343.  
  344.     return PLUGIN_HANDLED;
  345. }
  346.  
  347. stock get_operation_info(operation, info)
  348. {
  349.     new operationInfo[operationsInfo];
  350.  
  351.     ArrayGetArray(operationList, operation, operationInfo);
  352.  
  353.     return operationInfo[info];
  354. }
  355.  
  356. stock add_progress(id, amount = 1)
  357. {
  358.     if (!is_user_connected(id) || get_playersnum() < minPlayers) return PLUGIN_HANDLED;
  359.  
  360.     playerData[id][PLAYER_PROGRESS] += amount;
  361.  
  362.     if (get_progress(id) >= get_progress_need(id)) give_reward(id);
  363.     else save_operation(id);
  364.  
  365.     return PLUGIN_HANDLED;
  366. }
  367.  
  368. stock get_progress(id)
  369.     return playerData[id][PLAYER_ID] > -1 ? playerData[id][PLAYER_PROGRESS] : -1;
  370.  
  371. stock get_progress_need(id)
  372.     return playerData[id][PLAYER_TYPE] ? get_operation_info(playerData[id][PLAYER_ID], OPERATION_AMOUNT) : -1;
  373.  
  374. public _csgo_get_user_operation(id)
  375.     return playerData[id][PLAYER_ID];
  376.  
  377. public _csgo_get_user_operation_text(id, dataReturn[], dataLength)
  378. {
  379.     param_convert(2);
  380.  
  381.     if (playerData[id][PLAYER_ID] > -1) formatex(dataReturn, dataLength, "%i/%i (%0.1f%s)", get_progress(id), get_progress_need(id), float(get_progress(id)) / float(get_progress_need(id)) * 100.0, "%");
  382.     else formatex(dataReturn, dataLength, "Wpisz /operacja");
  383. }
  384.  
  385. public _csgo_get_user_operation_progress(id)
  386.     return get_progress(id);
  387.  
  388. public _csgo_get_user_operation_need(id)
  389.     return get_progress_need(id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement