Advertisement
Southclaw

Southclaw's Kill Feed Script (v1.0)

Jun 7th, 2012
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.08 KB | None | 0 0
  1.  
  2. /*
  3.     Kill Feed Box by Southclaw
  4.  
  5.         This script uses data from OnPlayerDeath to draw a custom kill feed
  6.         using text draws. The function isn't as simple as you might think.
  7.        
  8.         The UpdateKillBox function must ensure there is only a certain number
  9.         of lines by looping through the string and counting the lines using
  10.         strfind to search for "~n~" (The textdraw newline string) then insert an
  11.         EOS (end of string) character in the place of the last newline string.
  12.  
  13.        
  14.         The following is a run-through of how the string length is calculated,
  15.         taking into account all inputted data and their maximum string lengths.
  16.  
  17.  
  18.  
  19.     Max player name length: 24
  20.     Max weapon* name length: 17
  21.     Extras:
  22.         space on each side of weapon name, '~n~' for nextline.
  23.  
  24.     total line length: (MAX_PLAYER_NAME + 1 + 17 + 1 + MAX_PLAYER_NAME + 3) = 70
  25.  
  26.     First line length: 15
  27.     List lines: (70 * MAX_KB_LINES) = 350 (5 is default for MAX_KB_LINES)
  28.     End of string: 1
  29.  
  30.     Total List String Length: 366
  31.  
  32.  
  33.     Note: This is excluding the Night Vision Goggles (20 char) which you can't actually kill someone with!
  34.     You can decrease memory usage by using custom weapon names in an array.
  35.     For instance instead of "Combat Shotgun" You could just call it a "Spas12",
  36.     "Desert Eagle" could become simple "Deagle"
  37.     "Sawn-Off Shotgun" could just be "Sawnoff"
  38.  
  39.  
  40.     Note2: You could add colours to the killbox but it would require a larger string.
  41. */
  42.  
  43. #include <a_samp>
  44. #undef MAX_PLAYERS
  45. #define MAX_PLAYERS 16
  46.  
  47. // Only for the debug commands.
  48. // When running a public server, simply remove this include and the commands.
  49. #include <zcmd>
  50.  
  51.  
  52. #define KILLBOX_TEXT    "~r~Killfeed:~n~~w~"
  53. #define MAX_KB_LINES    5 // Not tested new values, the textdraw fits 5 though
  54. // I will update this to support a dynamic amount.
  55. #define MAX_KN_LINE_LEN 70
  56. #define MAX_KB_LEN      (16 + (MAX_KB_LINES*MAX_KN_LINE_LEN))
  57.  
  58. new
  59.     Text:kbBack,
  60.     Text:kbText,
  61.     szKbString[MAX_KB_LEN] = {KILLBOX_TEXT};
  62.  
  63.  
  64. public OnFilterScriptInit()
  65. {
  66.     LoadTD();
  67. }
  68. public OnFilterScriptExit()
  69. {
  70.     DestroyTD();
  71. }
  72.  
  73.  
  74. LoadTD()
  75. {
  76.     kbBack = TextDrawCreate(460.000000, 110.000000, "~n~~n~~n~~n~~n~~n~");
  77.     TextDrawBackgroundColor(kbBack, 255);
  78.     TextDrawFont(kbBack, 1);
  79.     TextDrawLetterSize(kbBack, 0.300000, 1.399999);
  80.     TextDrawColor(kbBack, -1);
  81.     TextDrawSetOutline(kbBack, 0);
  82.     TextDrawSetProportional(kbBack, 1);
  83.     TextDrawSetShadow(kbBack, 1);
  84.     TextDrawUseBox(kbBack, 1);
  85.     TextDrawBoxColor(kbBack, 100);
  86.     TextDrawTextSize(kbBack, 630.000000, 0.000000);
  87.  
  88.     kbText = TextDrawCreate(460.000000, 110.000000, "~r~Killfeed:~n~~w~(HLF)Southclaw M4 (HLF)Defiance~n~line2~n~line3~n~line4~n~line5");
  89.     TextDrawBackgroundColor(kbText, 255);
  90.     TextDrawFont(kbText, 1);
  91.     TextDrawLetterSize(kbText, 0.260000, 1.399999);
  92.     TextDrawColor(kbText, -1);
  93.     TextDrawSetOutline(kbText, 0);
  94.     TextDrawSetProportional(kbText, 1);
  95.     TextDrawSetShadow(kbText, 1);
  96. }
  97. DestroyTD()
  98. {
  99.     TextDrawDestroy(kbBack);
  100.     TextDrawDestroy(kbText);
  101. }
  102. UpdateKillBox(killer, victim, weapon)
  103. {
  104.     new
  105.         killerName[MAX_PLAYER_NAME],
  106.         victimName[MAX_PLAYER_NAME],
  107.         tmpWepName[17],
  108.         tmpLine[70],
  109.         iLoop,
  110.         iChar = 16,
  111.         len,
  112.         tmpPos;
  113.  
  114.     // Format the new line to insert at the top of the kill list.
  115.     GetPlayerName(killer, killerName, MAX_PLAYER_NAME);
  116.     GetPlayerName(victim, victimName, MAX_PLAYER_NAME);
  117.     GetWeaponName(weapon, tmpWepName, 17);
  118.     format(tmpLine, 70, "%s %s %s~n~", killerName, tmpWepName, victimName);
  119.    
  120.     // Insert the new line at the top of the list,
  121.     // This is after the heading of the killfeed.
  122.     strins(szKbString, tmpLine, strlen(KILLBOX_TEXT), 70);
  123.  
  124.     // This next part will remove any unwanted newline characters
  125.     // Because we only want 5 (Or whatever you set MAX_KB_LINES to)
  126.     // lines after the heading
  127.  
  128.     len = strlen(szKbString);
  129.  
  130.     // Loop through the text while the number of found lines is below the max
  131.     // and while the looping character cell is within the string.
  132.     while(iLoop < MAX_KB_LINES && iChar < len)
  133.     {
  134.         // Look for the nextline character
  135.         tmpPos = strfind(szKbString, "~n~", .pos=iChar);
  136.         // If one is found
  137.         if(tmpPos != -1)
  138.         {
  139.             iChar = tmpPos; // Set the char to the pos
  140.             iLoop++; // Increase the number of lines found
  141.         }
  142.         iChar++; // Increase the char index for the next strfind
  143.     }
  144.     // If there are more than 5 lines found,
  145.     // Set the 6th newline character to EOS (end of string)
  146.     // I use -1 because the last iteration of the loop performs 'iChar++'
  147.     if(iLoop >= 5)szKbString[iChar-1] = EOS;
  148.  
  149.     // Now the string has any overhang newlines removed, update it.
  150.     TextDrawSetString(kbText, szKbString);
  151. }
  152. TogglePlayerKillBox(playerid, bool:toggle)
  153. {
  154.     if(toggle)
  155.     {
  156.         TextDrawShowForPlayer(playerid, kbBack);
  157.         TextDrawShowForPlayer(playerid, kbText);
  158.     }
  159.     else
  160.     {
  161.         TextDrawHideForPlayer(playerid, kbBack);
  162.         TextDrawHideForPlayer(playerid, kbText);
  163.     }
  164. }
  165.  
  166. // The following commands are used for testing purposes.
  167.  
  168. CMD:showkb(playerid, params[])
  169. {
  170.     TogglePlayerKillBox(playerid, true);
  171.     return 1;
  172. }
  173. CMD:kbadd(playerid, params[])
  174. {
  175.     UpdateKillBox(0, 1, 34);
  176.     return 1;
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement