xFernando_xD

OPSP

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