Advertisement
BigETI

kills.pwn

Oct 24th, 2013
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.92 KB | None | 0 0
  1. #include <a_samp>
  2. #include <list>
  3.  
  4. #define NO_RESPONSE_DIALOGID                            (0)
  5. #define LASTKILLS_DIALOGID                              (1000)
  6.  
  7. #if NO_RESPONSE_DIALOGID == LASTKILLS_DIALOGID
  8.     #error You are not allowed to set NO_RESPONSE_DIALOGID equal LASTKILLS_DIALOGID.
  9. #endif
  10.  
  11. #define NULL_PTR                                        (Pointer:NULL)
  12. #define KILLS_FILE                                      "kills.binlist"
  13. #define MAX_LIST_KILLS                                  (30)
  14. #define GetDistanceBetweenPoints%6(%0,%1,%2,%3,%4,%5)   floatsqroot(floatpower((%3)-(%0),2.0)+floatpower((%4)-(%1),2.0)+floatpower((%5)-(%2),2.0))
  15.  
  16. MEM::struct kill_struct
  17. {
  18.     kill_datetime,
  19.     kill_victimid,
  20.     kill_victimip[16],
  21.     kill_victimname[MAX_PLAYER_NAME],
  22.     kill_killerid,
  23.     kill_killerip[16],
  24.     kill_killername[MAX_PLAYER_NAME],
  25.     kill_reason,
  26.     Float:kill_victimpos_x,
  27.     Float:kill_victimpos_y,
  28.     Float:kill_victimpos_z,
  29.     Float:kill_victimpos_rotz,
  30.     Float:kill_killerpos_x,
  31.     Float:kill_killerpos_y,
  32.     Float:kill_killerpos_z,
  33.     Float:kill_killerpos_rotz
  34. }
  35.  
  36. new LIST::init<kills_list>, Pointer:kill_ptrs_arr[MAX_PLAYERS] = {NULL_PTR, ...}, listed_kills[MAX_PLAYERS] = {0, ...};
  37.  
  38. static const WeapName[202][32] = {
  39.     "N/A",                  // 0
  40.     "Brass Knuckles",       // 1
  41.     "Golf Club",            // 2
  42.     "Night Stick",          // 3
  43.     "Knife",                // 4
  44.     "Baseball Bat",         // 5
  45.     "Shovel",               // 6
  46.     "Pool Cue",             // 7
  47.     "Katana",               // 8
  48.     "Chainsaw",             // 9
  49.     "Dildo",                // 10
  50.     "B-White Vibrator",     // 11
  51.     "M-White Vibrator",     // 12
  52.     "S-White Vibrator",     // 13
  53.     "Flowers",              // 14
  54.     "Cane",                 // 15
  55.     "Grenade",              // 16
  56.     "Teargas",              // 17
  57.     "Molotov",              // 18
  58.     "Vehicle missile",      // 19
  59.     "Hydra flare",          // 20
  60.     "Jetpack",              // 21
  61.     "Pistol",               // 22
  62.     "S-Pistol",             // 23
  63.     "Deagle",               // 24
  64.     "Shotgun",              // 25
  65.     "Sawnoff",              // 26
  66.     "SPAZ",                 // 27
  67.     "UZI",                  // 28
  68.     "MP5",                  // 29
  69.     "AK47",                 // 30
  70.     "M4",                   // 31
  71.     "Tec9",                 // 32
  72.     "Country Rifle",        // 33
  73.     "Sniper",               // 34
  74.     "RPG",                  // 35
  75.     "HS RPG",               // 36
  76.     "Flamethrower",         // 37
  77.     "Minigun",              // 38
  78.     "Satchel Bombs",        // 39
  79.     "Detonator",            // 40
  80.     "Spray Can",            // 41
  81.     "Fire Extinguisher",    // 42
  82.     "Camera",               // 43
  83.     "NV Goggles",           // 44
  84.     "IRV Goggles",          // 45
  85.     "Parachute",            // 46
  86.     "Fake Pistol",          // 47
  87.     " ",                    //
  88.     "Vehicle",              // 49
  89.     "Helicopter blades",    // 50
  90.     "Explosion",            // 51
  91.     " ",                    //
  92.     " ",                    //
  93.     "Collision",            // 54
  94.     " ",                    //
  95.     " ",                    //
  96.     " ",                    //
  97.     " ",                    //
  98.     " ",                    //
  99.     " ",                    // 60
  100.     " ",                    //
  101.     " ",                    //
  102.     " ",                    //
  103.     " ",                    //
  104.     " ",                    //
  105.     " ",                    //
  106.     " ",                    //
  107.     " ",                    //
  108.     " ",                    //
  109.     " ",                    // 70
  110.     " ",                    //
  111.     " ",                    //
  112.     " ",                    //
  113.     " ",                    //
  114.     " ",                    //
  115.     " ",                    //
  116.     " ",                    //
  117.     " ",                    //
  118.     " ",                    //
  119.     " ",                    // 80
  120.     " ",                    //
  121.     " ",                    //
  122.     " ",                    //
  123.     " ",                    //
  124.     " ",                    //
  125.     " ",                    //
  126.     " ",                    //
  127.     " ",                    //
  128.     " ",                    //
  129.     " ",                    // 90
  130.     " ",                    //
  131.     " ",                    //
  132.     " ",                    //
  133.     " ",                    //
  134.     " ",                    //
  135.     " ",                    //
  136.     " ",                    //
  137.     " ",                    //
  138.     " ",                    //
  139.     " ",                    // 100
  140.     " ",                    //
  141.     " ",                    //
  142.     " ",                    //
  143.     " ",                    //
  144.     " ",                    //
  145.     " ",                    //
  146.     " ",                    //
  147.     " ",                    //
  148.     " ",                    //
  149.     " ",                    // 110
  150.     " ",                    //
  151.     " ",                    //
  152.     " ",                    //
  153.     " ",                    //
  154.     " ",                    //
  155.     " ",                    //
  156.     " ",                    //
  157.     " ",                    //
  158.     " ",                    //
  159.     " ",                    // 120
  160.     " ",                    //
  161.     " ",                    //
  162.     " ",                    //
  163.     " ",                    //
  164.     " ",                    //
  165.     " ",                    //
  166.     " ",                    //
  167.     " ",                    //
  168.     " ",                    //
  169.     " ",                    // 130
  170.     " ",                    //
  171.     " ",                    //
  172.     " ",                    //
  173.     " ",                    //
  174.     " ",                    //
  175.     " ",                    //
  176.     " ",                    //
  177.     " ",                    //
  178.     " ",                    //
  179.     " ",                    // 140
  180.     " ",                    //
  181.     " ",                    //
  182.     " ",                    //
  183.     " ",                    //
  184.     " ",                    //
  185.     " ",                    //
  186.     " ",                    //
  187.     " ",                    //
  188.     " ",                    //
  189.     " ",                    // 150
  190.     " ",                    //
  191.     " ",                    //
  192.     " ",                    //
  193.     " ",                    //
  194.     " ",                    //
  195.     " ",                    //
  196.     " ",                    //
  197.     " ",                    //
  198.     " ",                    //
  199.     " ",                    // 160
  200.     " ",                    //
  201.     " ",                    //
  202.     " ",                    //
  203.     " ",                    //
  204.     " ",                    //
  205.     " ",                    //
  206.     " ",                    //
  207.     " ",                    //
  208.     " ",                    //
  209.     " ",                    // 170
  210.     " ",                    //
  211.     " ",                    //
  212.     " ",                    //
  213.     " ",                    //
  214.     " ",                    //
  215.     " ",                    //
  216.     " ",                    //
  217.     " ",                    //
  218.     " ",                    //
  219.     " ",                    // 180
  220.     " ",                    //
  221.     " ",                    //
  222.     " ",                    //
  223.     " ",                    //
  224.     " ",                    //
  225.     " ",                    //
  226.     " ",                    //
  227.     " ",                    //
  228.     " ",                    //
  229.     " ",                    // 190
  230.     " ",                    //
  231.     " ",                    //
  232.     " ",                    //
  233.     " ",                    //
  234.     " ",                    //
  235.     " ",                    //
  236.     " ",                    //
  237.     " ",                    //
  238.     " ",                    //
  239.     "Connect",              // 200
  240.     "Disconnect"            // 201
  241. };
  242.  
  243. stock ReturnWeaponName(weaponid)
  244. {
  245.     new str[32];
  246.     if(weaponid < 0 || weaponid > 201) format(str, sizeof(str), "Unknown");
  247.     else format(str, sizeof(str), WeapName[weaponid]);
  248.     return str;
  249. }
  250.  
  251. stock bool:ShowLastKills(playerid, ListIt:iterator)
  252. {
  253.     new now = gettime(), captcha[22], kills_dialog_str[1586], days, hours, minutes, seconds;
  254.     listed_kills[playerid] = 0;
  255.     if((kill_ptrs_arr[playerid] = MEM::calloc(MAX_LIST_KILLS)) == NULL_PTR)
  256.     {
  257.         SendClientMessage(playerid, 0xFF0000FF, "An error has occured. Please retry later.");
  258.         return false;
  259.     }
  260.     for(new ListIt:kills_it = iterator; _:kills_it != NULL; kills_it = ListIt:MEM_EX::get_val(Pointer:(kills_it)->LIST_IT_data_previous))
  261.     {
  262.         MEM::set_val(kill_ptrs_arr[playerid], listed_kills[playerid]++, _:kills_it);
  263.         days = (hours = (minutes = 0));
  264.         seconds = now-LIST_IT::data_val(kills_it, kill_datetime);
  265.         while(seconds > 86399)
  266.         {
  267.             seconds -= 86400;
  268.             days++;
  269.         }
  270.         while(seconds > 3599)
  271.         {
  272.             seconds -= 3600;
  273.             hours++;
  274.         }
  275.         while(seconds > 59)
  276.         {
  277.             seconds -= 60;
  278.             minutes++;
  279.         }
  280.         if(days == 0)
  281.         {
  282.             if(hours == 0)
  283.             {
  284.                 if(minutes == 0)
  285.                 {
  286.                     if(seconds == 0) strcat(kills_dialog_str, "Now\r\n");
  287.                     else format(kills_dialog_str, sizeof kills_dialog_str, "%s%d %s ago\n", kills_dialog_str, seconds, (seconds == 1)?("second"):("seconds"));
  288.                 }
  289.                 else format(kills_dialog_str, sizeof kills_dialog_str, "%s%d %s, and %d %s ago\n", kills_dialog_str, minutes, (minutes == 1)?("minute"):("minutes"), seconds, (seconds == 1)?("second"):("seconds"));
  290.             }
  291.             else format(kills_dialog_str, sizeof kills_dialog_str, "%s%d %s, %d %s, and %d %s ago\n", kills_dialog_str, hours, (hours == 1)?("hour"):("hours"), minutes, (minutes == 1)?("minute"):("minutes"), seconds, (seconds == 1)?("second"):("seconds"));
  292.         }
  293.         else format(kills_dialog_str, sizeof kills_dialog_str, "%s%d %s, %d %s, %d %s, and %d %s ago\n", kills_dialog_str, days, (days == 1)?("day"):("days"), hours, (hours == 1)?("hour"):("hours"), minutes, (minutes == 1)?("minute"):("minutes"), seconds, (seconds == 1)?("second"):("seconds"));
  294.         if(listed_kills[playerid] >= MAX_LIST_KILLS) break;
  295.     }
  296.     if(listed_kills[playerid] == 0)
  297.     {
  298.         MEM::free(kill_ptrs_arr[playerid]);
  299.         kill_ptrs_arr[playerid] = NULL_PTR;
  300.         if(iterator == ListIt:kills_list[LIST_base_end]) SendClientMessage(playerid, 0xFF0000FF, "There are no kills recorded.");
  301.         else SendClientMessage(playerid, 0xFF0000FF, "There are no more kills recorded.");
  302.         return false;
  303.     }
  304.     strcat(kills_dialog_str, "{FF7F00}More\n{7F7F7F}Exit");
  305.     if(iterator == ListIt:kills_list[LIST_base_end]) format(captcha, sizeof captcha, "{FF0000}Last %d kills", listed_kills[playerid]);
  306.     else format(captcha, sizeof captcha, "{FF0000}More %d kills", listed_kills[playerid]);
  307.     ShowPlayerDialog(playerid, LASTKILLS_DIALOGID, DIALOG_STYLE_LIST, captcha, kills_dialog_str, "Choose", "Exit");
  308.     return true;
  309. }
  310.  
  311. public OnFilterScriptInit()
  312. {
  313.     LIST::load(kills_list, KILLS_FILE);
  314.     print("\n===============================");
  315.     print("= Example kills filter script =");
  316.     print("=       Made by BigETI        =");
  317.     print("=           Loaded!           =");
  318.     print("===============================\n");
  319.     return 1;
  320. }
  321.  
  322. public OnFilterScriptExit()
  323. {
  324.     LIST::save(kills_list, KILLS_FILE, true);
  325.     for(new i = 0; i < sizeof kill_ptrs_arr; i++)
  326.     {
  327.         if(kill_ptrs_arr[i] == NULL_PTR) continue;
  328.         ShowPlayerDialog(i, -1, DIALOG_STYLE_MSGBOX, "", "", "", "");
  329.         MEM::free(kill_ptrs_arr[i]);
  330.     }
  331.     print("\n===============================");
  332.     print("= Example kills filter script =");
  333.     print("=       Made by BigETI        =");
  334.     print("=          Unloaded!          =");
  335.     print("===============================\n");
  336.     return 1;
  337. }
  338.  
  339. public OnPlayerDisconnect(playerid, reason)
  340. {
  341.     MEM::free(kill_ptrs_arr[playerid]);
  342.     kill_ptrs_arr[playerid] = NULL_PTR;
  343.     listed_kills[playerid] = 0;
  344.     return 1;
  345. }
  346.  
  347. public OnPlayerDeath(playerid, killerid, reason)
  348. {
  349.     new kill_buffer[kill_struct];
  350.     kill_buffer[kill_datetime] = gettime();
  351.     kill_buffer[kill_victimid] = playerid;
  352.     GetPlayerIp(playerid, kill_buffer[kill_victimip], 16);
  353.     GetPlayerName(playerid, kill_buffer[kill_victimname], MAX_PLAYER_NAME);
  354.     if((kill_buffer[kill_killerid] = killerid) == INVALID_PLAYER_ID)
  355.     {
  356.         kill_buffer[kill_killerpos_x] = 0.0;
  357.         kill_buffer[kill_killerpos_y] = 0.0;
  358.         kill_buffer[kill_killerpos_z] = 0.0;
  359.         kill_buffer[kill_killerpos_rotz] = 0.0;
  360.     }
  361.     else
  362.     {
  363.         GetPlayerIp(killerid, kill_buffer[kill_killerip], 16);
  364.         GetPlayerName(killerid, kill_buffer[kill_killername], MAX_PLAYER_NAME);
  365.         GetPlayerPos(killerid, kill_buffer[kill_killerpos_x], kill_buffer[kill_killerpos_y], kill_buffer[kill_killerpos_z]);
  366.         GetPlayerFacingAngle(killerid, kill_buffer[kill_killerpos_rotz]);
  367.     }
  368.     kill_buffer[kill_reason] = reason;
  369.     GetPlayerPos(playerid, kill_buffer[kill_victimpos_x], kill_buffer[kill_victimpos_y], kill_buffer[kill_victimpos_z]);
  370.     GetPlayerFacingAngle(playerid, kill_buffer[kill_victimpos_rotz]);
  371.     LIST::push_back_arr(kills_list, kill_buffer);
  372.     return 1;
  373. }
  374.  
  375. public OnPlayerCommandText(playerid, cmdtext[])
  376. {
  377.     if(!strcmp(cmdtext, "/lastkills", true, 11))
  378.     {
  379.         if(kill_ptrs_arr[playerid]) return SendClientMessage(playerid, 0xFF0000FF, "You are already looking for the last kills.");
  380.         ShowLastKills(playerid, ListIt:kills_list[LIST_base_end]);
  381.         return 1;
  382.     }
  383.     return 0;
  384. }
  385.  
  386. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  387. {
  388.     switch(dialogid)
  389.     {
  390.         case LASTKILLS_DIALOGID:
  391.         {
  392.             if(response)
  393.             {
  394.                 if(listitem >= listed_kills[playerid])
  395.                 {
  396.                     if(listitem == listed_kills[playerid]) {if(!ShowLastKills(playerid, LIST_IT::previous(MEM::get_val(kill_ptrs_arr[playerid], listed_kills[playerid]-1)))) return 1;}
  397.                     else
  398.                     {
  399.                         MEM::free(kill_ptrs_arr[playerid]);
  400.                         kill_ptrs_arr[playerid] = NULL_PTR;
  401.                         listed_kills[playerid] = 0;
  402.                         return SendClientMessage(playerid, 0xFF0000FF, "You have canceled the last kills dialog.");
  403.                     }
  404.                 }
  405.                 else
  406.                 {
  407.                     new kill_buffer[kill_struct], caption[52], kill_info_dialog_str[543], days, hours, minutes, seconds;
  408.                     MEM::get_arr(LIST_IT::data_ptr(ListIt:MEM::get_val(kill_ptrs_arr[playerid], listitem)), _, kill_buffer);
  409.                     seconds = gettime()-kill_buffer[kill_datetime];
  410.                     while(seconds > 86399)
  411.                     {
  412.                         seconds -= 86400;
  413.                         days++;
  414.                     }
  415.                     while(seconds > 3599)
  416.                     {
  417.                         seconds -= 3600;
  418.                         hours++;
  419.                     }
  420.                     while(seconds > 59)
  421.                     {
  422.                         seconds -= 60;
  423.                         minutes++;
  424.                     }
  425.                     if(days == 0)
  426.                     {
  427.                         if(hours == 0)
  428.                         {
  429.                             if(minutes == 0)
  430.                             {
  431.                                 if(seconds == 0) format(caption, sizeof caption, "Now");
  432.                                 else format(caption, sizeof caption, "%d %s ago", seconds, (seconds == 1)?("second"):("seconds"));
  433.                             }
  434.                             else format(caption, sizeof caption, "%d %s, and %d %s ago", minutes, (minutes == 1)?("minute"):("minutes"), seconds, (seconds == 1)?("second"):("seconds"));
  435.                         }
  436.                         else format(caption, sizeof caption, "%d %s, %d %s, and %d %s ago", hours, (hours == 1)?("hour"):("hours"), minutes, (minutes == 1)?("minute"):("minutes"), seconds, (seconds == 1)?("second"):("seconds"));
  437.                     }
  438.                     else format(caption, sizeof caption, "%d %s, %d %s, %d %s, and %d %s ago", days, (days == 1)?("day"):("days"), hours, (hours == 1)?("hour"):("hours"), minutes, (minutes == 1)?("minute"):("minutes"), seconds, (seconds == 1)?("second"):("seconds"));
  439.                     if(kill_buffer[kill_killerid] == INVALID_PLAYER_ID)
  440.                     {
  441.                         format(kill_info_dialog_str, sizeof kill_info_dialog_str, "{0000FF}Type: {FFFFFF}Suicide\n\n{0000FF}Suicides: {FFFFFF}%s ( %d : %s )\n{0000FF}Suicide weapon: {FFFFFF}%s{FFFFFF}\n\n\n{0000FF}Location:\n {FFFFFF}- X: %.4f\n - Y: %.4f\n - Z: %.4f\n - Angle: %.4f",
  442.                             kill_buffer[kill_victimname], kill_buffer[kill_victimid], kill_buffer[kill_victimip], ReturnWeaponName(kill_buffer[kill_reason]), kill_buffer[kill_victimpos_x], kill_buffer[kill_victimpos_y], kill_buffer[kill_victimpos_z], kill_buffer[kill_victimpos_rotz]);
  443.                     }
  444.                     else
  445.                     {
  446.                         format(kill_info_dialog_str, sizeof kill_info_dialog_str, "{0000FF}Type: {FFFFFF}Murder\n\n{0000FF}Victim: {FFFFFF}%s ( %d : %s )\n{0000FF}Killer: {FFFFFF}%s ( %d : %s )\n\n{0000FF}Murder weapon: {FFFFFF}%s ( %.4f meters )\n\n\n",
  447.                             kill_buffer[kill_victimname], kill_buffer[kill_victimid], kill_buffer[kill_victimip], kill_buffer[kill_killername], kill_buffer[kill_killerid], kill_buffer[kill_killerip], ReturnWeaponName(kill_buffer[kill_reason]),
  448.                             GetDistanceBetweenPoints(kill_buffer[kill_victimpos_x], kill_buffer[kill_victimpos_y], kill_buffer[kill_victimpos_z], kill_buffer[kill_killerpos_x], kill_buffer[kill_killerpos_y], kill_buffer[kill_killerpos_z]));
  449.                         format(kill_info_dialog_str, sizeof kill_info_dialog_str, "%s{0000FF}Victim: {FFFFFF}- X: %.4f\n - Y: %.4f\n - Z: %.4f\n - Angle: %.4f\n\n{0000FF}Killer: {FFFFFF}- X: %.4f\n - Y: %.4f\n - Z: %.4f\n - Angle: %.4f",
  450.                             kill_info_dialog_str, kill_buffer[kill_victimpos_x], kill_buffer[kill_victimpos_y], kill_buffer[kill_victimpos_z], kill_buffer[kill_victimpos_rotz], kill_buffer[kill_killerpos_x], kill_buffer[kill_killerpos_y], kill_buffer[kill_killerpos_z], kill_buffer[kill_killerpos_rotz]);
  451.                     }
  452.                     ShowPlayerDialog(playerid, NO_RESPONSE_DIALOGID, DIALOG_STYLE_MSGBOX, caption, kill_info_dialog_str, "OK", "");
  453.                     MEM::free(kill_ptrs_arr[playerid]);
  454.                     kill_ptrs_arr[playerid] = NULL_PTR;
  455.                     listed_kills[playerid] = 0;
  456.                 }
  457.             }
  458.             else
  459.             {
  460.                 MEM::free(kill_ptrs_arr[playerid]);
  461.                 kill_ptrs_arr[playerid] = NULL_PTR;
  462.                 listed_kills[playerid] = 0;
  463.             }
  464.         }
  465.     }
  466.     return 1;
  467. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement