Announcement

Collapse
No announcement yet.

Perfect autowall (penetration)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Perfect autowall (penetration)

    Code:
    void UTIL_TextureHit(Vector vecSrc, Vector vecEnd, Vector vecDir, int ignore, pmtrace_t &tr)
    {
        if (vecSrc[0] == vecEnd[0] && vecSrc[1] == vecEnd[1] && vecSrc[2] == vecEnd[2])
        {
            memset(&tr, NULL, sizeof(pmtrace_t));
    
            tr.endpos = vecEnd;
            tr.fraction = 1.0f;
            return;
        }
    
        g_Engine.pEventAPI->EV_SetTraceHull(2);
        g_Engine.pEventAPI->EV_PlayerTrace(vecSrc, vecEnd, PM_GLASS_IGNORE, ignore, &tr);
    
        if (tr.fraction == 0 && tr.startsolid && !tr.allsolid)
        {
            Vector vecTmp = vecSrc;
    
            while (!tr.allsolid && tr.fraction == 0.f)
            {
                vecTmp = vecTmp + vecDir;
    
                g_Engine.pEventAPI->EV_SetTraceHull(2);
                g_Engine.pEventAPI->EV_PlayerTrace(vecTmp, vecEnd, PM_WORLD_ONLY, ignore, &tr);
            }
    
            if (!tr.allsolid && tr.fraction != 1.0f)
            {
                vecTmp = vecEnd - vecSrc;
    
                float Length1 = vecTmp.Length();
    
                vecTmp = tr.endpos - vecSrc;
    
                float Length2 = vecTmp.Length();
    
                tr.fraction = Length1 / Length2;
                tr.startsolid = 1.0f;
            }
        }
    
        if (tr.allsolid)
            tr.fraction = 1.0f;
    }
    
    int CUtils::FireBullets(Vector start, Vector end, float flDistance, int iOriginalPenetration, int iBulletType, int iDamage, float flRangeModifier)
    {
        Vector vecSrc, vecEnd, vecDir, vecTmp;
        int iPenetration = iOriginalPenetration + 1;
        int iPenetrationPower;
        int iCurrentDamage = iDamage;
        float flPenetrationDistance;
        float flCurrentDistance;
    
        pmtrace_t tr;
        vecSrc = start;
        vecEnd = end;
    
        switch (iBulletType)
        {
        case BULLET_PLAYER_9MM:
            iPenetrationPower = 21;
            flPenetrationDistance = 800;
            break;
        case BULLET_PLAYER_45ACP:
            iPenetrationPower = 15;
            flPenetrationDistance = 500;
            break;
        case BULLET_PLAYER_50AE:
            iPenetrationPower = 30;
            flPenetrationDistance = 1000;
            break;
        case BULLET_PLAYER_762MM:
            iPenetrationPower = 39;
            flPenetrationDistance = 5000;
            break;
        case BULLET_PLAYER_556MM:
            iPenetrationPower = 35;
            flPenetrationDistance = 4000;
            break;
        case BULLET_PLAYER_338MAG:
            iPenetrationPower = 45;
            flPenetrationDistance = 8000;
            break;
        case BULLET_PLAYER_57MM:
            iPenetrationPower = 30;
            flPenetrationDistance = 2000;
            break;
        case BULLET_PLAYER_357SIG:
            iPenetrationPower = 25;
            flPenetrationDistance = 800;
            break;
        default:
            iPenetrationPower = 0;
            flPenetrationDistance = 0;
            break;
        }
    
        vecDir = vecEnd - vecSrc;
    
        float Length = vecDir.Length();
    
        vecDir /= Length;
    
        vecEnd = vecDir * flDistance + vecSrc;
    
        float flDamageModifier = 0.5;
    
        while (iPenetration)
        {
            UTIL_TextureHit(vecSrc, vecEnd, vecDir, -1, tr);
    
            char cTextureType = GetTextureType(&tr, vecSrc, vecEnd);
    
            switch (cTextureType)
            {
            case CHAR_TEX_CONCRETE:
                iPenetrationPower *= 0.25;
                break;
            case CHAR_TEX_GRATE:
                iPenetrationPower *= 0.5;
                flDamageModifier = 0.4;
                break;
            case CHAR_TEX_METAL:
                iPenetrationPower *= 0.15;
                flDamageModifier = 0.2;
                break;
            case CHAR_TEX_COMPUTER:
                iPenetrationPower *= 0.4;
                flDamageModifier = 0.45;
                break;
            case CHAR_TEX_TILE:
                iPenetrationPower *= 0.65;
                flDamageModifier = 0.3;
                break;
            case CHAR_TEX_VENT:
                iPenetrationPower *= 0.5;
                flDamageModifier = 0.45;
                break;
            case CHAR_TEX_WOOD:
                flDamageModifier = 0.6;
                break;
            default:
                break;
            }
    
            if (tr.fraction != 1.0)
            {
                iPenetration--;
    
                vecTmp = tr.endpos - start;
    
                float tmplen = vecTmp.Length();
    
                if (tmplen >= Length)
                {
                    vecTmp = end - vecSrc;
    
                    float Length1 = vecTmp.Length();
    
                    vecTmp = vecEnd - vecSrc;
    
                    float Length2 = vecTmp.Length();
    
                    tr.fraction = Length1 / Length2;
    
                    flCurrentDistance = flDistance * tr.fraction;
    
                    iCurrentDamage *= pow(flRangeModifier, flCurrentDistance / 500);
    
                    return iCurrentDamage;
                }
    
                flCurrentDistance = flDistance * tr.fraction;
    
                iCurrentDamage *= pow(flRangeModifier, flCurrentDistance / 500);
    
                if (flCurrentDistance > flPenetrationDistance)
                    iPenetration = 0;
    
                if (iPenetration)
                {
                    vecSrc = iPenetrationPower * vecDir + tr.endpos;
    
                    flDistance = (flDistance - flCurrentDistance) * 0.5;
    
                    vecEnd = vecDir * flDistance + vecSrc;
    
                    flCurrentDistance = iCurrentDamage;
    
                    iCurrentDamage = flCurrentDistance * flDamageModifier;
                }
                else
                {
                    vecSrc = 42 * vecDir + tr.endpos;
    
                    flDistance = (flDistance - flCurrentDistance) * 0.75;
    
                    vecEnd = vecDir * flDistance + vecSrc;
    
                    iCurrentDamage *= 0.75;
                }
            }
            else iPenetration = 0;
        }
        return 0;
    }
Working...
X