Advertisement
Guest User

OPSP V6.0

a guest
Aug 2nd, 2011
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.55 KB | None | 0 0
  1. /********************************************
  2.  * OnPlayerShootPlayer! V6.0                *
  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     
  34.         Float:RL_phealth[MAX_PLAYERS],
  35.         Float:RL_parmour[MAX_PLAYERS],
  36.         bool:RL_Shooting[MAX_PLAYERS],
  37.         bool:RL_UpdatedHealth[MAX_PLAYERS],
  38.         bool:RL_OPUP,
  39.         bool:RL_OPSC,
  40.         bool:RL_OPKSC,
  41.         bool:RL_OPC,
  42.         RL_Released[MAX_PLAYERS];
  43. // forwards
  44. forward OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost);
  45.  
  46. public OnPlayerUpdate(playerid)
  47. {
  48.     static  Float:RL_HP,
  49.             Float:RL_Armour;
  50.     GetPlayerHealth(playerid,RL_HP);
  51.     GetPlayerArmour(playerid,RL_Armour);
  52.     if(RL_HP != RL_phealth[playerid] || RL_Armour != RL_parmour[playerid])
  53.     {
  54.         if(RL_UpdatedHealth[playerid])
  55.             RL_UpdatedHealth[playerid]=false;
  56.         else
  57.         {
  58.             new
  59.                     Float:RL_PlayerPos[3],
  60.                     Float:RL_Distance,
  61.                     Float:RL_CameraPos[3],
  62.                     Float:RL_CameraVectors[3],
  63.                     RL_Tick
  64.                     ;
  65.             RL_Tick = (GetTickCount()-1000);
  66.             GetPlayerPos(playerid, RL_PlayerPos[0], RL_PlayerPos[1], RL_PlayerPos[2]);
  67.             foreach(Player,i)
  68.             {
  69.                 if(RL_Shooting[i] || RL_Tick < RL_Released[i])
  70.                 {
  71.                     if(i != playerid)
  72.                     {
  73.                         if(IsPlayerInRangeOfPoint(i,200.0,RL_PlayerPos[0], RL_PlayerPos[1], RL_PlayerPos[2]))
  74.                         {
  75.                             GetPlayerCameraFrontVector(i, RL_CameraVectors[0], RL_CameraVectors[1], RL_CameraVectors[2]);
  76.                             GetPlayerCameraPos(i, RL_CameraPos[0], RL_CameraPos[1], RL_CameraPos[2]);
  77.                             GetDistanceFromPointToLine(RL_Distance, RL_CameraVectors[0], RL_CameraVectors[1], RL_CameraVectors[2], RL_CameraPos[0], RL_CameraPos[1], RL_CameraPos[2], RL_PlayerPos[0], RL_PlayerPos[1], RL_PlayerPos[2]);
  78.                             if(RL_Distance < 2.5)
  79.                             {
  80.                                     CallLocalFunction("OnPlayerShootPlayer","iiff",i,playerid,(RL_phealth[playerid]-RL_HP),(RL_parmour[playerid]-RL_Armour));
  81.                                     break;
  82.                             }
  83.                         }
  84.                     }
  85.                 }
  86.             }
  87.         }
  88.     }
  89.     RL_phealth[playerid]=RL_HP;
  90.     RL_parmour[playerid]=RL_Armour;
  91.     return (RL_OPUP)?CallLocalFunction("RL_OnPlayerUpdate","i",playerid):1;
  92. }
  93. // Functions
  94. stock crossp(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z, &Float:output)
  95. {
  96.     new
  97.         Float:c1 = (v1y * v2z) - (v1z * v2y),
  98.         Float:c2 = (v1z * v2x) - (v1x * v2z),
  99.         Float:c3 = (v1x * v2y) - (v1y * v2x);
  100.     output = floatsqroot ((c1 * c1) + (c2 * c2) + (c3 * c3));
  101.     return 0;
  102. }
  103.  
  104. 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)
  105. {
  106.     //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).
  107.     static Float:output;
  108.     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.
  109.     distance = output / floatsqroot ((line_vector_x * line_vector_x) + (line_vector_y * line_vector_y) + (line_vector_z * line_vector_z));
  110.     return 0;
  111. }
  112. // SetPlayerHealth
  113. stock SetPlayerHealthEx(playerid, Float:health)
  114. {
  115. //  RL_phealth[playerid]=health;
  116.     RL_UpdatedHealth[playerid]=true;
  117.     return SetPlayerHealth(playerid, health);
  118. }
  119.  
  120. #define SetPlayerHealth SetPlayerHealthEx
  121.  
  122. // SetPlayerArmour
  123. stock SetPlayerArmourEx(playerid, Float:armour)
  124. {
  125. //  RL_parmour[playerid]=armour;
  126.     RL_UpdatedHealth[playerid]=true;
  127.     return SetPlayerArmour(playerid, armour);
  128. }
  129.  
  130. #define SetPlayerArmour SetPlayerArmourEx
  131.  
  132. #if defined _ALS_OnPlayerUpdate
  133.     #undef OnPlayerUpdate
  134. #else
  135.     #define _ALS_OnPlayerUpdate
  136. #endif
  137.  
  138. #define OnPlayerUpdate RL_OnPlayerUpdate
  139. forward RL_OnPlayerUpdate(playerid);
  140.  
  141. // OnPlayerKeyStateChange
  142. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  143. {
  144.     if(PRESSED(KEY_FIRE)) RL_Shooting[playerid]=true;
  145.     else if(RELEASED(KEY_FIRE))
  146.     {
  147.         RL_Shooting[playerid]=false;
  148.         RL_Released[playerid]=GetTickCount();
  149.     }
  150.     return (RL_OPKSC)?CallLocalFunction("RL_OnPlayerKeyStateChange","iii",playerid,newkeys,oldkeys):1;
  151. }
  152. #if defined _ALS_OnPlayerKeyStateChange
  153.     #undef OnPlayerKeyStateChange
  154. #else
  155.     #define _ALS_OnPlayerKeyStateChange
  156. #endif
  157. #define OnPlayerKeyStateChange RL_OnPlayerKeyStateChange
  158. forward RL_OnPlayerKeyStateChange(playerid,newkeys,oldkeys);
  159.  
  160. // OnPlayerStateChange
  161. public OnPlayerStateChange(playerid, newstate, oldstate)
  162. {
  163.     if(newstate == PLAYER_STATE_WASTED)
  164.     {
  165.         if(RL_UpdatedHealth[playerid])
  166.             RL_UpdatedHealth[playerid]=false;
  167.         else
  168.         {
  169.             new
  170.                     Float:RL_PlayerPos[3],
  171.                     Float:RL_Distance,
  172.                     Float:RL_CameraPos[3],
  173.                     Float:RL_CameraVectors[3],
  174.                     RL_Tick,
  175.                     Float:RL_HP,
  176.                     Float:RL_Armour
  177.                     ;
  178.             RL_Tick = (GetTickCount()-1000);
  179.             GetPlayerPos(playerid, RL_PlayerPos[0], RL_PlayerPos[1], RL_PlayerPos[2]);
  180.             foreach(Player,i)
  181.             {
  182.                 if(RL_Shooting[i] || RL_Tick < RL_Released[i])
  183.                 {
  184.                     if(i != playerid)
  185.                     {
  186.                         GetPlayerCameraFrontVector(i, RL_CameraVectors[0], RL_CameraVectors[1], RL_CameraVectors[2]);
  187.                         GetPlayerCameraPos(i, RL_CameraPos[0], RL_CameraPos[1], RL_CameraPos[2]);
  188.                         if(IsPlayerInRangeOfPoint(i,200.0,RL_PlayerPos[0], RL_PlayerPos[1], RL_PlayerPos[2]))
  189.                         {
  190.                             GetDistanceFromPointToLine(RL_Distance, RL_CameraVectors[0], RL_CameraVectors[1], RL_CameraVectors[2], RL_CameraPos[0], RL_CameraPos[1], RL_CameraPos[2], RL_PlayerPos[0], RL_PlayerPos[1], RL_PlayerPos[2]);
  191.                             if(RL_Distance < 2.5)
  192.                             {
  193.                                     CallLocalFunction("OnPlayerShootPlayer","iiff",i,playerid,(RL_phealth[playerid]-RL_HP),(RL_parmour[playerid]-RL_Armour));
  194.                                     break;
  195.                             }
  196.                         }
  197.                     }
  198.                 }
  199.             }
  200.         }
  201.        
  202.     }
  203.     RL_Shooting[playerid]=false;
  204.     RL_Released[playerid]=GetTickCount();
  205.     return (RL_OPSC)?CallLocalFunction("RL_OnPlayerStateChange","iii",playerid,newstate,oldstate):1;
  206. }
  207. #if defined _ALS_OnPlayerStateChange
  208.     #undef OnPlayerStateChange
  209. #else
  210.     #define _ALS_OnPlayerStateChange
  211. #endif
  212. #define OnPlayerStateChange RL_OnPlayerStateChange
  213.  
  214. forward RL_OnPlayerStateChange(playerid,newstate, oldstate);
  215.  
  216. // OnPlayerConnect
  217. public OnPlayerConnect(playerid)
  218. {
  219.     RL_Shooting[playerid]=false;
  220.     RL_Released[playerid]=0;
  221.     return (RL_OPC)?CallLocalFunction("RL_OnPlayerConnect","i",playerid):1;
  222. }
  223.  
  224. #if defined _ALS_OnPlayerConnect
  225.     #undef OnPlayerConnect
  226. #else
  227.     #define _ALS_OnPlayerConnect
  228. #endif
  229. #define OnPlayerConnect RL_OnPlayerConnect
  230.  
  231. forward RL_OnPlayerConnect(playerid);
  232.  
  233. // OnGameModeInit
  234. public OnGameModeInit()
  235. {
  236.     RL_OPUP = (funcidx("RL_OnPlayerUpdate") != -1);
  237.     RL_OPSC = (funcidx("RL_OnPlayerStateChange") != -1);
  238.     RL_OPKSC = (funcidx("RL_OnPlayerKeyStateChange") != -1);
  239.     RL_OPC = (funcidx("RL_OnPlayerConnect") != -1);
  240.     return (funcidx("RL_OnGameModeInit") != -1)?CallLocalFunction("RL_OnGameModeInit",""):1;
  241. }
  242. #if defined _ALS_OnGameModeInit
  243.     #undef OnGameModeInit
  244. #else
  245.     #define _ALS_OnGameModeInit
  246. #endif
  247. #define OnGameModeInit RL_OnGameModeInit
  248. forward RL_OnGameModeInit();
  249. // The end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement