Advertisement
Julian90

OnPlayerAssist - v0.0.2

Sep 16th, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.49 KB | None | 0 0
  1. /*
  2.         OnPlayerAssist - By: [J]ulian.
  3.     v0.0.1 - 16/09/2014
  4.                - Lanzamiento inicial.
  5.     v0.0.2 - 17/09/2014
  6.                - Se corrigió un error donde el asesino también se llamaba como asistente.
  7.     v0.0.3 - 06/11/2014
  8.                - Se corrigió un error donde la información de asistencia se borraba antes de ser enviada.
  9.  
  10.     Requerido:
  11.       - y_hooks: http://forum.sa-mp.com/showthread.php?t=166016
  12. */
  13.  
  14. #include <YSI\y_hooks>
  15.  
  16. forward OnPlayerAssist(playerid, deadid, Float:damage, time, bullets);
  17. /*
  18.     native ResetAssistInfo(playerid = INVALID_PLAYER_ID, userid = INVALID_PLAYER_ID);
  19.     native SetPlayerAssistInfo(playerid, userid, Float:damage, time, bullets);
  20.     native GetPlayerAssistInfo(playerid, userid, &Float:damage, &time, &bullets);
  21. */
  22.  
  23. enum ASSIST_INFO {
  24.     Float:DAMAGE,
  25.     TIME,
  26.     BULLETS
  27. }
  28. new AssistInfo[MAX_PLAYERS][MAX_PLAYERS][ASSIST_INFO];
  29.  
  30. hook OnPlayerConnect(playerid)
  31. {
  32.     for(new i = 0; i != GetMaxPlayers(); i++)
  33.     {
  34.         ResetAssistInfo(i, playerid);
  35.         ResetAssistInfo(playerid, i);
  36.     }
  37.     return 1;
  38. }
  39.  
  40. hook OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  41. {
  42.     if(hittype == BULLET_HIT_TYPE_PLAYER)
  43.     {
  44.         AssistInfo[playerid][hitid][BULLETS]++;
  45.     }
  46.     return 1;
  47. }
  48.  
  49. hook OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid, bodypart)
  50. {
  51.     if(playerid != INVALID_PLAYER_ID && damagedid != INVALID_PLAYER_ID)
  52.     {
  53.         AssistInfo[playerid][damagedid][DAMAGE] += amount;
  54.         AssistInfo[playerid][damagedid][TIME]  = gettime();
  55.     }
  56.     return 1;
  57. }
  58.  
  59. hook OnPlayerDeath(playerid, killerid, reason)
  60. {
  61.     for(new i = 0, e = GetMaxPlayers(); i != e; i++)
  62.     {
  63.         if(AssistInfo[i][playerid][BULLETS] != 0)
  64.         {
  65.             if(killerid != i)
  66.             {
  67.                 CallLocalFunction("OnPlayerAssist", "iifii", i, playerid, AssistInfo[i][playerid][DAMAGE], (gettime()-AssistInfo[i][playerid][TIME]), AssistInfo[i][playerid][BULLETS]);
  68.             }
  69.             ResetAssistInfo(i, playerid);
  70.         }
  71.     }
  72.     for(new i = 0, e = GetMaxPlayers(); i != e; i++)
  73.     {
  74.         if(AssistInfo[playerid][i][BULLETS] != 0)
  75.         {
  76.             ResetAssistInfo(playerid, i);
  77.         }
  78.     }
  79.     return 1;
  80. }
  81.  
  82. stock ResetAssistInfo(playerid = INVALID_PLAYER_ID, userid = INVALID_PLAYER_ID)
  83. {
  84.     if(playerid == INVALID_PLAYER_ID && userid == INVALID_PLAYER_ID)
  85.     {
  86.         for(new i = 0, e = GetMaxPlayers(); i != e; i++)
  87.         {
  88.             for(new u = 0, f = GetMaxPlayers(); u != f; u++)
  89.             {
  90.                 AssistInfo[i][u][DAMAGE]    = 0;
  91.                 AssistInfo[i][u][TIME]      = 0;
  92.                 AssistInfo[i][u][BULLETS]   = 0;
  93.                 AssistInfo[u][i][DAMAGE]    = 0;
  94.                 AssistInfo[u][i][TIME]      = 0;
  95.                 AssistInfo[u][i][BULLETS]   = 0;
  96.             }
  97.         }
  98.         return 1;
  99.     }
  100.     AssistInfo[playerid][userid][DAMAGE]    = 0;
  101.     AssistInfo[playerid][userid][TIME]      = 0;
  102.     AssistInfo[playerid][userid][BULLETS]   = 0;
  103.     return 1;
  104. }
  105.  
  106. stock SetPlayerAssistInfo(playerid, userid, Float:damage, time, bullets)
  107. {
  108.     if(playerid != INVALID_PLAYER_ID && userid != INVALID_PLAYER_ID)
  109.     {
  110.         if(IsPlayerConnected(playerid) && IsPlayerConnected(userid))
  111.         {
  112.             AssistInfo[playerid][userid][DAMAGE] = damage;
  113.             AssistInfo[playerid][userid][TIME] = gettime()+time;
  114.             AssistInfo[playerid][userid][BULLETS] = bullets;
  115.         }
  116.     }
  117.     return 1;
  118. }
  119.  
  120. stock GetPlayerAssistInfo(playerid, userid, &Float:damage, &time, &bullets)
  121. {
  122.     if(playerid != INVALID_PLAYER_ID && userid != INVALID_PLAYER_ID)
  123.     {
  124.         if(IsPlayerConnected(playerid) && IsPlayerConnected(userid))
  125.         {
  126.             damage = AssistInfo[playerid][userid][DAMAGE];
  127.             time = AssistInfo[playerid][userid][TIME];
  128.             bullets = AssistInfo[playerid][userid][BULLETS];
  129.         }
  130.     }
  131.     return 1;
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement