Advertisement
Guest User

[FS]rEasyKill

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