How can I change the target of the tank when the survivor is incapacitated?
this is a bit of my code
PHP Code:
public void OnPluginStart()
{
l4d_chance_attacknext = CreateConVar("l4d_chance_attacknext", "100.0", "chance of continue attack [0.0, 100.0]" );
l4d_change_target = CreateConVar("l4d_change_target", "1", "0 = change target, 1 = change target");
l4d_range_attack = CreateConVar("l4d_range_attack", "400.0", "attack range");
HookEvent("player_incapacitated", eIncap);
}
public Action eIncap(Event event, const char[] name, bool dontBroadcast)
{
int userid = event.GetInt("userid");
int victim = GetClientOfUserId(userid);
int tank = event.GetInt("attackerentid");
if( victim > 0 && tank > 0)
{
if(IsClientInGame(victim) && GetClientTeam(victim)==2)
{
StartAttack(tank, victim);
}
}
return Plugin_Continue;
}
void StartAttack(int tank, int victim)
{
if(IsTank(tank) && GetRandomFloat(0.0, 100.0) < l4d_chance_attacknext.FloatValue)
{
OnStart(tank, victim);
}
}
void OnStart(int ent, int victim)
{
if(IsTank(ent))
{
GetEntPropVector(ent, Prop_Send, "m_vecOrigin", fPos);
if(GetConVarInt(l4d_change_target)==1) NextVictim = GetVictim( victim, fPos );
else if(IsPlayerIncapped(victim))
{
NextVictim = victim;
}
if( NextVictim > 0 )
{
PrintToChatAll("next target is %N", NextVictim);
}
}
}
int GetVictim(int except, float Tpos[3])
{
float minDis = l4d_range_attack.FloatValue;
float ePos[3];
int selected = 0;
for( int i = 1; i <= MaxClients; i++)
{
if( IsClientInGame(i) && GetClientTeam(i)==2 && IsPlayerAlive(i) && i!=except && !IsPlayerIncapped(i) )
{
GetClientAbsOrigin(i, ePos);
float dis = GetVectorDistance(ePos, Tpos);
if( dis <= minDis )
{
selected = i;
minDis = dis;
}
}
}
return selected;
}
bool IsPlayerIncapped(int client)
{
if( client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && IsPlayerAlive(client) )
{
if (GetEntProp(client, Prop_Send, "m_isIncapacitated", 1))
return true;
}
return false;
}
bool IsTank(int client)
{
if( client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3 )
{
int class = GetEntProp(client, Prop_Send, "m_zombieClass");
if( class == 5 )
return true;
}
return false;
}