Advertisement
Guest User

OPSP v8.4

a guest
Sep 17th, 2011
9,621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.64 KB | None | 0 0
  1. /********************************************
  2.  * OnPlayerShootPlayer! V8.3                *
  3.  * Credits: wups                            *
  4.  * Double-O-Seven for CrossProduct system   *
  5.  * Nero3D for GetPlayerCameraWeaponVector   *
  6.  ********************************************/
  7.  
  8. // include
  9. #include <a_samp>
  10. #tryinclude <foreach>
  11.  
  12. // defines
  13. #if defined OPSP
  14.     #endinput
  15. #endif
  16. #define OPSP
  17.  
  18. #if !defined foreach
  19.     #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  20.     #define __SSCANF_FOREACH__
  21. #endif
  22. #if !defined PRESSED
  23.     #define PRESSED(%0) \
  24.         (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  25. #endif
  26. #if !defined RELEASED
  27.     #define RELEASED(%0) \
  28.         (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
  29. #endif
  30. // variables
  31. static     
  32.         Float:RL_phealth[MAX_PLAYERS],
  33.         Float:RL_parmour[MAX_PLAYERS],
  34.         bool:RL_Shooting[MAX_PLAYERS],
  35.         bool:RL_UpdatedHealth[MAX_PLAYERS],
  36.         bool:RL_OPUP,
  37.         bool:RL_OPSC,
  38.         bool:RL_OPKSC,
  39.         bool:RL_OPC,
  40.         RL_Released[MAX_PLAYERS];
  41. // forwards
  42. forward OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost);
  43.  
  44.  
  45. /*--------------------------------------------------------------------------------------------------
  46.     Function:
  47.         AdjustVector
  48.     Params:
  49.         & Float: vX - x Vector to adjust
  50.         & Float: vY - y Vector to adjust
  51.         & Float: vZ - z Vector to adjust
  52.         Float: oX - x Offset Vector
  53.         Float: oY - y Offset Vector
  54.         const Float: oZ - z Offset Vector
  55.     Return:
  56.         -
  57.     Notes:
  58.         Adjust the vector with the offset
  59. --------------------------------------------------------------------------------------------------*/
  60.  
  61. stock AdjustVector(& Float: vX, & Float: vY, & Float: vZ, Float: oX, Float: oY, const Float: oZ) { // Credits Nero_3D
  62.     static
  63.         Float: Angle;
  64.     Angle = -atan2(vX, vY);
  65.     if(45.0 < Angle) {
  66.         oX ^= oY;
  67.         oY ^= oX;
  68.         oX ^= oY;
  69.         if(90.0 < Angle) {
  70.             oX *= -1;
  71.             if(135.0 < Angle) {
  72.                 oX *= -1;
  73.                 oX ^= oY;
  74.                 oY ^= oX;
  75.                 oX ^= oY;
  76.                 oX *= -1;
  77.             }
  78.         }
  79.     } else if(Angle < 0.0) {
  80.         oY *= -1;
  81.         if(Angle < -45.0) {
  82.             oX *= -1;
  83.             oX ^= oY;
  84.             oY ^= oX;
  85.             oX ^= oY;
  86.             oX *= -1;
  87.             if(Angle < -90.0) {
  88.                 oX *= -1;
  89.                 if(Angle < -135.0) {
  90.                     oX ^= oY;
  91.                     oY ^= oX;
  92.                     oX ^= oY;
  93.                 }
  94.             }
  95.         }
  96.     }
  97.     vX += oX,
  98.     vY += oY;
  99.     vZ += oZ;
  100.     return false;
  101. }
  102. /*--------------------------------------------------------------------------------------------------
  103.     Function:
  104.         GetPlayerCameraWeaponVector
  105.     Params:
  106.         playerid - Player to get the weapon vector of
  107.         & Float: vX - x Vector variable
  108.         & Float: vY - y Vector variable
  109.         & Float: vZ - z Vector variable
  110.     Return:
  111.         If the player is connected
  112.     Notes:
  113.         Gets the weapon vector of the player
  114.  
  115. native GetPlayerCameraWeaponVector(playerid, & Float: vX, & Float: vY, & Float: vZ);
  116. --------------------------------------------------------------------------------------------------*/
  117. stock GetPlayerCameraWeaponVector(playerid, & Float: vX, & Float: vY, & Float: vZ) { // Credits Nero_3D
  118.     static
  119.         weapon;
  120.     if(21 < (weapon = GetPlayerWeapon(playerid)) < 39) {
  121.         GetPlayerCameraFrontVector(playerid, vX, vY, vZ);
  122.         switch(weapon) {
  123.             case WEAPON_SNIPER, WEAPON_ROCKETLAUNCHER, WEAPON_HEATSEEKER: {}
  124.             case WEAPON_RIFLE: {
  125.                 AdjustVector(vX, vY, vZ, 0.016204, 0.009899, 0.047177);
  126.             }
  127.             case WEAPON_AK47, WEAPON_M4: {
  128.                 AdjustVector(vX, vY, vZ, 0.026461, 0.013070, 0.069079);
  129.             }
  130.             default: {
  131.                 AdjustVector(vX, vY, vZ, 0.043949, 0.015922, 0.103412);
  132.             }
  133.         }
  134.         return true;
  135.     }
  136.     else
  137.         GetPlayerCameraFrontVector(playerid, vX, vY, vZ);
  138.     return false;
  139. }
  140. stock crossp(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z, &Float:output)
  141. {
  142.     new
  143.         Float:c1 = (v1y * v2z) - (v1z * v2y),
  144.         Float:c2 = (v1z * v2x) - (v1x * v2z),
  145.         Float:c3 = (v1x * v2y) - (v1y * v2x);
  146.     output = floatsqroot ((c1 * c1) + (c2 * c2) + (c3 * c3));
  147.     return 0;
  148. }
  149. 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)
  150. {
  151.     //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).
  152.     static Float:output;
  153.     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.
  154.     distance = output / floatsqroot ((line_vector_x * line_vector_x) + (line_vector_y * line_vector_y) + (line_vector_z * line_vector_z));
  155.     return 0;
  156. }
  157.  
  158.  
  159. public OnPlayerUpdate(playerid)
  160. {
  161.     static  Float:RL_HP,
  162.             Float:RL_Armour;
  163.     GetPlayerHealth(playerid,RL_HP);
  164.     GetPlayerArmour(playerid,RL_Armour);
  165.     if(RL_HP != RL_phealth[playerid] || RL_Armour != RL_parmour[playerid])
  166.     {
  167.         if(RL_UpdatedHealth[playerid])
  168.             RL_UpdatedHealth[playerid]=false;
  169.         else
  170.         {
  171.             new
  172.                     Float:RL_PlayerPos[3],
  173.                     Float:RL_Distance,
  174.                     Float:RL_CameraPos[3],
  175.                     Float:RL_CameraVectors[3],
  176.                     RL_Tick
  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.                         if(IsPlayerInRangeOfPoint(i,200.0,RL_PlayerPos[0], RL_PlayerPos[1], RL_PlayerPos[2]))
  187.                         {
  188.                             GetPlayerCameraWeaponVector(i, RL_CameraVectors[0], RL_CameraVectors[1], RL_CameraVectors[2]);
  189.                            
  190.                             GetPlayerCameraPos(i, RL_CameraPos[0], RL_CameraPos[1], RL_CameraPos[2]);
  191.                             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]);
  192.                             if(RL_Distance < 2.5)
  193.                             {
  194.                                     CallLocalFunction("OnPlayerShootPlayer","iiff",i,playerid,(RL_phealth[playerid]-RL_HP),(RL_parmour[playerid]-RL_Armour));
  195.                                     break;
  196.                             }
  197.                         }
  198.                     }
  199.                 }
  200.             }
  201.         }
  202.     }
  203.     RL_phealth[playerid]=RL_HP;
  204.     RL_parmour[playerid]=RL_Armour;
  205.     return (RL_OPUP)?CallLocalFunction("RL_OnPlayerUpdate","i",playerid):1;
  206. }
  207. // Functions
  208.  
  209. // SetPlayerHealth
  210. stock SetPlayerHealthEx(playerid, Float:health)
  211. {
  212. //  RL_phealth[playerid]=health;
  213.     RL_UpdatedHealth[playerid]=true;
  214.     return SetPlayerHealth(playerid, health);
  215. }
  216.  
  217. #define SetPlayerHealth SetPlayerHealthEx
  218.  
  219. // SetPlayerArmour
  220. stock SetPlayerArmourEx(playerid, Float:armour)
  221. {
  222. //  RL_parmour[playerid]=armour;
  223.     RL_UpdatedHealth[playerid]=true;
  224.     return SetPlayerArmour(playerid, armour);
  225. }
  226.  
  227. #define SetPlayerArmour SetPlayerArmourEx
  228.  
  229. #if defined _ALS_OnPlayerUpdate
  230.     #undef OnPlayerUpdate
  231. #else
  232.     #define _ALS_OnPlayerUpdate
  233. #endif
  234.  
  235. #define OnPlayerUpdate RL_OnPlayerUpdate
  236. forward RL_OnPlayerUpdate(playerid);
  237.  
  238. // OnPlayerKeyStateChange
  239. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  240. {
  241.     if(PRESSED(KEY_FIRE)) RL_Shooting[playerid]=true;
  242.     else if(RELEASED(KEY_FIRE))
  243.     {
  244.         RL_Shooting[playerid]=false;
  245.         RL_Released[playerid]=GetTickCount();
  246.     }
  247.     return (RL_OPKSC)?CallLocalFunction("RL_OnPlayerKeyStateChange","iii",playerid,newkeys,oldkeys):1;
  248. }
  249. #if defined _ALS_OnPlayerKeyStateChange
  250.     #undef OnPlayerKeyStateChange
  251. #else
  252.     #define _ALS_OnPlayerKeyStateChange
  253. #endif
  254. #define OnPlayerKeyStateChange RL_OnPlayerKeyStateChange
  255. forward RL_OnPlayerKeyStateChange(playerid,newkeys,oldkeys);
  256.  
  257. // OnPlayerStateChange
  258. public OnPlayerStateChange(playerid, newstate, oldstate)
  259. {
  260.     if(newstate == PLAYER_STATE_WASTED)
  261.     {
  262.         if(RL_UpdatedHealth[playerid])
  263.             RL_UpdatedHealth[playerid]=false;
  264.         else
  265.         {
  266.             new
  267.                     Float:RL_PlayerPos[3],
  268.                     Float:RL_Distance,
  269.                     Float:RL_CameraPos[3],
  270.                     Float:RL_CameraVectors[3],
  271.                     RL_Tick,
  272.                     Float:RL_HP,
  273.                     Float:RL_Armour
  274.                     ;
  275.             GetPlayerHealth(playerid,RL_HP);
  276.             GetPlayerArmour(playerid,RL_Armour);
  277.             RL_Tick = (GetTickCount()-1000);
  278.             GetPlayerPos(playerid, RL_PlayerPos[0], RL_PlayerPos[1], RL_PlayerPos[2]);
  279.             foreach(Player,i)
  280.             {
  281.                 if(RL_Shooting[i] || RL_Tick < RL_Released[i])
  282.                 {
  283.                     if(i != playerid)
  284.                     {
  285.                         GetPlayerCameraWeaponVector(i, RL_CameraVectors[0], RL_CameraVectors[1], RL_CameraVectors[2]);
  286.                         GetPlayerCameraPos(i, RL_CameraPos[0], RL_CameraPos[1], RL_CameraPos[2]);
  287.                         if(IsPlayerInRangeOfPoint(i,200.0,RL_PlayerPos[0], RL_PlayerPos[1], RL_PlayerPos[2]))
  288.                         {
  289.                             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]);
  290.                             if(RL_Distance < 2.5)
  291.                             {
  292.                                     CallLocalFunction("OnPlayerShootPlayer","iiff",i,playerid,(RL_phealth[playerid]-RL_HP),(RL_parmour[playerid]-RL_Armour));
  293.                                     break;
  294.                             }
  295.                         }
  296.                     }
  297.                 }
  298.             }
  299.         }
  300.        
  301.     }
  302.     RL_Shooting[playerid]=false;
  303.     RL_Released[playerid]=GetTickCount();
  304.     return (RL_OPSC)?CallLocalFunction("RL_OnPlayerStateChange","iii",playerid,newstate,oldstate):1;
  305. }
  306. #if defined _ALS_OnPlayerStateChange
  307.     #undef OnPlayerStateChange
  308. #else
  309.     #define _ALS_OnPlayerStateChange
  310. #endif
  311. #define OnPlayerStateChange RL_OnPlayerStateChange
  312.  
  313. forward RL_OnPlayerStateChange(playerid,newstate, oldstate);
  314.  
  315.  
  316. // OnPlayerConnect
  317. public OnPlayerConnect(playerid)
  318. {
  319.     RL_Shooting[playerid]=false;
  320.     RL_Released[playerid]=0;
  321.     return (RL_OPC)?CallLocalFunction("RL_OnPlayerConnect","i",playerid):1;
  322. }
  323.  
  324. #if defined _ALS_OnPlayerConnect
  325.     #undef OnPlayerConnect
  326. #else
  327.     #define _ALS_OnPlayerConnect
  328. #endif
  329. #define OnPlayerConnect RL_OnPlayerConnect
  330.  
  331. forward RL_OnPlayerConnect(playerid);
  332. #if !defined FILTERSCRIPT
  333.     // OnGameModeInit
  334.     public OnGameModeInit()
  335.     {
  336.         RL_OPUP = (funcidx("RL_OnPlayerUpdate") != -1);
  337.         RL_OPSC = (funcidx("RL_OnPlayerStateChange") != -1);
  338.         RL_OPKSC = (funcidx("RL_OnPlayerKeyStateChange") != -1);
  339.         RL_OPC = (funcidx("RL_OnPlayerConnect") != -1);
  340.         return (funcidx("RL_OnGameModeInit") != -1)?CallLocalFunction("RL_OnGameModeInit",""):1;
  341.     }
  342.     #if defined _ALS_OnGameModeInit
  343.         #undef OnGameModeInit
  344.     #else
  345.         #define _ALS_OnGameModeInit
  346.     #endif
  347.     #define OnGameModeInit RL_OnGameModeInit
  348.     forward RL_OnGameModeInit();
  349. #else
  350.     // OnFilterScriptInit
  351.     public OnFilterScriptInit()
  352.     {
  353.         RL_OPUP = (funcidx("RL_OnPlayerUpdate") != -1);
  354.         RL_OPSC = (funcidx("RL_OnPlayerStateChange") != -1);
  355.         RL_OPKSC = (funcidx("RL_OnPlayerKeyStateChange") != -1);
  356.         RL_OPC = (funcidx("RL_OnPlayerConnect") != -1);
  357.         return (funcidx("RL_OnFilterScriptInit") != -1)?CallLocalFunction("RL_OnFilterScriptInit",""):1;
  358.     }
  359.     #if defined _ALS_OnFilterScriptInit
  360.         #undef OnFilterScriptInit
  361.     #else
  362.         #define _ALS_OnFilterScriptInit
  363.     #endif
  364.     #define OnFilterScriptInit RL_OnFilterScriptInit.
  365.     forward RL_OnFilterScriptInit();
  366. #endif
  367.  
  368.  
  369. // The end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement