AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   General (https://forums.alliedmods.net/forumdisplay.php?f=58)
-   -   Solved [L4D2] CoOp: Determine non-finale map success/fail (https://forums.alliedmods.net/showthread.php?t=346464)

Mystik Spiral 02-26-2024 16:42

[L4D2] CoOp: Determine non-finale map success/fail
 
For finale maps, there is a finale_win (and mission_lost) event that can be checked to determine finale success.

There does not appear to be a map_win event (which I define as at least one survivor successfully made it to the checkpoint, closed the door, and triggered a changelevel to the next map in the campaign).

I thought at first that if OnMapEnd was reached it would be a success (because if mission_lost is triggered, OnMapEnd will not trigger), but that only works most of the time. There are at least two scenarios I can think of that cause problems... OnMapEnd is triggered when a new lobby connects, and OnMapEnd is triggered when a vote passes to change to a new map/campaign. It is also possible that lobby/vote connections go directly to any map in the campaign.

In either round_start or OnMapStart I want to determine if the previous map was a success, or if we got here from a new lobby connect, map vote change, or anything else that might changelevel without a map_win.

I am thinking when the ending checkpoint door is closed I may have to determine if all alive survivors are in the ending checkpoint and set an appropriate global variable to indicate a map_win, then check the value of that variable in round_start and/or OnMapStart.

Any better ideas?

Mystik Spiral 02-26-2024 21:56

Re: [L4D2] CoOp: Determine non-finale map success/fail
 
In case anyone is interested, I effectively created my own map_win event by piggy-backing off of the door_close event (requires left4dhooks):

PHP Code:

public void Event_DoorClose(Event eventchar[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    
bool bCPdoor = (GetEventBool(event"checkpoint"));
    if (
bCPdoor && L4D_IsInLastCheckpoint(client))
    {
        
g_bMapWin true;
        for (
int i 1<= MaxClientsi++)
        {
            if (
IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == SURVIVOR_TEAM && !L4D_IsInLastCheckpoint(i))
            {
                
g_bMapWin false;
                break;
            }
        }
        if (
g_bMapWin)
        {
            
//stuff
        
}
    }


I am sure that can be refined but it resolves the issue for me.

BRU7US 02-28-2024 18:29

Re: [L4D2] CoOp: Determine non-finale map success/fail
 
Use "map_transition" event to determine boolean variable as true. Then check this variable on forward "OnMapStart" to check previous map change type. You only need to define the correct event at which the boolean variable gets the value false, so that you can correctly distinguish when the map was changed as a result of victory or as a result of other operations

Mystik Spiral 02-28-2024 19:59

Re: [L4D2] CoOp: Determine non-finale map success/fail
 
Note that I am trying to determine the success of the previous map, like a changelevel from map 3 to map 4 of a 5 map campaign, not the success of the previous campaign. This is important because I am manipulating entities in the ending checkpoint that affect the starting checkpoint in the next map. What I have works great and my tests have not revealed any problems.

I will (eventually) investigate when "map_transition" fires. I thought it would only fire for the first map of a campaign during the fly-by intro and for the last map of a campaign for the escape, but maybe it fires at the end of every map.

Thanks for the feedback!

BRU7US 03-01-2024 17:38

Re: [L4D2] CoOp: Determine non-finale map success/fail
 
"map_transition" fires every time your team successfully completes a map (not campaign)

Mystik Spiral 03-01-2024 18:08

Re: [L4D2] CoOp: Determine non-finale map success/fail
 
Thanks @BRU7US!

I will probably switch to using that then since I have discovered a rare issue... if the last bot into the checkpoint warps in while the door is closed, g_bMapWin will not get set.

Mystik Spiral 03-01-2024 21:36

Re: [L4D2] CoOp: Determine non-finale map success/fail
 
I am now using map_transition. It is simpler and works better. Thanks again @BRU7US!

BRU7US 03-02-2024 03:45

Re: [L4D2] CoOp: Determine non-finale map success/fail
 
Quote:

Originally Posted by Mystik Spiral (Post 2818880)
I am now using map_transition. It is simpler and works better. Thanks again @BRU7US!

You are welcome!


All times are GMT -4. The time now is 14:41.

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