Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <sdktools>
- #include <sdkhooks>
- #pragma semicolon 1
- #define MAX_SPAWNPOINTS 64
- enum
- {
- Team_Allies = 0,
- Team_Axis
- }
- enum ConVars
- {
- Handle:Enabled,
- Handle:GrenadeEnabled,
- Handle:RocketEnabled,
- Handle:MaxDistance,
- Handle:DisplayMessage,
- Handle:TextChatMessage
- }
- new g_iConVar[ConVars];
- new g_iOffset_Origin;
- new g_iOffset_StunDuration;
- new g_iSpawnCount[2];
- static const String:g_szGrenades[][] =
- {
- "bazooka",
- "pschreck",
- "frag_us",
- "frag_ger",
- "riflegren_us",
- "riflegren_ger"
- };
- static const String:g_szSpawnPoints[][] =
- {
- "info_player_allies",
- "info_player_axis"
- };
- new Float:g_vecSpawnPositions[2][MAX_SPAWNPOINTS][3];
- public Plugin:myinfo =
- {
- name = "Grenade-Rocket Spawn Protection Edition",
- author = "Andersso,T@HK",
- description = "Blocks damage from grenades,rocket in spawn",
- version = "1.3.6",
- url = "http://www.dodsourceplugins.net/,http://dayofdefeat.ucoz.net/"
- };
- public OnPluginStart()
- {
- LoadTranslations("grenaderocketprotection.phrases");
- g_iConVar[Enabled] = CreateConVar("sm_grenaderocketprotection_enabled", "1", "Enable/Disable Full Grenade/Rocket Protection.");
- g_iConVar[GrenadeEnabled] = CreateConVar("sm_grenadeprotection_enabled", "1", "Enable/Disable Only Grenade Protection.");
- g_iConVar[RocketEnabled] = CreateConVar("sm_rocketprotection_enabled", "1", "Enable/Disable Only Rocket Protection.");
- g_iConVar[MaxDistance] = CreateConVar("sm_grenadeprotection_maxdistance", "500", "Maximum distance a player can be away from spawn without taking any damage from grenades.");
- g_iConVar[DisplayMessage] = CreateConVar("sm_grenadeprotection_displaymessage", "1", "Enable/Disable showing text message to attacker.");
- g_iConVar[TextChatMessage] = CreateConVar("sm_grenadeprotection_textchatmessage", "1", "Enable/Disable showing chat text message to attacker.");
- AutoExecConfig(true, "dod_grenaderocketprotection", "sourcemod");
- if ((g_iOffset_Origin = FindSendPropOffs("CBaseEntity", "m_vecOrigin")) == -1)
- {
- SetFailState("Fatal Error: Unable to find prop offset \"CBaseEntity::m_vecOrigin\"!");
- }
- if ((g_iOffset_StunDuration = FindSendPropOffs("CDODPlayer", "m_flStunDuration")) == -1)
- {
- SetFailState("Fatal Error: Unable to find prop offset \"CDODPlayer::m_flStunDuration\"!");
- }
- }
- public OnMapStart()
- {
- new iEntity;
- for (new i = 0; i < sizeof(g_szSpawnPoints); i++)
- {
- g_iSpawnCount[i] = 0;
- iEntity = -1;
- while ((iEntity = FindEntityByClassname(iEntity, g_szSpawnPoints[i])) != -1)
- {
- if (g_iSpawnCount[i] < MAX_SPAWNPOINTS)
- {
- GetEntDataVector(iEntity, g_iOffset_Origin, g_vecSpawnPositions[i][g_iSpawnCount[i]++]);
- }
- }
- }
- }
- public OnClientPutInServer(iClient)
- {
- SDKHook(iClient, SDKHook_OnTakeDamage, OnTakeDamage);
- }
- public Action:OnTakeDamage(iClient, &iAttacker, &iInflictor, &Float:fDamage, &iDamageType)
- {
- if (GetConVarBool(g_iConVar[Enabled]))
- {
- if (iClient != iAttacker && iInflictor > MaxClients && IsValidEdict(iInflictor) && iDamageType & DMG_BLAST)
- {
- decl String:szInflictorName[64];
- GetEdictClassname(iInflictor, szInflictorName, sizeof(szInflictorName));
- if (ReplaceString(szInflictorName, sizeof(szInflictorName), "grenade_", NULL_STRING) >= 1 && GetConVarBool(g_iConVar[GrenadeEnabled]))
- {
- for (new i = 0; i < sizeof(g_szGrenades); i++)
- {
- if (StrEqual(szInflictorName, g_szGrenades[i]) && IsPlayerNearSpawn(iClient))
- {
- if (GetConVarBool(g_iConVar[DisplayMessage]) && IsClientInGame(iAttacker))
- {
- PrintCenterText(iAttacker, "%t", "Attacker Message Grenades");
- }
- if (GetConVarBool(g_iConVar[TextChatMessage]) && IsClientInGame(iAttacker))
- {
- PrintToChat(iAttacker, "\x04[GrenadeRocket Protection] \x03%t", "Attacker Message Grenades");
- }
- SetEntDataFloat(iClient, g_iOffset_StunDuration, 0.0);
- return Plugin_Handled;
- }
- }
- }
- if (ReplaceString(szInflictorName, sizeof(szInflictorName), "rocket_", NULL_STRING) >= 1 && GetConVarBool(g_iConVar[RocketEnabled]))
- {
- for (new i = 0; i < sizeof(g_szGrenades); i++)
- {
- if (StrEqual(szInflictorName, g_szGrenades[i]) && IsPlayerNearSpawn(iClient))
- {
- if (GetConVarBool(g_iConVar[DisplayMessage]) && IsClientInGame(iAttacker))
- {
- PrintCenterText(iAttacker, "%t", "Attacker Message Rocket");
- }
- if (GetConVarBool(g_iConVar[TextChatMessage]) && IsClientInGame(iAttacker))
- {
- PrintToChat(iAttacker, "\x04[GrenadeRocket Protection] \x03%t", "Attacker Message Rocket");
- }
- SetEntDataFloat(iClient, g_iOffset_StunDuration, 0.0);
- return Plugin_Handled;
- }
- }
- }
- }
- }
- return Plugin_Continue;
- }
- bool:IsPlayerNearSpawn(iClient)
- {
- decl Float:vecOrigin[3];
- GetClientAbsOrigin(iClient, vecOrigin);
- new iTeam = GetClientTeam(iClient) - 2;
- for (new i = 0; i < g_iSpawnCount[iTeam]; i++)
- {
- if (GetVectorDistance(g_vecSpawnPositions[iTeam][i], vecOrigin) <= GetConVarFloat(g_iConVar[MaxDistance]))
- {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement