1
0

sync.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // sync.inc - Sync shooting framework for Limitless Roleplay
  2. // Created by Emmet on 01/01/2017 @ 8:18 AM.
  3. static
  4. lastShotFrom[MAX_PLAYERS],
  5. lastShotReason[MAX_PLAYERS char];
  6. forward OnPlayerDamageHandled(playerid, damagedid, Float:amount, weaponid);
  7. static ProcessDamage(playerid, issuerid, Float:amount, weaponid)
  8. {
  9. new Float:health, Float:armour;
  10. GetPlayerHealth(playerid, health);
  11. GetPlayerArmour(playerid, armour);
  12. // Player has armour.
  13. if(armour > 0.0)
  14. {
  15. if(armour >= amount)
  16. {
  17. armour -= amount;
  18. }
  19. else
  20. {
  21. // Player's armour isn't enough to cover the damage. So we'll take some of their health.
  22. health -= amount - armour;
  23. armour = 0;
  24. }
  25. }
  26. // Health deductions.
  27. else if(health > 0.0)
  28. {
  29. if(health >= amount)
  30. {
  31. health -= amount;
  32. }
  33. else
  34. {
  35. // Kill the player obviously.
  36. health = 0;
  37. }
  38. }
  39. // Apply the changes.
  40. SetPlayerHealth(playerid, health < 0.0 ? 0.0 : health);
  41. SetPlayerArmour(playerid, armour < 0.0 ? 0.0 : armour);
  42. if(health <= 0.0)
  43. {
  44. // OnPlayerDeath isn't normally called when teamkilling happens.
  45. // In this case we use CallREMOTEFunction to call it in the gamemode.
  46. CallLocalFunction("OnPlayerDeath", "iii", playerid, issuerid, weaponid);
  47. }
  48. }
  49. public OnPlayerSpawn(playerid)
  50. {
  51. if(GetPlayerTeam(playerid) != 10)
  52. {
  53. // If you set the player in a team script-wise then they can't damage each other.
  54. SetPlayerTeam(playerid, 10);
  55. }
  56. lastShotFrom[playerid] = INVALID_PLAYER_ID;
  57. lastShotReason[playerid] = 0;
  58. #if defined SYNC_OnPlayerSpawn
  59. return SYNC_OnPlayerSpawn(playerid);
  60. #else
  61. return 1;
  62. #endif
  63. }
  64. #if defined _ALS_OnPlayerSpawn
  65. #undef OnPlayerSpawn
  66. #else
  67. #define _ALS_OnPlayerSpawn
  68. #endif
  69. #define OnPlayerSpawn SYNC_OnPlayerSpawn
  70. #if defined SYNC_OnPlayerSpawn
  71. forward SYNC_OnPlayerSpawn(playerid);
  72. #endif
  73. public OnPlayerDisconnect(playerid, reason)
  74. {
  75. for(new i = 0; i <= GetPlayerPoolSize(); i ++)
  76. {
  77. if(IsPlayerConnected(i) && lastShotFrom[i] == playerid)
  78. {
  79. lastShotFrom[i] = INVALID_PLAYER_ID;
  80. lastShotReason[i] = 0;
  81. }
  82. }
  83. #if defined SYNC_OnPlayerDisconnect
  84. return SYNC_OnPlayerDisconnect(playerid, reason);
  85. #else
  86. return 1;
  87. #endif
  88. }
  89. #if defined _ALS_OnPlayerDisconnect
  90. #undef OnPlayerDisconnect
  91. #else
  92. #define _ALS_OnPlayerDisconnect
  93. #endif
  94. #define OnPlayerDisconnect SYNC_OnPlayerDisconnect
  95. #if defined SYNC_OnPlayerDisconnect
  96. forward SYNC_OnPlayerDisconnect(playerid, reason);
  97. #endif
  98. public OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid)
  99. {
  100. if(issuerid != INVALID_PLAYER_ID && IsPlayerConnected(playerid))
  101. {
  102. if(funcidx("OnPlayerDamageHandled") == -1 || CallLocalFunction("OnPlayerDamageHandled", "iifi", issuerid, playerid, amount, weaponid))
  103. {
  104. ProcessDamage(playerid, issuerid, amount, weaponid);
  105. }
  106. }
  107. lastShotFrom[playerid] = issuerid;
  108. lastShotReason[playerid] = weaponid;
  109. #if defined SYNC_OnPlayerTakeDamage
  110. return SYNC_OnPlayerTakeDamage
  111. #else
  112. return 1;
  113. #endif
  114. }
  115. #if defined _ALS_OnPlayerTakeDamage
  116. #undef OnPlayerTakeDamage
  117. #else
  118. #define _ALS_OnPlayerTakeDamage
  119. #endif
  120. #define OnPlayerTakeDamage SYNC_OnPlayerTakeDamage
  121. #if defined SYNC_OnPlayerTakeDamage
  122. forward SYNC_OnPlayerTakeDamage(playerid, issuerid, Float:amount, weaponid);
  123. #endif