So, a brief explanation to this code. I want to make it so that the Bushwacka will grant cloak while you're holding attack2, but after you stop holding attack2 you will bleed for however many seconds you held for. Now I got all of it to work except I could only make it work with a global variable, which obviously causes problems if multiple people are using the weapons ability. I haven't gotten any alternatives I could think of to work so I'd really appreciate any help with this.
PHP Code:
bool g_wait[MAXPLAYERS + 1];
float debt = 1.0;
public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon)
{
int iWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if(!IsValidEntity(iWeapon))
{
return;
}
int index = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
if(index == 232 && buttons & IN_ATTACK2 && g_wait[client] == false)
{
g_wait[client] = true;
CreateTimer(1.0, yourDebt, client, TIMER_REPEAT);
}
}
public Action yourDebt(Handle timer, int client)
{
if(IsClientInGame(client) && IsPlayerAlive(client))
{
int iWeapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if(!IsValidEntity(iWeapon))
{
g_wait[client] = false;
return Plugin_Stop;
}
int index = GetEntProp(iWeapon, Prop_Send, "m_iItemDefinitionIndex");
int buttons = GetClientButtons(client);
if(index == 232 && buttons & IN_ATTACK2 && debt != 15)
{
TF2_AddCondition(client, TFCond_Stealthed, 1.3);
if(debt < 10)
{
SetHudTextParams(-1.0, 0.75, 1.0, 0, 255, 0, 0);
ShowHudText(client, -1, "Blood debt: %i pints.", RoundFloat(debt));
}
if(debt >= 10 && debt != 14)
{
SetHudTextParams(-1.0, 0.75, 1.0, 255, 128, 0, 0);
ShowHudText(client, -1, "Blood debt: %i pints. The bushman is getting impatient.", RoundFloat(debt));
}
if(debt == 14)
{
SetHudTextParams(-1.0, 0.75, 1.0, 255, 0, 0, 0);
ShowHudText(client, -1, "Last chance mate!");
}
debt = debt + 1.0;
return Plugin_Continue;
}
else if (debt >= 15)
{
SDKHooks_TakeDamage(client, 0, 0, 450.0);
g_wait[client] = false;
SetHudTextParams(-1.0, 0.75, 1.0, 255, 0, 0, 0);
ShowHudText(client, -1, "G'day mate.");
debt = 1.0;
return Plugin_Stop;
}
else if (debt < 15)
{
TF2_MakeBleed(client, client, debt);
g_wait[client] = false;
debt = 1.0;
return Plugin_Stop;
}
else
{
g_wait[client] = false;
debt = 1.0;
return Plugin_Stop;
}
}
else
{
g_wait[client] = false;
debt = 1.0;
return Plugin_Stop;
}
}