SirPlease / L4D2-Competitive-Rework

Just refreshing and optimizing the core files a bit, eh?
GNU General Public License v3.0
241 stars 128 forks source link

[SUG] Detect saferooms with Nav methods instead of manual info #553

Open jensewe opened 1 year ago

jensewe commented 1 year ago
#define DOOR_RANGE_TOLLERANCE 2000.0

bool IsEntityInSaferoom(int entity, bool bStartSaferoom)
{
    float vecPos[3];
    GetEntPropVector(entity, Prop_Data, "m_vecAbsOrigin", vecPos);

    Address nav = L4D_GetNearestNavArea(vecPos);
    if (nav != Address_Null)
    {
        int spawnAttributes = L4D_GetNavArea_SpawnAttributes(nav);
        if (spawnAttributes & NAV_SPAWN_CHECKPOINT)
        {
            return bStartSaferoom != L4D2Direct_GetTerrorNavAreaFlow(nav) > DOOR_RANGE_TOLLERANCE;
        }
    }

    return false;
}

Latest Left 4 DHooks introduces more nav stuff and spawn attributes become available, pretty clean in use. Pratically this was used in one of my plugin l4d2_spit_spread_patch and worked without issues.

Related plugin sources: https://github.com/SirPlease/L4D2-Competitive-Rework/blob/5f553acbdfc6a906e88541a0a7d0ab2b11eb8ead/addons/sourcemod/scripting/l4d2_saferoom_detect.sp#L160-L345 https://github.com/SirPlease/L4D2-Competitive-Rework/blob/14e26036d158192fb6f2163c3ceb2dd0c4e6c51e/addons/sourcemod/scripting/confoglcompmod/MapInfo.sp#L339-L356 https://github.com/SirPlease/L4D2-Competitive-Rework/blob/c048ca752681436804403dff79ac06016fbe279b/addons/sourcemod/scripting/l4d2lib/mapinfo.sp#L314-L339 https://github.com/SirPlease/L4D2-Competitive-Rework/blob/14e26036d158192fb6f2163c3ceb2dd0c4e6c51e/addons/sourcemod/scripting/confoglcompmod/WeaponInformation.sp#L1035-L1050 https://github.com/SirPlease/L4D2-Competitive-Rework/blob/14e26036d158192fb6f2163c3ceb2dd0c4e6c51e/addons/sourcemod/scripting/confoglcompmod/WeaponInformation.sp#L894-L918 https://github.com/SirPlease/L4D2-Competitive-Rework/blob/c0e5ae938df88614f41d15592a5b7c4685bb6e43/addons/sourcemod/scripting/nosaferoomkits.sp#L44-L72

A1mDev commented 1 year ago

DOOR_RANGE_TOLLERANCE? Something is confusing me with this code.

jensewe commented 1 year ago

DOOR_RANGE_TOLLERANCE? Something is confusing me with this code.

Stolen from Silvers' left4dhooks, looks reliable. Not really matters or instead convert into flow percent like this: https://developer.valvesoftware.com/wiki/L4D2_Vscript_Helpers

ProjectSky commented 1 year ago

some maps like blood harvest & the passing finale have spawn attributes inside a finale marked area

A1mDev commented 1 year ago

For players it would be more correct to use GetLastKnowArea.