Guest User

Untitled

a guest
Apr 9th, 2018
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.18 KB | None | 0 0
  1. public OnPlayerGiveDamage(playerid, damagedid, Float:amount, weaponid, bodypart)
  2. {
  3. if (!IsHighRateWeapon(weaponid)) {
  4. DebugMessage(playerid, "OnPlayerGiveDamage(%d gave %f to %d using %d on bodypart %d)", playerid, amount, damagedid, weaponid, bodypart);
  5. }
  6.  
  7. // Nobody got damaged
  8. if (damagedid == INVALID_PLAYER_ID) {
  9. #if defined OnInvalidWeaponDamage
  10. OnInvalidWeaponDamage(playerid, damagedid, amount, weaponid, bodypart, WC_NO_DAMAGED, true);
  11. #endif
  12.  
  13. AddRejectedHit(playerid, damagedid, HIT_NO_DAMAGEDID, weaponid);
  14.  
  15. return 0;
  16. }
  17.  
  18. if (s_IsDying[damagedid]) {
  19. AddRejectedHit(playerid, damagedid, HIT_DYING_PLAYER, weaponid);
  20. return 0;
  21. }
  22.  
  23. if (!s_LagCompMode) {
  24. new npc = IsPlayerNPC(damagedid);
  25.  
  26. if (weaponid == WEAPON_KNIFE && _:amount == _:0.0) {
  27. if (s_KnifeTimeout[damagedid] != -1) {
  28. KillTimer(s_KnifeTimeout[damagedid]);
  29. }
  30.  
  31. s_KnifeTimeout[damagedid] = SetTimerEx("WC_SetSpawnForStreamedIn", 2500, false, "i", damagedid);
  32. }
  33.  
  34. if (!npc) {
  35. return 0;
  36. }
  37. }
  38.  
  39. // Ignore unreliable and invalid damage
  40. if (weaponid < 0 || weaponid >= sizeof(s_ValidDamageGiven) || !s_ValidDamageGiven[weaponid]) {
  41. // Fire is synced as taken damage (because it's not reliable as given), so no need to show a rejected hit.
  42. // Vehicle damage is also synced as taken, so no need to show that either.
  43. if (weaponid != WEAPON_FLAMETHROWER && weaponid != WEAPON_VEHICLE) {
  44. AddRejectedHit(playerid, damagedid, HIT_INVALID_WEAPON, weaponid);
  45. }
  46.  
  47. return 0;
  48. }
  49.  
  50. if (!IsPlayerSpawned(playerid)) {
  51. // Make sure the rejected hit wasn't added in OnPlayerWeaponShot
  52. if (!IsBulletWeapon(weaponid) || s_LastShot[playerid][e_Valid]) {
  53. AddRejectedHit(playerid, damagedid, HIT_NOT_SPAWNED, weaponid);
  54. }
  55.  
  56. return 0;
  57. }
  58.  
  59. new npc = IsPlayerNPC(damagedid);
  60.  
  61. // From stealth knife, can be any weapon
  62. if (_:amount == _:1833.33154296875) {
  63. return 0;
  64. }
  65.  
  66. if (weaponid == WEAPON_KNIFE) {
  67. if (_:amount == _:0.0) {
  68. // Resync without bothering the player being knifed
  69. if (npc || HasSameTeam(playerid, damagedid)) {
  70. if (s_KnifeTimeout[damagedid] != -1) {
  71. KillTimer(s_KnifeTimeout[damagedid]);
  72. }
  73.  
  74. s_KnifeTimeout[damagedid] = SetTimerEx("WC_SpawnForStreamedIn", 150, false, "i", damagedid);
  75. ClearAnimations(playerid, 1);
  76. SetPlayerArmedWeapon(playerid, 0);
  77.  
  78. return 0;
  79. }
  80.  
  81. if (!OnPlayerDamage(damagedid, amount, playerid, weaponid, bodypart)) {
  82. if (s_KnifeTimeout[damagedid] != -1) {
  83. KillTimer(s_KnifeTimeout[damagedid]);
  84. }
  85.  
  86. s_KnifeTimeout[damagedid] = SetTimerEx("WC_SpawnForStreamedIn", 150, false, "i", damagedid);
  87. ClearAnimations(playerid, 1);
  88. SetPlayerArmedWeapon(playerid, 0);
  89.  
  90. return 0;
  91. }
  92.  
  93. s_DamageDoneHealth[playerid] = s_PlayerHealth[playerid];
  94. s_DamageDoneArmour[playerid] = s_PlayerArmour[playerid];
  95.  
  96. OnPlayerDamageDone(damagedid, s_PlayerHealth[damagedid] + s_PlayerArmour[damagedid], playerid, weaponid, bodypart);
  97.  
  98. ClearAnimations(damagedid, 1);
  99.  
  100. PlayerDeath(damagedid, "KNIFE", "KILL_Knife_Ped_Damage", _, 5200);
  101.  
  102. SetTimerEx("WC_SecondKnifeAnim", 2200, false, "i", damagedid);
  103.  
  104. #if defined WC_OnPlayerDeath
  105. WC_OnPlayerDeath(damagedid, playerid, weaponid);
  106. #endif
  107.  
  108. DebugMessage(damagedid, "being knifed by %d", playerid);
  109. DebugMessage(playerid, "knifing %d", damagedid);
  110.  
  111. new Float:x, Float:y, Float:z, Float:a;
  112.  
  113. GetPlayerFacingAngle(damagedid, a);
  114. SetPlayerFacingAngle(playerid, a);
  115. PosInFront(damagedid, -1.0, x, y, z);
  116.  
  117. SetPlayerVelocity(damagedid, 0.0, 0.0, 0.0);
  118. SetPlayerVelocity(playerid, 0.0, 0.0, 0.0);
  119.  
  120. new forcesync = 2;
  121.  
  122. if (747 < GetPlayerAnimationIndex(playerid) > 748) {
  123. DebugMessageRed(playerid, "applying knife anim for you too (current: %d)", GetPlayerAnimationIndex(playerid));
  124.  
  125. forcesync = 1;
  126. }
  127.  
  128. ApplyAnimation(playerid, "KNIFE", "KILL_Knife_Player", 4.1, 0, 1, 1, 0, 1800, forcesync);
  129.  
  130. return 0;
  131. }
  132. }
  133.  
  134. if (HasSameTeam(playerid, damagedid)) {
  135. AddRejectedHit(playerid, damagedid, HIT_SAME_TEAM, weaponid);
  136. return 0;
  137. }
  138.  
  139. // Both players should see eachother
  140. if ((!IsPlayerStreamedIn(playerid, damagedid) && !IsPlayerPaused(damagedid)) || !IsPlayerStreamedIn(damagedid, playerid)) {
  141. AddRejectedHit(playerid, damagedid, HIT_UNSTREAMED, weaponid, damagedid);
  142. return 0;
  143. }
  144.  
  145. new Float:bullets, err;
  146.  
  147. if ((err = ProcessDamage(damagedid, playerid, amount, weaponid, bodypart, bullets))) {
  148. if (err == WC_INVALID_DAMAGE) {
  149. AddRejectedHit(playerid, damagedid, HIT_INVALID_DAMAGE, weaponid, _:amount);
  150. }
  151.  
  152. if (err != WC_INVALID_DISTANCE) {
  153. #if defined OnInvalidWeaponDamage
  154. OnInvalidWeaponDamage(playerid, damagedid, amount, weaponid, bodypart, err, true);
  155. #endif
  156. }
  157.  
  158. return 0;
  159. }
  160.  
  161. new tick = GetTickCount();
  162. if (tick == 0) tick = 1;
  163.  
  164. new idx = (s_LastHitIdx[playerid] + 1) % sizeof(s_LastHitTicks[]);
  165.  
  166. // JIT plugin fix
  167. if (idx < 0) {
  168. idx += sizeof(s_LastHitTicks[]);
  169. }
  170.  
  171. s_LastHitIdx[playerid] = idx;
  172. s_LastHitTicks[playerid][idx] = tick;
  173. s_LastHitWeapons[playerid][idx] = weaponid;
  174. s_HitsIssued[playerid] += 1;
  175.  
  176. #if WC_DEBUG
  177. if (s_HitsIssued[playerid] > 1) {
  178. new prev_tick_idx = (idx - 1) % sizeof(s_LastHitTicks[]);
  179.  
  180. // JIT plugin fix
  181. if (prev_tick_idx < 0) {
  182. prev_tick_idx += sizeof(s_LastHitTicks[]);
  183. }
  184.  
  185. new prev_tick = s_LastHitTicks[playerid][prev_tick_idx];
  186.  
  187. DebugMessage(playerid, "(hit) last: %d last 3: %d", tick - prev_tick, AverageHitRate(playerid, 3));
  188. }
  189. #endif
  190.  
  191. new multiple_weapons;
  192. new avg_rate = AverageHitRate(playerid, s_MaxHitRateSamples, multiple_weapons);
  193.  
  194. // Hit issue flood?
  195. // Could be either a cheat or just lag
  196. if (avg_rate != -1) {
  197. if (multiple_weapons) {
  198. if (avg_rate < 100) {
  199. AddRejectedHit(playerid, damagedid, HIT_RATE_TOO_FAST_MULTIPLE, weaponid, avg_rate, s_MaxHitRateSamples);
  200. return 0;
  201. }
  202. } else if (s_MaxWeaponShootRate[weaponid] - avg_rate > 20) {
  203. AddRejectedHit(playerid, damagedid, HIT_RATE_TOO_FAST, weaponid, avg_rate, s_MaxHitRateSamples, s_MaxWeaponShootRate[weaponid]);
  204. return 0;
  205. }
  206. }
  207.  
  208. if (IsBulletWeapon(weaponid) && _:amount != _:2.6400001049041748046875 && !(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0)) {
  209. new valid = true;
  210.  
  211. if (!s_LastShot[playerid][e_Valid]) {
  212. //AddRejectedHit(playerid, damagedid, HIT_LAST_SHOT_INVALID, weaponid);
  213. valid = false;
  214. DebugMessageRed(playerid, "last shot not valid");
  215. } else if (WEAPON_SHOTGUN <= weaponid <= WEAPON_SHOTGSPA) {
  216. // Let's assume someone won't hit 3 players with 1 shotgun shot, and that one OnPlayerWeaponShot can be out of sync
  217. if (s_LastShot[playerid][e_Hits] >= 3) {
  218. valid = false;
  219. AddRejectedHit(playerid, damagedid, HIT_MULTIPLE_PLAYERS_SHOTGUN, weaponid, s_LastShot[playerid][e_Hits] + 1);
  220. }
  221. } else if (s_LastShot[playerid][e_Hits] > 0) {
  222. // Sniper doesn't always send OnPlayerWeaponShot
  223. if (s_LastShot[playerid][e_Hits] > 4 && weaponid != WEAPON_SNIPER) {
  224. valid = false;
  225. AddRejectedHit(playerid, damagedid, HIT_MULTIPLE_PLAYERS, weaponid, s_LastShot[playerid][e_Hits] + 1);
  226. } else {
  227. DebugMessageRed(playerid, "hit %d players with 1 shot", s_LastShot[playerid][e_Hits] + 1);
  228. }
  229. }
  230.  
  231. s_LastShot[playerid][e_Hits] += 1;
  232.  
  233. if (!valid) {
  234. return 0;
  235. }
  236. }
  237.  
  238. if (npc) {
  239. OnPlayerDamageDone(damagedid, amount, playerid, weaponid, bodypart);
  240. } else {
  241. InflictDamage(damagedid, amount, playerid, weaponid, bodypart);
  242. }
  243.  
  244. // Don't send OnPlayerGiveDamage to the rest of the script, since it should not be used
  245. return 0;
  246. }
  247.  
  248. public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid, bodypart)
  249. {
  250. UpdateHealthBar(playerid, true);
  251.  
  252. if (s_IsDying[playerid]) {
  253. return 0;
  254. }
  255.  
  256. if (s_BeingResynced[playerid]) {
  257. return 0;
  258. }
  259.  
  260. if (!IsHighRateWeapon(weaponid)) {
  261. DebugMessage(playerid, "OnPlayerTakeDamage(%d took %f from %d by %d on bodypart %d)", playerid, amount, issuerid, weaponid, bodypart);
  262. }
  263.  
  264. // Ignore unreliable and invalid damage
  265. if (weaponid < 0 || weaponid >= sizeof(s_ValidDamageTaken) || !s_ValidDamageTaken[weaponid]) {
  266. return 0;
  267. }
  268.  
  269. if (playerid == INVALID_PLAYER_ID || IsPlayerNPC(playerid)) {
  270. return 0;
  271. }
  272.  
  273. // Carjack damage
  274. if (weaponid == 54 && _:amount == _:0.0) {
  275. return 0;
  276. }
  277.  
  278. // From stealth knife, can be any weaponid
  279. if (_:amount == _:1833.33154296875) {
  280. return 0;
  281. }
  282.  
  283. // Climb bug
  284. if (weaponid == WEAPON_COLLISION) {
  285. if (s_CustomFallDamage) {
  286. return 0;
  287. }
  288.  
  289. new anim = GetPlayerAnimationIndex(playerid);
  290.  
  291. if (1061 <= anim <= 1067) {
  292. DebugMessage(playerid, "climb bug prevented");
  293. return 0;
  294. }
  295. }
  296.  
  297. // Being knifed client-side
  298. if (weaponid == WEAPON_KNIFE) {
  299. if (s_IsDying[playerid]) {
  300. return 0;
  301. }
  302.  
  303. // With the plugin, this part is never actually used (it can't happen)
  304. if (_:amount == _:0.0) {
  305. if (s_KnifeTimeout[playerid] != -1) {
  306. KillTimer(s_KnifeTimeout[playerid]);
  307.  
  308. s_KnifeTimeout[playerid] = -1;
  309. }
  310.  
  311. if (issuerid == INVALID_PLAYER_ID || HasSameTeam(playerid, issuerid)) {
  312. ResyncPlayer(playerid);
  313.  
  314. return 0;
  315. }
  316.  
  317. if (!OnPlayerDamage(playerid, amount, issuerid, weaponid, bodypart)) {
  318. ResyncPlayer(playerid);
  319.  
  320. return 0;
  321. }
  322.  
  323. // Make sure the values were not modified
  324. weaponid = WEAPON_KNIFE;
  325. amount = 0.0;
  326.  
  327. s_DamageDoneHealth[playerid] = s_PlayerHealth[playerid];
  328. s_DamageDoneArmour[playerid] = s_PlayerArmour[playerid];
  329.  
  330. OnPlayerDamageDone(playerid, s_PlayerHealth[playerid] + s_PlayerArmour[playerid], issuerid, weaponid, bodypart);
  331.  
  332. PlayerDeath(playerid, "KNIFE", "KILL_Knife_Ped_Die", _, 4000 - GetPlayerPing(playerid));
  333.  
  334. #if defined WC_OnPlayerDeath
  335. WC_OnPlayerDeath(playerid, issuerid, weaponid);
  336. #endif
  337.  
  338. SetPlayerHealth(playerid, Float:0x7f7fffff);
  339.  
  340. DebugMessage(playerid, "being knifed by %d", issuerid);
  341. DebugMessage(issuerid, "knifing %d", playerid);
  342.  
  343. new Float:x, Float:y, Float:z, Float:a;
  344.  
  345. GetPlayerFacingAngle(playerid, a);
  346. SetPlayerFacingAngle(issuerid, a);
  347. PosInFront(playerid, -1.0, x, y, z);
  348.  
  349. SetPlayerVelocity(playerid, 0.0, 0.0, 0.0);
  350. SetPlayerVelocity(issuerid, 0.0, 0.0, 0.0);
  351.  
  352. new forcesync = 2;
  353.  
  354. if (GetPlayerAnimationIndex(issuerid) != 747) {
  355. DebugMessageRed(issuerid, "applying knife anim for you too (current: %d)", GetPlayerAnimationIndex(issuerid));
  356.  
  357. forcesync = 1;
  358. }
  359.  
  360. ApplyAnimation(issuerid, "KNIFE", "KILL_Knife_Player", 4.1, 0, 1, 1, 0, 1800, forcesync);
  361.  
  362. return 0;
  363. }
  364. }
  365.  
  366. // If it's lagcomp, only allow damage that's valid for both modes
  367. if (s_LagCompMode && s_ValidDamageTaken[weaponid] != 2) {
  368. if (issuerid != INVALID_PLAYER_ID && IsPlayerInAnyVehicle(issuerid) && GetPlayerVehicleSeat(issuerid) == 0 && (weaponid == WEAPON_M4 || weaponid == WEAPON_MINIGUN)) {
  369. weaponid = weaponid == WEAPON_M4 ? WEAPON_VEHICLE_M4 : WEAPON_VEHICLE_MINIGUN;
  370. } else {
  371. return 0;
  372. }
  373. }
  374.  
  375. // Should still be damaged by grenades or fire after someone has died
  376. if (issuerid != INVALID_PLAYER_ID) {
  377. if (HasSameTeam(playerid, issuerid)) {
  378. return 0;
  379. }
  380.  
  381. if (s_IsDying[issuerid] && (IsBulletWeapon(weaponid) || IsMeleeWeapon(weaponid))) {
  382. DebugMessageRed(playerid, "shot/punched by dead player (%d)", issuerid);
  383.  
  384. return 0;
  385. }
  386.  
  387. if (s_BeingResynced[issuerid]) {
  388. return 0;
  389. }
  390. }
  391.  
  392. new Float:bullets = 0.0, err;
  393.  
  394. if ((err = ProcessDamage(playerid, issuerid, amount, weaponid, bodypart, bullets))) {
  395. if (err == WC_INVALID_DAMAGE) {
  396. AddRejectedHit(issuerid, playerid, HIT_INVALID_DAMAGE, weaponid, _:amount);
  397. }
  398.  
  399. if (err != WC_INVALID_DISTANCE) {
  400. #if defined OnInvalidWeaponDamage
  401. OnInvalidWeaponDamage(issuerid, playerid, amount, weaponid, bodypart, err, false);
  402. #endif
  403. }
  404.  
  405. return 0;
  406. }
  407.  
  408. if (IsBulletWeapon(weaponid)) {
  409. new Float:x, Float:y, Float:z;
  410. GetPlayerPos(issuerid, x, y, z);
  411. new Float:dist = GetPlayerDistanceFromPoint(playerid, x, y, z);
  412.  
  413. if (dist > s_WeaponRange[weaponid] + 2.0) {
  414. AddRejectedHit(issuerid, playerid, HIT_OUT_OF_RANGE, weaponid, _:dist, _:s_WeaponRange[weaponid]);
  415. return 0;
  416. }
  417. }
  418.  
  419. InflictDamage(playerid, amount, issuerid, weaponid, bodypart);
  420.  
  421. return 0;
  422. }
Advertisement
Add Comment
Please, Sign In to add comment