Advertisement
freefiles

Untitled

Feb 28th, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3. #include <sdkhooks>
  4. #pragma semicolon 1
  5.  
  6. #define MAX_SPAWNPOINTS 64
  7.  
  8. enum
  9. {
  10. Team_Allies = 0,
  11. Team_Axis
  12. }
  13.  
  14. enum ConVars
  15. {
  16. Handle:Enabled,
  17. Handle:GrenadeEnabled,
  18. Handle:RocketEnabled,
  19. Handle:MaxDistance,
  20. Handle:DisplayMessage,
  21. Handle:TextChatMessage
  22. }
  23.  
  24. new g_iConVar[ConVars];
  25.  
  26. new g_iOffset_Origin;
  27. new g_iOffset_StunDuration;
  28.  
  29. new g_iSpawnCount[2];
  30.  
  31. static const String:g_szGrenades[][] =
  32. {
  33. "bazooka",
  34. "pschreck",
  35. "frag_us",
  36. "frag_ger",
  37. "riflegren_us",
  38. "riflegren_ger"
  39. };
  40.  
  41. static const String:g_szSpawnPoints[][] =
  42. {
  43. "info_player_allies",
  44. "info_player_axis"
  45. };
  46.  
  47. new Float:g_vecSpawnPositions[2][MAX_SPAWNPOINTS][3];
  48.  
  49. public Plugin:myinfo =
  50. {
  51. name = "Grenade-Rocket Spawn Protection Edition",
  52. author = "Andersso,T@HK",
  53. description = "Blocks damage from grenades,rocket in spawn",
  54. version = "1.3.6",
  55. url = "http://www.dodsourceplugins.net/,http://dayofdefeat.ucoz.net/"
  56. };
  57.  
  58. public OnPluginStart()
  59. {
  60. LoadTranslations("grenaderocketprotection.phrases");
  61.  
  62. g_iConVar[Enabled] = CreateConVar("sm_grenaderocketprotection_enabled", "1", "Enable/Disable Full Grenade/Rocket Protection.");
  63. g_iConVar[GrenadeEnabled] = CreateConVar("sm_grenadeprotection_enabled", "1", "Enable/Disable Only Grenade Protection.");
  64. g_iConVar[RocketEnabled] = CreateConVar("sm_rocketprotection_enabled", "1", "Enable/Disable Only Rocket Protection.");
  65. g_iConVar[MaxDistance] = CreateConVar("sm_grenadeprotection_maxdistance", "500", "Maximum distance a player can be away from spawn without taking any damage from grenades.");
  66. g_iConVar[DisplayMessage] = CreateConVar("sm_grenadeprotection_displaymessage", "1", "Enable/Disable showing text message to attacker.");
  67. g_iConVar[TextChatMessage] = CreateConVar("sm_grenadeprotection_textchatmessage", "1", "Enable/Disable showing chat text message to attacker.");
  68.  
  69. AutoExecConfig(true, "dod_grenaderocketprotection", "sourcemod");
  70.  
  71. if ((g_iOffset_Origin = FindSendPropOffs("CBaseEntity", "m_vecOrigin")) == -1)
  72. {
  73. SetFailState("Fatal Error: Unable to find prop offset \"CBaseEntity::m_vecOrigin\"!");
  74. }
  75.  
  76. if ((g_iOffset_StunDuration = FindSendPropOffs("CDODPlayer", "m_flStunDuration")) == -1)
  77. {
  78. SetFailState("Fatal Error: Unable to find prop offset \"CDODPlayer::m_flStunDuration\"!");
  79. }
  80. }
  81.  
  82. public OnMapStart()
  83. {
  84. new iEntity;
  85.  
  86. for (new i = 0; i < sizeof(g_szSpawnPoints); i++)
  87. {
  88. g_iSpawnCount[i] = 0;
  89.  
  90. iEntity = -1;
  91.  
  92. while ((iEntity = FindEntityByClassname(iEntity, g_szSpawnPoints[i])) != -1)
  93. {
  94. if (g_iSpawnCount[i] < MAX_SPAWNPOINTS)
  95. {
  96. GetEntDataVector(iEntity, g_iOffset_Origin, g_vecSpawnPositions[i][g_iSpawnCount[i]++]);
  97. }
  98. }
  99. }
  100. }
  101.  
  102. public OnClientPutInServer(iClient)
  103. {
  104. SDKHook(iClient, SDKHook_OnTakeDamage, OnTakeDamage);
  105. }
  106.  
  107. public Action:OnTakeDamage(iClient, &iAttacker, &iInflictor, &Float:fDamage, &iDamageType)
  108. {
  109. if (GetConVarBool(g_iConVar[Enabled]))
  110. {
  111. if (iClient != iAttacker && iInflictor > MaxClients && IsValidEdict(iInflictor) && iDamageType & DMG_BLAST)
  112. {
  113. decl String:szInflictorName[64];
  114. GetEdictClassname(iInflictor, szInflictorName, sizeof(szInflictorName));
  115.  
  116. if (ReplaceString(szInflictorName, sizeof(szInflictorName), "grenade_", NULL_STRING) >= 1 && GetConVarBool(g_iConVar[GrenadeEnabled]))
  117. {
  118.  
  119. for (new i = 0; i < sizeof(g_szGrenades); i++)
  120. {
  121. if (StrEqual(szInflictorName, g_szGrenades[i]) && IsPlayerNearSpawn(iClient))
  122. {
  123. if (GetConVarBool(g_iConVar[DisplayMessage]) && IsClientInGame(iAttacker))
  124. {
  125. PrintCenterText(iAttacker, "%t", "Attacker Message Grenades");
  126. }
  127.  
  128. if (GetConVarBool(g_iConVar[TextChatMessage]) && IsClientInGame(iAttacker))
  129. {
  130. PrintToChat(iAttacker, "\x04[GrenadeRocket Protection] \x03%t", "Attacker Message Grenades");
  131. }
  132.  
  133. SetEntDataFloat(iClient, g_iOffset_StunDuration, 0.0);
  134.  
  135. return Plugin_Handled;
  136. }
  137. }
  138. }
  139.  
  140. if (ReplaceString(szInflictorName, sizeof(szInflictorName), "rocket_", NULL_STRING) >= 1 && GetConVarBool(g_iConVar[RocketEnabled]))
  141. {
  142. for (new i = 0; i < sizeof(g_szGrenades); i++)
  143. {
  144. if (StrEqual(szInflictorName, g_szGrenades[i]) && IsPlayerNearSpawn(iClient))
  145. {
  146. if (GetConVarBool(g_iConVar[DisplayMessage]) && IsClientInGame(iAttacker))
  147. {
  148. PrintCenterText(iAttacker, "%t", "Attacker Message Rocket");
  149. }
  150.  
  151. if (GetConVarBool(g_iConVar[TextChatMessage]) && IsClientInGame(iAttacker))
  152. {
  153. PrintToChat(iAttacker, "\x04[GrenadeRocket Protection] \x03%t", "Attacker Message Rocket");
  154. }
  155.  
  156. SetEntDataFloat(iClient, g_iOffset_StunDuration, 0.0);
  157.  
  158. return Plugin_Handled;
  159. }
  160. }
  161. }
  162. }
  163. }
  164.  
  165. return Plugin_Continue;
  166. }
  167.  
  168. bool:IsPlayerNearSpawn(iClient)
  169. {
  170. decl Float:vecOrigin[3];
  171. GetClientAbsOrigin(iClient, vecOrigin);
  172.  
  173. new iTeam = GetClientTeam(iClient) - 2;
  174.  
  175. for (new i = 0; i < g_iSpawnCount[iTeam]; i++)
  176. {
  177. if (GetVectorDistance(g_vecSpawnPositions[iTeam][i], vecOrigin) <= GetConVarFloat(g_iConVar[MaxDistance]))
  178. {
  179. return true;
  180. }
  181. }
  182.  
  183. return false;
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement