View Single Post
Mr. Zero
Veteran Member
Join Date: Jun 2009
Location: Denmark
Old 11-23-2018 , 05:00   Re: [L4D] How to count the distance in map route?
Reply With Quote #2

The map distance concept within L4D is called "Map Flow". The Director uses it to figure out how far the Survivors have progressed and when to spawn Bosses (Tank and Witch).

ProdigySim made some very nice stocks for this some years back.

https://forums.alliedmods.net/showthread.php?t=180028

The specific function you are looking for is called:

PHP Code:
stock float L4D2Direct_GetMapMaxFlowDistance(); 
This function returns map length, A to B in Survivor movement, in hammer units. An example would be No Mercy map 1 is 8000 units.

Then you can use
PHP Code:
stock float L4D2Direct_GetFlowDistance(int Client); 
to get the Survivors individual flow count. Might return something like
PHP Code:
4000.0 
That means the Survivor is half way through the map.

Beaware, sometimes the Survivor can not be pinpointed or get outside of the flow of the map (map exploits or whatever). Which can make the return flow value be weird (honestly it may return any value, the Director attempts to guess where the Survivor may be). Personally I find using a delta timer function with a median value (just store the last three flow values of the Survivor and get the median value) to work well against this problem.

Furthermore if Survivors can move in the opposite direction of the checkpoint safe room from their starting location (in other words, they can move backwards which puts them further away from the checkpoint), the flow value can reach negative values. It doesn't mean it is invalid, it just means Survivors are getting further away from the checkpoint.
The map max flow distance is counted from starting checkpoint to end checkpoint, but it doesn't mean a Survivor can move behind or past the checkpoints (so Survivors can reach higher flow values than the map max flow distance returns and they can reach negative values as well). Be sure to validate your inputs!

And lastly, areas only Infected are suppose to reach returns the following value for Survivors; (Areas marked as INFECTED_ONLY with the Nav Editor)
PHP Code:
#define FLOW_VALUE_INFECTED_ONLY_AREA -9999.000000 
Oh and here is a small stock function to return flow from a point without a client:
PHP Code:
stock bool GetFlowFromPoint(float point[3], &float flow)
{
    
Address terrorNavPointer L4D2Direct_GetTerrorNavArea(point);
    if (
terrorNavPointer == Address_Null)
    {
        return 
false;
    }
    
    
flow L4D2Direct_GetTerrorNavAreaFlow(terrorNavPointer);
    return 
true;

I hope it could be of some use
Mr. Zero is offline