Raised This Month: $12 Target: $400
 3% 

Tank Damage Announce by griffin


Post New Thread Reply   
 
Thread Tools Display Modes
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 07-25-2012 , 17:06   Re: Tank Damage Announce by griffin
Reply With Quote #11

Quote:
Originally Posted by eric0279 View Post
Thanks shavit, I test the next tank.

edit : doesn't works :
Code:
PrintRemainingHealth()
{
        if (!g_bEnabled) 
            return;
        new tankclient = GetTankClient();
        if (!tankclient) return;
     
        decl String:name[MAX_NAME_LENGTH];
        if (IsFakeClient(tankclient)) name = "AI";
        else GetClientName(tankclient, name, sizeof(name));
        PrintToChatAll("[HP TANK] Il reste %d HP a (%N).", name, g_iLastTankHealth);
}
>> It gives a random number instead of the nickname, I think it gives the userid?

The number of remaining HP to tank is not correct when the survivors are all on land.
A tank has 6000 hp in versus mode.

Screenshot :
first


second (Works) :


could you tell me how to fix this?
PHP Code:
        PrintToChatAll("[HP TANK] Il reste %N HP a (%d)."nameg_iLastTankHealth); 
I meant that.
__________________
retired
shavit is offline
eric0279
AlliedModders Donor
Join Date: May 2007
Old 07-25-2012 , 17:36   Re: Tank Damage Announce by griffin
Reply With Quote #12

Quote:
L 07/25/2012 - 236:47: [SM] Displaying call stack trace for plugin "l4d2_tank_dmage.smx":
L 07/25/2012 - 236:47: [SM] [0] Line 293, F:\SRCDS\l4d2\left4dead2\left4dead2\addons\so urcemod\scripting\include\halflife.inc:rint ToChatAll()
L 07/25/2012 - 236:47: [SM] [1] Line 194, F:\SRCDS\l4d2\left4dead2\left4dead2\addons\so urcemod\scripting\l4d2_tank_dmage.sp:rintRe mainingHealth()
L 07/25/2012 - 236:47: [SM] [2] Line 153, F:\SRCDS\l4d2\left4dead2\left4dead2\addons\so urcemod\scripting\l4d2_tank_dmage.sp::Event_R oundEnd()
.sp :
Code:
#pragma semicolon 1
     
#include <sourcemod>

new     const           TEAM_SURVIVOR               = 2;
new     const           TEAM_INFECTED               = 3;
new     const           ZOMBIECLASS_TANK            = 8;                // Zombie class of the tank, used to find tank after he have been passed to another player
new             bool:   g_bEnabled                  = true;
new             bool:   g_bAnnounceTankDamage       = false;            // Whether or not tank damage should be announced
new             bool:   g_bIsTankInPlay             = false;            // Whether or not the tank is active
new                     g_iOffset_Incapacitated     = 0;                // Used to check if tank is dying
new                     g_iTankClient               = 0;                // Which client is currently playing as tank
new                     g_iLastTankHealth           = 0;                // Used to award the killing blow the exact right amount of damage
new                     g_iSurvivorLimit            = 4;                // For survivor array in damage print
new                     g_iDamage[MAXPLAYERS + 1];
new             Float:  g_fMaxTankHealth            = 6000.0;
new             Handle: g_hCvarEnabled              = INVALID_HANDLE;
new             Handle: g_hCvarTankHealth           = INVALID_HANDLE;
new             Handle: g_hCvarSurvivorLimit        = INVALID_HANDLE;
     
public Plugin:myinfo =
{
        name = "Tank Damage Announce L4D2",
        author = "Griffin and Blade",
        description = "Announce damage dealt to tanks by survivors",
        version = "0.6.5c"
};
     
public OnPluginStart()
{
        g_bIsTankInPlay = false;
        g_bAnnounceTankDamage = false;
        g_iTankClient = 0;
        ClearTankDamage();
        HookEvent("tank_spawn", Event_TankSpawn);
        HookEvent("player_death", Event_PlayerKilled);
        HookEvent("round_start", Event_RoundStart);
        HookEvent("round_end", Event_RoundEnd);
        HookEvent("player_hurt", Event_PlayerHurt);
     
        g_hCvarEnabled = CreateConVar("l4d_tankdamage_enabled", "1", "Announce damage done to tanks when enabled", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY, true, 0.0, true, 1.0);
        g_hCvarSurvivorLimit = FindConVar("survivor_limit");
        g_hCvarTankHealth = FindConVar("z_tank_health");
     
        HookConVarChange(g_hCvarEnabled, Cvar_Enabled);
        HookConVarChange(g_hCvarSurvivorLimit, Cvar_SurvivorLimit);
        HookConVarChange(g_hCvarTankHealth, Cvar_TankHealth);
     
        g_bEnabled = GetConVarBool(g_hCvarEnabled);
        CalculateTankHealth();
     
        g_iOffset_Incapacitated = FindSendPropInfo("Tank", "m_isIncapacitated");
}
     
public OnMapStart()
{
        // In cases where a tank spawns and map is changed manually, bypassing round end
        ClearTankDamage();
}
     
public OnClientDisconnect_Post(client)
{
        if (!g_bIsTankInPlay || client != g_iTankClient) return;
        CreateTimer(0.5, Timer_CheckTank, client); // Use a delayed timer due to bugs where the tank passes to another player
}
     
public Cvar_Enabled(Handle:convar, const String:oldValue[], const String:newValue[])
{
        g_bEnabled = StringToInt(newValue) > 0 ? true:false;
}
     
public Cvar_SurvivorLimit(Handle:convar, const String:oldValue[], const String:newValue[])
{
        g_iSurvivorLimit = StringToInt(newValue);
}
     
public Cvar_TankHealth(Handle:convar, const String:oldValue[], const String:newValue[])
{
        CalculateTankHealth();
}
     
CalculateTankHealth()
{
        g_fMaxTankHealth = GetConVarFloat(g_hCvarTankHealth);
        if (g_fMaxTankHealth <= 0.0) g_fMaxTankHealth = 1.0; // No dividing by 0!
}
     
public Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
        if (!g_bIsTankInPlay) return; // No tank in play; no damage to record
     
        new victim = GetClientOfUserId(GetEventInt(event, "userid"));
        if (victim != GetTankClient() ||        // Victim isn't tank; no damage to record
                IsTankDying()                                   // Something buggy happens when tank is dying with regards to damage
                                        ) return;
     
        new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
        // We only care about damage dealt by survivors, though it can be funny to see
        // claw/self inflicted hittable damage, so maybe in the future we'll do that
        if (attacker == 0 ||                                                    // Damage from world?
                !IsClientInGame(attacker) ||                            // Not sure if this happens
                GetClientTeam(attacker) != TEAM_SURVIVOR
                                        ) return;
     
        g_iDamage[attacker] += GetEventInt(event, "dmg_health");
        g_iLastTankHealth = GetEventInt(event, "health");
}
     
public Event_PlayerKilled(Handle:event, const String:name[], bool:dontBroadcast)
{
        if (!g_bIsTankInPlay) return; // No tank in play; no damage to record
     
        new victim = GetClientOfUserId(GetEventInt(event, "userid"));
        if (victim != g_iTankClient) return;
     
        // Award the killing blow's damage to the attacker; we don't award
        // damage from player_hurt after the tank has died/is dying
        // If we don't do it this way, we get wonky/inaccurate damage values
        new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
        if (attacker && IsClientInGame(attacker)) g_iDamage[attacker] += g_iLastTankHealth;
     
        // Damage announce could probably happen right here...
        CreateTimer(0.5, Timer_CheckTank, victim); // Use a delayed timer due to bugs where the tank passes to another player
}
     
public Event_TankSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
        new client = GetClientOfUserId(GetEventInt(event, "userid"));
        g_iTankClient = client;
     
        if (g_bIsTankInPlay) return; // Tank passed
     
        // New tank, damage has not been announced
        g_bAnnounceTankDamage = true;
        g_bIsTankInPlay = true;
        // Set health for damage print in case it doesn't get set by player_hurt (aka no one shoots the tank)
        g_iLastTankHealth = GetClientHealth(client);
}
     
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
        g_bIsTankInPlay = false;
        g_iTankClient = 0;
        ClearTankDamage(); // Probably redundant
}
     
// When survivors wipe or juke tank, announce damage
public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
        // But only if a tank that hasn't been killed exists
        if (g_bAnnounceTankDamage)
        {
                PrintRemainingHealth();
                PrintTankDamage();
        }
        ClearTankDamage();
}
     
public Action:Timer_CheckTank(Handle:timer, any:oldtankclient)
{
        if (g_iTankClient != oldtankclient) return; // Tank passed
     
        new tankclient = FindTankClient();
        if (tankclient && tankclient != oldtankclient)
        {
                g_iTankClient = tankclient;
     
                return; // Found tank, done
        }
     
        if (g_bAnnounceTankDamage) PrintTankDamage();
        ClearTankDamage();
        g_bIsTankInPlay = false; // No tank in play
}
     
bool:IsTankDying()
{
        new tankclient = GetTankClient();
        if (!tankclient) return false;
     
        return bool:GetEntData(tankclient, g_iOffset_Incapacitated);
}
     
PrintRemainingHealth()
{
        if (!g_bEnabled) 
            return;
        new tankclient = GetTankClient();
        if (!tankclient) return;
     
        decl String:name[MAX_NAME_LENGTH];
        if (IsFakeClient(tankclient)) name = "AI";
        else GetClientName(tankclient, name, sizeof(name));
        PrintToChatAll("[HP TANK] Il reste %N HP a (%d).", name, g_iLastTankHealth);
}
     
PrintTankDamage()
{
        if (!g_bEnabled) return;
        PrintToChatAll("[SM] Les dégâts infligés au Tank :");
     
        new client;
        new percent_total; // Accumulated total of calculated percents, for fudging out numbers at the end
        new damage_total; // Accumulated total damage dealt by survivors, to see if we need to fudge upwards to 100%
        new survivor_index = -1;
        new survivor_clients[g_iSurvivorLimit]; // Array to store survivor client indexes in, for the display iteration
        decl percent_damage, damage;
        for (client = 1; client <= MaxClients; client++)
        {
                if (!IsClientInGame(client) || GetClientTeam(client) != TEAM_SURVIVOR) continue;
                survivor_index++;
                survivor_clients[survivor_index] = client;
                damage = g_iDamage[client];
                damage_total += damage;
                percent_damage = GetDamageAsPercent(damage);
                percent_total += percent_damage;
        }
        SortCustom1D(survivor_clients, g_iSurvivorLimit, SortByDamageDesc);
     
        new percent_adjustment;
        // Percents add up to less than 100% AND > 99.5% damage was dealt to tank
        if ((percent_total < 100 &&
                float(damage_total) > (g_fMaxTankHealth - (g_fMaxTankHealth / 200.0)))
                )
        {
                percent_adjustment = 100 - percent_total;
        }
     
        new last_percent = 100; // Used to store the last percent in iteration to make sure an adjusted percent doesn't exceed the previous percent
        decl adjusted_percent_damage;
        for (new i; i <= survivor_index; i++)
        {
                client = survivor_clients[i];
                damage = g_iDamage[client];
                percent_damage = GetDamageAsPercent(damage);
                // Attempt to adjust the top damager's percent, defer adjustment to next player if it's an exact percent
                // e.g. 3000 damage on 6k health tank shouldn't be adjusted
                if (percent_adjustment != 0 && // Is there percent to adjust
                        damage > 0 &&  // Is damage dealt > 0%
                        !IsExactPercent(damage) // Percent representation is not exact, e.g. 3000 damage on 6k tank = 50%
                        )
                {
                        adjusted_percent_damage = percent_damage + percent_adjustment;
                        if (adjusted_percent_damage <= last_percent) // Make sure adjusted percent is not higher than previous percent, order must be maintained
                        {
                                percent_damage = adjusted_percent_damage;
                                percent_adjustment = 0;
                        }
                }
                PrintToChatAll("%4d HP (%d%%) : %N", damage, percent_damage, client);
        }
}
     
ClearTankDamage()
{
        g_iLastTankHealth = 0;
        for (new i = 1; i <= MaxClients; i++) { g_iDamage[i] = 0; }
        g_bAnnounceTankDamage = false;
}
     
     
GetTankClient()
{
        if (!g_bIsTankInPlay) return 0;
     
        new tankclient = g_iTankClient;
     
        if (!IsClientInGame(tankclient)) // If tank somehow is no longer in the game (kicked, hence events didn't fire)
        {
                tankclient = FindTankClient(); // find the tank client
                if (!tankclient) return 0;
                g_iTankClient = tankclient;
        }
     
        return tankclient;
}
     
FindTankClient()
{
        for (new client = 1; client <= MaxClients; client++)
        {
                if (!IsClientInGame(client) ||
                        GetClientTeam(client) != TEAM_INFECTED ||
                        !IsPlayerAlive(client) ||
                        GetEntProp(client, Prop_Send, "m_zombieClass") != ZOMBIECLASS_TANK)
                        continue;
     
                return client; // Found tank, return
        }
        return 0;
}
     
GetDamageAsPercent(damage)
{
        return RoundToFloor(FloatMul(FloatDiv(float(damage), g_fMaxTankHealth), 100.0));
}
     
bool:IsExactPercent(damage)
{
        return (FloatAbs(float(GetDamageAsPercent(damage)) - FloatMul(FloatDiv(float(damage), g_fMaxTankHealth), 100.0)) < 0.001) ? true:false;
}
     
public SortByDamageDesc(elem1, elem2, const array[], Handle:hndl)
{
        // By damage, then by client index, descending
        if (g_iDamage[elem1] > g_iDamage[elem2]) return -1;
        else if (g_iDamage[elem2] > g_iDamage[elem1]) return 1;
        else if (elem1 > elem2) return -1;
        else if (elem2 > elem1) return 1;
        return 0;
}
eric0279 is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 07-26-2012 , 14:48   Re: Tank Damage Announce by griffin
Reply With Quote #13

Quote:
Originally Posted by eric0279 View Post
.sp :
Code:
#pragma semicolon 1
     
#include <sourcemod>

new     const           TEAM_SURVIVOR               = 2;
new     const           TEAM_INFECTED               = 3;
new     const           ZOMBIECLASS_TANK            = 8;                // Zombie class of the tank, used to find tank after he have been passed to another player
new             bool:   g_bEnabled                  = true;
new             bool:   g_bAnnounceTankDamage       = false;            // Whether or not tank damage should be announced
new             bool:   g_bIsTankInPlay             = false;            // Whether or not the tank is active
new                     g_iOffset_Incapacitated     = 0;                // Used to check if tank is dying
new                     g_iTankClient               = 0;                // Which client is currently playing as tank
new                     g_iLastTankHealth           = 0;                // Used to award the killing blow the exact right amount of damage
new                     g_iSurvivorLimit            = 4;                // For survivor array in damage print
new                     g_iDamage[MAXPLAYERS + 1];
new             Float:  g_fMaxTankHealth            = 6000.0;
new             Handle: g_hCvarEnabled              = INVALID_HANDLE;
new             Handle: g_hCvarTankHealth           = INVALID_HANDLE;
new             Handle: g_hCvarSurvivorLimit        = INVALID_HANDLE;
     
public Plugin:myinfo =
{
        name = "Tank Damage Announce L4D2",
        author = "Griffin and Blade",
        description = "Announce damage dealt to tanks by survivors",
        version = "0.6.5c"
};
     
public OnPluginStart()
{
        g_bIsTankInPlay = false;
        g_bAnnounceTankDamage = false;
        g_iTankClient = 0;
        ClearTankDamage();
        HookEvent("tank_spawn", Event_TankSpawn);
        HookEvent("player_death", Event_PlayerKilled);
        HookEvent("round_start", Event_RoundStart);
        HookEvent("round_end", Event_RoundEnd);
        HookEvent("player_hurt", Event_PlayerHurt);
     
        g_hCvarEnabled = CreateConVar("l4d_tankdamage_enabled", "1", "Announce damage done to tanks when enabled", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY, true, 0.0, true, 1.0);
        g_hCvarSurvivorLimit = FindConVar("survivor_limit");
        g_hCvarTankHealth = FindConVar("z_tank_health");
     
        HookConVarChange(g_hCvarEnabled, Cvar_Enabled);
        HookConVarChange(g_hCvarSurvivorLimit, Cvar_SurvivorLimit);
        HookConVarChange(g_hCvarTankHealth, Cvar_TankHealth);
     
        g_bEnabled = GetConVarBool(g_hCvarEnabled);
        CalculateTankHealth();
     
        g_iOffset_Incapacitated = FindSendPropInfo("Tank", "m_isIncapacitated");
}
     
public OnMapStart()
{
        // In cases where a tank spawns and map is changed manually, bypassing round end
        ClearTankDamage();
}
     
public OnClientDisconnect_Post(client)
{
        if (!g_bIsTankInPlay || client != g_iTankClient) return;
        CreateTimer(0.5, Timer_CheckTank, client); // Use a delayed timer due to bugs where the tank passes to another player
}
     
public Cvar_Enabled(Handle:convar, const String:oldValue[], const String:newValue[])
{
        g_bEnabled = StringToInt(newValue) > 0 ? true:false;
}
     
public Cvar_SurvivorLimit(Handle:convar, const String:oldValue[], const String:newValue[])
{
        g_iSurvivorLimit = StringToInt(newValue);
}
     
public Cvar_TankHealth(Handle:convar, const String:oldValue[], const String:newValue[])
{
        CalculateTankHealth();
}
     
CalculateTankHealth()
{
        g_fMaxTankHealth = GetConVarFloat(g_hCvarTankHealth);
        if (g_fMaxTankHealth <= 0.0) g_fMaxTankHealth = 1.0; // No dividing by 0!
}
     
public Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
        if (!g_bIsTankInPlay) return; // No tank in play; no damage to record
     
        new victim = GetClientOfUserId(GetEventInt(event, "userid"));
        if (victim != GetTankClient() ||        // Victim isn't tank; no damage to record
                IsTankDying()                                   // Something buggy happens when tank is dying with regards to damage
                                        ) return;
     
        new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
        // We only care about damage dealt by survivors, though it can be funny to see
        // claw/self inflicted hittable damage, so maybe in the future we'll do that
        if (attacker == 0 ||                                                    // Damage from world?
                !IsClientInGame(attacker) ||                            // Not sure if this happens
                GetClientTeam(attacker) != TEAM_SURVIVOR
                                        ) return;
     
        g_iDamage[attacker] += GetEventInt(event, "dmg_health");
        g_iLastTankHealth = GetEventInt(event, "health");
}
     
public Event_PlayerKilled(Handle:event, const String:name[], bool:dontBroadcast)
{
        if (!g_bIsTankInPlay) return; // No tank in play; no damage to record
     
        new victim = GetClientOfUserId(GetEventInt(event, "userid"));
        if (victim != g_iTankClient) return;
     
        // Award the killing blow's damage to the attacker; we don't award
        // damage from player_hurt after the tank has died/is dying
        // If we don't do it this way, we get wonky/inaccurate damage values
        new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
        if (attacker && IsClientInGame(attacker)) g_iDamage[attacker] += g_iLastTankHealth;
     
        // Damage announce could probably happen right here...
        CreateTimer(0.5, Timer_CheckTank, victim); // Use a delayed timer due to bugs where the tank passes to another player
}
     
public Event_TankSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
        new client = GetClientOfUserId(GetEventInt(event, "userid"));
        g_iTankClient = client;
     
        if (g_bIsTankInPlay) return; // Tank passed
     
        // New tank, damage has not been announced
        g_bAnnounceTankDamage = true;
        g_bIsTankInPlay = true;
        // Set health for damage print in case it doesn't get set by player_hurt (aka no one shoots the tank)
        g_iLastTankHealth = GetClientHealth(client);
}
     
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
        g_bIsTankInPlay = false;
        g_iTankClient = 0;
        ClearTankDamage(); // Probably redundant
}
     
// When survivors wipe or juke tank, announce damage
public Event_RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
        // But only if a tank that hasn't been killed exists
        if (g_bAnnounceTankDamage)
        {
                PrintRemainingHealth();
                PrintTankDamage();
        }
        ClearTankDamage();
}
     
public Action:Timer_CheckTank(Handle:timer, any:oldtankclient)
{
        if (g_iTankClient != oldtankclient) return; // Tank passed
     
        new tankclient = FindTankClient();
        if (tankclient && tankclient != oldtankclient)
        {
                g_iTankClient = tankclient;
     
                return; // Found tank, done
        }
     
        if (g_bAnnounceTankDamage) PrintTankDamage();
        ClearTankDamage();
        g_bIsTankInPlay = false; // No tank in play
}
     
bool:IsTankDying()
{
        new tankclient = GetTankClient();
        if (!tankclient) return false;
     
        return bool:GetEntData(tankclient, g_iOffset_Incapacitated);
}
     
PrintRemainingHealth()
{
        if (!g_bEnabled) 
            return;
        new tankclient = GetTankClient();
        if (!tankclient) return;
     
        decl String:name[MAX_NAME_LENGTH];
        if (IsFakeClient(tankclient)) name = "AI";
        else GetClientName(tankclient, name, sizeof(name));
        PrintToChatAll("[HP TANK] Il reste %N HP a (%d).", name, g_iLastTankHealth);
}
     
PrintTankDamage()
{
        if (!g_bEnabled) return;
        PrintToChatAll("[SM] Les dégâts infligés au Tank :");
     
        new client;
        new percent_total; // Accumulated total of calculated percents, for fudging out numbers at the end
        new damage_total; // Accumulated total damage dealt by survivors, to see if we need to fudge upwards to 100%
        new survivor_index = -1;
        new survivor_clients[g_iSurvivorLimit]; // Array to store survivor client indexes in, for the display iteration
        decl percent_damage, damage;
        for (client = 1; client <= MaxClients; client++)
        {
                if (!IsClientInGame(client) || GetClientTeam(client) != TEAM_SURVIVOR) continue;
                survivor_index++;
                survivor_clients[survivor_index] = client;
                damage = g_iDamage[client];
                damage_total += damage;
                percent_damage = GetDamageAsPercent(damage);
                percent_total += percent_damage;
        }
        SortCustom1D(survivor_clients, g_iSurvivorLimit, SortByDamageDesc);
     
        new percent_adjustment;
        // Percents add up to less than 100% AND > 99.5% damage was dealt to tank
        if ((percent_total < 100 &&
                float(damage_total) > (g_fMaxTankHealth - (g_fMaxTankHealth / 200.0)))
                )
        {
                percent_adjustment = 100 - percent_total;
        }
     
        new last_percent = 100; // Used to store the last percent in iteration to make sure an adjusted percent doesn't exceed the previous percent
        decl adjusted_percent_damage;
        for (new i; i <= survivor_index; i++)
        {
                client = survivor_clients[i];
                damage = g_iDamage[client];
                percent_damage = GetDamageAsPercent(damage);
                // Attempt to adjust the top damager's percent, defer adjustment to next player if it's an exact percent
                // e.g. 3000 damage on 6k health tank shouldn't be adjusted
                if (percent_adjustment != 0 && // Is there percent to adjust
                        damage > 0 &&  // Is damage dealt > 0%
                        !IsExactPercent(damage) // Percent representation is not exact, e.g. 3000 damage on 6k tank = 50%
                        )
                {
                        adjusted_percent_damage = percent_damage + percent_adjustment;
                        if (adjusted_percent_damage <= last_percent) // Make sure adjusted percent is not higher than previous percent, order must be maintained
                        {
                                percent_damage = adjusted_percent_damage;
                                percent_adjustment = 0;
                        }
                }
                PrintToChatAll("%4d HP (%d%%) : %N", damage, percent_damage, client);
        }
}
     
ClearTankDamage()
{
        g_iLastTankHealth = 0;
        for (new i = 1; i <= MaxClients; i++) { g_iDamage[i] = 0; }
        g_bAnnounceTankDamage = false;
}
     
     
GetTankClient()
{
        if (!g_bIsTankInPlay) return 0;
     
        new tankclient = g_iTankClient;
     
        if (!IsClientInGame(tankclient)) // If tank somehow is no longer in the game (kicked, hence events didn't fire)
        {
                tankclient = FindTankClient(); // find the tank client
                if (!tankclient) return 0;
                g_iTankClient = tankclient;
        }
     
        return tankclient;
}
     
FindTankClient()
{
        for (new client = 1; client <= MaxClients; client++)
        {
                if (!IsClientInGame(client) ||
                        GetClientTeam(client) != TEAM_INFECTED ||
                        !IsPlayerAlive(client) ||
                        GetEntProp(client, Prop_Send, "m_zombieClass") != ZOMBIECLASS_TANK)
                        continue;
     
                return client; // Found tank, return
        }
        return 0;
}
     
GetDamageAsPercent(damage)
{
        return RoundToFloor(FloatMul(FloatDiv(float(damage), g_fMaxTankHealth), 100.0));
}
     
bool:IsExactPercent(damage)
{
        return (FloatAbs(float(GetDamageAsPercent(damage)) - FloatMul(FloatDiv(float(damage), g_fMaxTankHealth), 100.0)) < 0.001) ? true:false;
}
     
public SortByDamageDesc(elem1, elem2, const array[], Handle:hndl)
{
        // By damage, then by client index, descending
        if (g_iDamage[elem1] > g_iDamage[elem2]) return -1;
        else if (g_iDamage[elem2] > g_iDamage[elem1]) return 1;
        else if (elem1 > elem2) return -1;
        else if (elem2 > elem1) return 1;
        return 0;
}
Tested it on my server and it worked without any error o,o just weird language.
I think you don't know how to compile.
__________________
retired
shavit is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 07-26-2012 , 15:46   Re: Tank Damage Announce by griffin
Reply With Quote #14

Shavit,your edit is wrong and is what gives him the errors. %N is used only to retrive the name from the client index without declaring any strings.
%s is used to retrive the name from a string, in this case from decl String:name[MAX_NAME_LENGTH]; and GetClientName(tankclient, name, sizeof(name));

PHP Code:
PrintToChatAll("[HP TANK] Il reste %N HP a (%d)."nameg_iLastTankHealth); 
should be
PHP Code:
PrintToChatAll("[HP TANK] Il reste %s HP a (%d)."nameg_iLastTankHealth); 
TheTwistedPanda also showed a better, example on page 1 which I'd recommend using instead.
https://forums.alliedmods.net/showpost.php?p=1757501&postcount=9

Last edited by Visual77; 07-26-2012 at 16:02.
Visual77 is offline
eric0279
AlliedModders Donor
Join Date: May 2007
Old 07-26-2012 , 18:10   Re: Tank Damage Announce by griffin
Reply With Quote #15

I use sourcemod compiler for Windows :
Quote:
//SourceMod Batch Compiler
// by the SourceMod Dev Team


//// l4d2_tank_dmage.sp
// Header size: 2880 bytes
// Code size: 6324 bytes
// Data size: 1008 bytes
// Stack/heap size: 16384 bytes; Total requirements: 26596 bytes
//
// Compilation Time: 0,33 sec
// ----------------------------------------

Press enter to exit ...
@Visual77, if :
Code:
PrintToChatAll("[HP TANK] Il reste %d HP a (%s).", name, g_iLastTankHealth);
it's not correct (HP remaining and name of player is not correct !)

if :
Code:
PrintToChatAll("[HP TANK] Il reste %s HP a (%d).", name, g_iLastTankHealth);
Values ​​are correct but reversed, in play, we get:
Quote:
Il reste name_player HP a (HP of Tank)
Fixed to :
Code:
PrintToChatAll("[HP TANK] Le Tank (%s) a encore %s HP.", name, g_iLastTankHealth);
compared to the English text, this is not right once but it translate agree.

You're it possible to move the entire text (PrintTankDamage) on the left of the screen ?

because the images of the scoreboard or else from seeing properly.

Last edited by eric0279; 07-26-2012 at 18:18.
eric0279 is offline
Visual77
Veteran Member
Join Date: Jan 2009
Old 07-26-2012 , 19:58   Re: Tank Damage Announce by griffin
Reply With Quote #16

Quote:
Originally Posted by eric0279 View Post
I use sourcemod compiler for Windows :
@Visual77, if :
Code:
PrintToChatAll("[HP TANK] Il reste %d HP a (%s).", name,  g_iLastTankHealth);
it's not correct (HP remaining and name of player is not correct !)

First of all I didn't tell you to use that. I told you to use:
Code:
PrintToChatAll("[HP TANK] Il reste %s HP a (%d).", name, g_iLastTankHealth);
Which prints the name of the player followed by the health of the tank. If you want the health first, followed by the name of the player, then it should be:
Code:
PrintToChatAll("[HP TANK] Il reste %d HP a (%s).", g_iLastTankHealth, name);

Last edited by Visual77; 07-26-2012 at 20:16.
Visual77 is offline
eric0279
AlliedModders Donor
Join Date: May 2007
Old 07-26-2012 , 22:20   Re: Tank Damage Announce by griffin
Reply With Quote #17

Quote:
First of all I didn't tell you to use that. I told you to use:
yes, sorry

Quote:
Which prints the name of the player followed by the health of the tank. If you want the health first, followed by the name of the player, then it should be:
Thanks ! <3

and for my request :
Quote:
You're it possible to move the entire text (PrintTankDamage) on the left of the screen ?

because the images of the scoreboard or else from seeing properly.
It's not possible?
eric0279 is offline
Griffin
New Member
Join Date: Jun 2011
Old 07-30-2012 , 10:41   Re: Tank Damage Announce by griffin
Reply With Quote #18

Quote:
Originally Posted by Mr. Zero View Post
Looks like its based somewhat of my old Rotoblin code. I would try increase the timer if it prints to chat upon tank being passed.

Replace all
CreateTimer(0.1, Timer_CheckTank
with
CreateTimer(0.5, Timer_CheckTank
For the record, it is completely based on the rotoblin tank manager. The original source that I distributed included the comment:

Quote:
Basically roto's tank manager with damage tracking tacked on
Someone must have removed it somewhere down the line. Credit for all of that is all yours, Mr. Zero.

P.S. Did this solution work? I'm assuming this bug is related to the tank control plugin in promod?
Griffin is offline
eric0279
AlliedModders Donor
Join Date: May 2007
Old 08-01-2012 , 01:21   Re: Tank Damage Announce by griffin
Reply With Quote #19

Hello,

added after #include <sourcemod> :
Code:
#include <colors>
(latest version)

Code:
PrintRemainingHealth()
{
        if (!g_bEnabled) 
            return;
        new tankclient = GetTankClient();
        if (!tankclient) return;
     
        decl String:name[MAX_NAME_LENGTH];
        if (IsFakeClient(tankclient)) name = "AI";
        else GetClientName(tankclient, name, sizeof(name));
        /*PrintToChatAll("[HP TANK] Il reste %d\x01 HP a (%s).", g_iLastTankHealth, name);*/
        CPrintToChatAll("{green}[{default}HP TANK{green}]{lightgreen} Il reste {default}%d HP a {green}({default}%s{green}){default}.", g_iLastTankHealth, name);
}
doesn't works but why ?

Last edited by eric0279; 08-02-2012 at 14:01. Reason: Solved
eric0279 is offline
eric0279
AlliedModders Donor
Join Date: May 2007
Old 09-01-2012 , 12:15   Re: Tank Damage Announce by griffin
Reply With Quote #20

Hello,

for those who are interested, I added the ability to translate the phrases in the language desired.
I hope this will be appreciated.

Last edited by eric0279; 09-06-2012 at 00:31. Reason: Link to download : removed 0 Downloads
eric0279 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:31.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode