Hack Forums
[C] Better way to calculate percent for chicken settings? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Better way to calculate percent for chicken settings? (/showthread.php?tid=3433589)



Better way to calculate percent for chicken settings? - RHurford89 - Apr 24, 2013

better way to calculate percent for my chicken settings?

Struct

Code
BYTE CalcPercent(DWORD dwVal, DWORD dwMaxVal, BYTE iMin)
{
    if (dwVal == 0 || dwMaxVal == 0)
        return NULL;

    BYTE iRes = (BYTE)((double)dwVal / (double)dwMaxVal * 100.0);

    if (iRes > 100)
        iRes = 100;

    return max(iRes, iMin);
}

Chicken.cpp

Code
BOOL TriggerTown()
{
    if (!ClientReady(TRUE))
        return FALSE;

    DOUBLE LifePercent = CalcPercent((GetUnitStat(Me, STAT_HP) >> 12), (GetUnitStat(Me, STAT_MAXHP) >> 12));
    DOUBLE ManaPercent = CalcPercent((GetUnitStat(Me, STAT_MANA) >> 8), (GetUnitStat(Me, STAT_MAXMANA) >> 8));

    if (!V_DelayedChicken && !InTown(Me) && !GetUnitState(Me, AFFECT_WHIRLWIND))
    {
        if (V_HiddenValues == TRUE)
        {
            if (V_LifeTownPercent > 0 && LifePercent <= V_LifeTownPercent + 10)
                Town();

            return FALSE;
        }

    {
        if (V_HiddenValues == FALSE)
        {
            if (V_LifeTownPercent > 0 && LifePercent <= V_LifeTownPercent)
                Town();

            return FALSE;
        }
    }
}
    return TRUE;
}



* - Krofnica - Apr 24, 2013

How the hell are we supposed to know why are you shifting those bits in TriggerTown()? And not to mention number of parameters doesn't match!

Try this:
Spoiler (Click to View)


* - RHurford89 - Apr 24, 2013

sorry i was testing a few things and i forgot to switch that one back over.