Adding a cooldown to the script fixed the problem. I believe you can mark this topic solved. Big thanks to nosoop for the code snippets and his coding tips.
Code:
#pragma semicolon 1
#include <TF2_stocks>
#define RSOUND "weapons/rocket_blackbox_shoot.wav"
new bool:g_wait[MAXPLAYERS + 1];
public Plugin myinfo =
{
name = "The Medic Rocket",
author = "PC Gamer",
description = "Shoots Rocket when you call for Medic",
version = "PLUGIN_VERSION 1.1",
url = "www.sourcemod.com"
}
public OnPluginStart()
{
AddNormalSoundHook(GamerSH);
}
public OnMapStart()
{
PrecacheSound(RSOUND, true);
}
public Action:GamerSH(clients[64], &numClients, String:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
{
if (!IsValidClient(entity)) return Plugin_Continue;
if (g_wait[entity] == true) return Plugin_Continue;
if (StrContains(sample, "_medic0", false) != -1)
{
sample = RSOUND;
decl Float:ang[3];
decl Float:pos[3];
GetClientEyePosition(entity, pos);
GetClientEyeAngles(entity, ang);
new RTeam = GetClientTeam(entity);
FireTeamRocket(pos, ang, entity, RTeam);
g_wait[entity] = true;
CreateTimer(0.1, Waiting, entity);
return Plugin_Changed;
}
return Plugin_Changed;
}
stock FireTeamRocket(Float:vPos[3], Float:vAng[3], iOwner = 0, iTeam = 0, Float:flSpeed = 1100.0, Float:flDamage = 90.0, bool:bCrit = false, iWeapon = -1)
{
new iRocket = CreateEntityByName("tf_projectile_rocket");
if (IsValidEntity(iRocket))
{
decl Float:vVel[3]; // Determine velocity based on given speed/angle
GetAngleVectors(vAng, vVel, NULL_VECTOR, NULL_VECTOR);
ScaleVector(vVel, flSpeed);
SetEntProp(iRocket, Prop_Send, "m_bCritical", bCrit);
SetRocketDamage(iRocket, flDamage);
SetEntProp(iRocket, Prop_Send, "m_nSkin", (0, iTeam - 2)); // 0 = RED 1 = BLU
SetEntProp(iRocket, Prop_Send, "m_iTeamNum", iTeam, 1);
SetVariantInt(iTeam);
AcceptEntityInput(iRocket, "TeamNum");
SetVariantInt(iTeam);
AcceptEntityInput(iRocket, "SetTeam");
if (iOwner != -1)
{
SetEntPropEnt(iRocket, Prop_Send, "m_hOwnerEntity", iOwner);
}
TeleportEntity(iRocket, vPos, vAng, vVel);
DispatchSpawn(iRocket);
if (iWeapon != -1)
{
SetEntPropEnt(iRocket, Prop_Send, "m_hOriginalLauncher", iWeapon); // GetEntPropEnt(baseRocket, Prop_Send, "m_hOriginalLauncher")
SetEntPropEnt(iRocket, Prop_Send, "m_hLauncher", iWeapon); // GetEntPropEnt(baseRocket, Prop_Send, "m_hLauncher")
}
return iRocket;
}
return -1;
}
static s_iRocketDmgOffset = -1;
stock SetRocketDamage(iRocket, Float:flDamage)
{
if (s_iRocketDmgOffset == -1)
{
s_iRocketDmgOffset = FindSendPropInfo("CTFProjectile_Rocket", "m_iDeflected") + 4; // Credit to voogru
}
SetEntDataFloat(iRocket, s_iRocketDmgOffset, flDamage, true);
}
stock Float:GetRocketDamage(iRocket)
{
if (s_iRocketDmgOffset == -1)
{
s_iRocketDmgOffset = FindSendPropOffs("CTFProjectile_Rocket", "m_iDeflected") + 4; // Credit to voogru
}
return GetEntDataFloat(iRocket, s_iRocketDmgOffset);
}
stock bool:IsValidClient(client)
{
if (client <= 0) return false;
if (client > MaxClients) return false;
return IsClientInGame(client);
}
public Action:Waiting(Handle:timer, any:client)
{
g_wait[client] = false;
}