Raised This Month: $ Target: $400
 0% 

[TF2] Get map type without relying on map name


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-20-2013 , 16:23   [TF2] Get map type without relying on map name
Reply With Quote #1

So, I wrote a little snippet that lets you find out what game type the current map is even if it has been renamed to something else.

This also has info on how to determine which type of CP map you're on.

PHP Code:
#include <sdktools>

// These correspond to tf_gamerules m_nGameType netprop
enum
{
    
TF2_GameType_Unknown,
    
TF2_GameType_CTF 1,
    
TF2_GameType_CP 2,
    
TF2_GameType_PL 3,
    
TF2_GameType_Arena 4,
}

enum TF2_GameMode
{
    
TF2_GameMode_Unknown,
    
TF2_GameMode_CTF,
    
TF2_GameMode_5CP,
    
TF2_GameMode_PL,
    
TF2_GameMode_Arena,
    
TF2_GameMode_ADCP,
    
TF2_GameMode_TC,
    
TF2_GameMode_PLR,
    
TF2_GameMode_KOTH,
    
TF2_GameMode_SD,
    
TF2_GameMode_MvM,
    
TF2_GameMode_Training,
    
TF2_GameMode_ItemTest,
}

stock TF2_GameMode:TF2_DetectGameMode()
{
    
    
// If we can get the map type through netprops, do so.
    
if (GameRules_GetProp("m_bIsInTraining"))
    {
        return 
TF2_GameMode_Training;
    }

    if (
GameRules_GetProp("m_bIsInItemTestingMode"))
    {
        return 
TF2_GameMode_ItemTest;
    }
    
    if (
GameRules_GetProp("m_bPlayingSpecialDeliveryMode"))
    {
        return 
TF2_GameMode_SD;
    }
    
    if (
GameRules_GetProp("m_bPlayingMannVsMachine"))
    {
        return 
TF2_GameMode_MvM;
    }
    
    if (
GameRules_GetProp("m_bPlayingKoth"))
    {
        return 
TF2_GameMode_KOTH;
    }

    
// Netprops didn't help, lets check the game type
    
new gameType GameRules_GetProp("m_nGameType");
    
    switch (
gameType)
    {
        case 
TF2_GameType_CTF:
        {
            return 
TF2_GameMode_CTF;
        }
        
        
// 5cp, a/d cp, and tc all show up as this game type
        // koth and mvm  too, but we already filtered those
        
case TF2_GameType_CP:
        {
            
// Check for multi-stage maps first.
            
new roundCount 0;
            new 
roundCP = -1;
            new 
priority = -1;
            
            new 
restrictWinner = -1;
            new 
restrictCount 0;
            
            while ((
roundCP FindEntityByClassname(roundCP"team_control_point_round")) != -1)
            {
                
roundCount++;
                
                
restrictWinner GetEntProp(roundCPProp_Data"m_iInvalidCapWinner");
                if (
restrictWinner 1)
                {
                    
restrictCount++;
                }
                
                new 
newPriority GetEntProp(roundCPProp_Data"m_nPriority");
                if (
newPriority priority)
                {
                    
priority newPriority;
                }
                else if (
newPriority == priority)
                {
                    
// Only TC maps have multiple rounds with the same priority, and it's the highest priority
                    // Sadly, this will fail to detect push/pull TC maps
                    
return TF2_GameMode_TC;
                }
            }
            
            
// All rounds have a winner restriction, so it must be a A/D cp map
            
if (roundCount && roundCount == restrictCount)
            {
                return 
TF2_GameMode_ADCP;
            }
            else if (
roundCount 1)
            {
                
// We had multiple rounds, but not all of them were restricted...
                // must be a push/pull TC map
                
return TF2_GameMode_TC;
            }
            
            
// Now for single round maps... same check on control point master
            
new masterCP FindEntityByClassname(-1"team_control_point_master");
            
            if (
masterCP > -1)
            {
                
restrictWinner GetEntProp(masterCPProp_Data"m_iInvalidCapWinner");
                
// Single round restricted are always A/D (gorge, gravelpit)
                
if (restrictWinner 1)
                {
                    return 
TF2_GameMode_ADCP;
                }
            }
            
            return 
TF2_GameMode_5CP;
        }
        
        
// pl and plr both show up as this game type
        
case TF2_GameType_PL:
        {
            
// All plr maps have this entity
            
if (FindEntityByClassname(-1"tf_logic_multiple_escort") > -1)
            {
                return 
TF2_GameMode_PLR;
            }
            
            return 
TF2_GameMode_PL;
        }
        
        case 
TF2_GameType_Arena:
        {
            return 
TF2_GameMode_Arena;
        }
    }
    return 
TF2_GameMode_Unknown;

Note: I haven't tested it on a hybrid CTF/CP map, but I assume it will be detected by its game type, CTF.

I wrote this code as part of a detection script for what control points are currently active, but that's not done yet.
Attached Files
File Type: inc controlpoints.inc (3.4 KB, 379 views)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 09-20-2013 at 16:31.
Powerlord is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:33.


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