Advertisement
Guest User

OPSP

a guest
Feb 18th, 2011
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.32 KB | None | 0 0
  1. /********************************************
  2.  * OnPlayerShootPlayer! V4.5                *
  3.  * Credits: wups,               *
  4.  * Double-O-Seven for his HS functions      *
  5.  ********************************************/
  6.  
  7. // include
  8. #include <a_samp>
  9. #tryinclude <foreach>
  10.  
  11. // defines
  12. #if defined OPSP
  13.     #endinput
  14. #endif
  15. #define OPSP
  16.  
  17. #if !defined foreach
  18.     #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  19.     #define __SSCANF_FOREACH__
  20. #endif
  21. #if defined FILTERSCRIPT
  22.     #error "OnPlayerShootPlayer ERROR: You must include it in your game mode, not in your filterscript!"
  23. #endif
  24. #if !defined PRESSED
  25.     #define PRESSED(%0) \
  26.         (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  27. #endif
  28. #if !defined RELEASED
  29.     #define RELEASED(%0) \
  30.         (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
  31. #endif
  32. // variables
  33. static  Float:phealth[MAX_PLAYERS],
  34.         bool:Shooting[MAX_PLAYERS],
  35.         Released[MAX_PLAYERS],
  36.         bool:RL_OPUP,
  37.         bool:RL_OPSC,
  38.         bool:RL_OPKSC,
  39.         bool:RL_OPC;
  40. // forwards
  41. forward OnPlayerShootPlayer(shooter,target,Float:damage);
  42.  
  43. public OnPlayerUpdate(playerid)
  44. {
  45.     static  Float:HP,
  46.             Float:Armour;
  47.     GetPlayerHealth(playerid,HP);
  48.     GetPlayerArmour(playerid,Armour);
  49.     if(HP+Armour < phealth[playerid])
  50.     {
  51.         static Float:VALUE[14];
  52.         GetPlayerPos(playerid, VALUE[0], VALUE[1], VALUE[2]);
  53.         GetPlayerCameraFrontVector(playerid, VALUE[7], VALUE[8], VALUE[9]);
  54.         GetPlayerCameraPos(playerid, VALUE[10], VALUE[11], VALUE[12]);
  55.         foreach(Player,i)
  56.         {
  57.             if(i != playerid && IsPlayerInRangeOfPoint(i,200.0,VALUE[0],VALUE[1],VALUE[2]))
  58.             {
  59.                 GetPlayerPos(i, VALUE[3], VALUE[4], VALUE[5]);
  60.                 GetDistanceFromPointToLine(VALUE[6], VALUE[7], VALUE[8], VALUE[9], VALUE[10], VALUE[11], VALUE[12], VALUE[3], VALUE[4], VALUE[5]);
  61.                 if(VALUE[6] < 2.5)
  62.                 {
  63.                     if(Shooting[i] || (GetTickCount()-1000 < Released[i]))
  64.                     {
  65.                         CallLocalFunction("OnPlayerShootPlayer","iif",i,playerid,(phealth[playerid]-HP-Armour));
  66.                         break;
  67.                     }
  68.                 }
  69.             }
  70.         }
  71.     }
  72.     phealth[playerid]=HP+Armour;
  73.     return (RL_OPUP)?CallLocalFunction("RL_OnPlayerUpdate","i",playerid):1;
  74. }
  75.  
  76. stock crossp(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z, &Float:output)
  77. {
  78.     new
  79.         Float:c1 = (v1y * v2z) - (v1z * v2y),
  80.         Float:c2 = (v1z * v2x) - (v1x * v2z),
  81.         Float:c3 = (v1x * v2y) - (v1y * v2x);
  82.     output = floatsqroot ((c1 * c1) + (c2 * c2) + (c3 * c3));
  83.     return 0;
  84. }
  85.  
  86. stock GetDistanceFromPointToLine(&Float:distance, Float:line_vector_x, Float:line_vector_y, Float:line_vector_z, Float:line_x, Float:line_y, Float:line_z, Float:point_x, Float:point_y, Float:point_z)
  87. {
  88.     //A line is defined by a point (which is on the line (line_x/y/z)) and a vector which defines the direction (line_vector_x/y/z).
  89.     static Float:output;
  90.     crossp(line_vector_x, line_vector_y, line_vector_z, point_x - line_x, point_y - line_y, point_z - line_z, output);//Cross product of 2 vectors.
  91.     distance = output / floatsqroot ((line_vector_x * line_vector_x) + (line_vector_y * line_vector_y) + (line_vector_z * line_vector_z));
  92.     return 0;
  93. }
  94.  
  95. stock SetPlayerHealthEx(playerid, Float:health)
  96. {
  97.     new Float:armour;
  98.     GetPlayerArmour(playerid,armour);
  99.     phealth[playerid]=health+armour;
  100.     return SetPlayerHealth(playerid, health);
  101. }
  102.  
  103. #define SetPlayerHealth SetPlayerHealthEx
  104.  
  105. #if defined _ALS_OnPlayerUpdate
  106.     #undef OnPlayerUpdate
  107. #else
  108.     #define _ALS_OnPlayerUpdate
  109. #endif
  110. #define OnPlayerUpdate RL_OnPlayerUpdate
  111. forward RL_OnPlayerUpdate(playerid);
  112. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  113. {
  114.     if(PRESSED(KEY_FIRE)) Shooting[playerid]=true;
  115.     else if(RELEASED(KEY_FIRE))
  116.     {
  117.         Shooting[playerid]=false;
  118.         Released[playerid]=GetTickCount();
  119.     }
  120.     return (RL_OPKSC)?CallLocalFunction("RL_OnPlayerKeyStateChange","iii",playerid,newkeys,oldkeys):1;
  121. }
  122. #if defined _ALS_OnPlayerKeyStateChange
  123.     #undef OnPlayerKeyStateChange
  124. #else
  125.     #define _ALS_OnPlayerKeyStateChange
  126. #endif
  127. #define OnPlayerKeyStateChange RL_OnPlayerKeyStateChange
  128. forward RL_OnPlayerKeyStateChange(playerid,newkeys,oldkeys);
  129.  
  130. public OnPlayerStateChange(playerid, newstate, oldstate)
  131. {
  132.     Shooting[playerid]=false;
  133.     Released[playerid]=GetTickCount();
  134.     return (RL_OPSC)?CallLocalFunction("RL_OnPlayerStateChange","iii",playerid,newstate,oldstate):1;
  135. }
  136. #if defined _ALS_OnPlayerStateChange
  137.     #undef OnPlayerStateChange
  138. #else
  139.     #define _ALS_OnPlayerStateChange
  140. #endif
  141. #define OnPlayerStateChange RL_OnPlayerStateChange
  142. forward RL_OnPlayerStateChange(playerid,newstate, oldstate);
  143. public OnPlayerConnect(playerid)
  144. {
  145.     Shooting[playerid]=false;
  146.     Released[playerid]=0;
  147.     return (RL_OPC)?CallLocalFunction("RL_OnPlayerConnect","i",playerid):1;
  148. }
  149. #if defined _ALS_OnPlayerConnect
  150.     #undef OnPlayerConnect
  151. #else
  152.     #define _ALS_OnPlayerConnect
  153. #endif
  154. #define OnPlayerConnect RL_OnPlayerConnect
  155. forward RL_OnPlayerConnect(playerid);
  156. public OnGameModeInit()
  157. {
  158.     RL_OPUP = (funcidx("RL_OnPlayerUpdate") != -1);
  159.     RL_OPSC = (funcidx("RL_OnPlayerStateChange") != -1);
  160.     RL_OPKSC = (funcidx("RL_OnPlayerKeyStateChange") != -1);
  161.     RL_OPC = (funcidx("RL_OnPlayerConnect") != -1);
  162.     return (funcidx("RL_OnGameModeInit") != -1)?CallLocalFunction("RL_OnGameModeInit",""):1;
  163. }
  164. #if defined _ALS_OnGameModeInit
  165.     #undef OnGameModeInit
  166. #else
  167.     #define _ALS_OnGameModeInit
  168. #endif
  169. #define OnGameModeInit RL_OnGameModeInit
  170. forward RL_OnGameModeInit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement