Raised This Month: $51 Target: $400
 12% 

[L4D2] How to detect first chapter?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 08-05-2018 , 14:57   [L4D2] How to detect first chapter?
Reply With Quote #1

How do we detect the first chapter of a map? Without hard coding map names like every plugin seems to do. I'm trying to avoid the SDKCall method.

I want to reset a variable when people leave half-way through a campaign, more simply on first chapter of a new campaign.
__________________
Silvers is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 08-05-2018 , 15:29   Re: [L4D2] How to detect first chapter?
Reply With Quote #2

You could try that method we talked about the other morning: Reading the mission files.

I would just get the map name, use the KeyValues system to read the mission files, find which file contains that map name, then read the "modes/coop/1" subsection, then check the "Map" key and its value for that.

Layout of every mission file:

PHP Code:
"mission"
{
     
"modes"
     
{
          
"coop"
          
{
               
"1"
               
{
                    
"Map" "c1m1_hotel"
                    
// Other stuff below
               
}
          }
     }

It's very tedious though. I wish there was a string table for the maps like they have for the melee weapons.
__________________
Psyk0tik is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 08-05-2018 , 16:55   Re: [L4D2] How to detect first chapter?
Reply With Quote #3

PHP Code:
stock bool:IsFinalMap()
{
    return (
FindEntityByClassname(-1"info_changelevel") == -1
            
&& FindEntityByClassname(-1"trigger_changelevel") == -1);
}

stock bool:IsStartOrEndMap()
{
    new 
iCount;
    new 
= -1;
    while((
FindEntityByClassname(i"info_landmark")) != -1) {
        
iCount++;
    }
    
    return (
iCount == 1);

Or just check for the intro entity, but its not required so idk if it works with 3th party maps that dont even have a intro.

use like this:
PHP Code:
if(IsStartOrEndMap() && !IsFinalMap())
{
      
//First chapter


Last edited by Timocop; 08-05-2018 at 17:00.
Timocop is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 08-05-2018 , 17:32   Re: [L4D2] How to detect first chapter?
Reply With Quote #4

Yeah something to support all 3rd party too. Thanks for the info so far.
__________________
Silvers is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 08-06-2018 , 11:39   Re: [L4D2] How to detect first chapter?
Reply With Quote #5

I believe player_entered_start_area or player_left_start_area events will work with a little finesse. These 2 events are only ever called on the first map of a campaign, not 100% sure though. Only problem is they will get repeatedly called if players enter or leave the start area over n over. Im sure u could work around that though. I would just use Timo's method to be honest though.

Last edited by MasterMind420; 08-06-2018 at 11:43.
MasterMind420 is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-06-2018 , 12:08   Re: [L4D2] How to detect first chapter?
Reply With Quote #6

What would be the reason to not use SDK call method?
__________________
Spirit_12 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 08-06-2018 , 12:49   Re: [L4D2] How to detect first chapter?
Reply With Quote #7

@MasterMind420 Thanks, I believe these get called for saferooms on 2nd map too etc. I could try.

Quote:
Originally Posted by Spirit_12 View Post
What would be the reason to not use SDK call method?
Because the plugin uses no gamedata and works as is by clicking "Get plugin" so I want to avoid any extra requirements. Weather Control plugin for those wondering.
__________________
Silvers is offline
Timocop
AlliedModders Donor
Join Date: Mar 2013
Location: Germany
Old 08-06-2018 , 13:06   Re: [L4D2] How to detect first chapter?
Reply With Quote #8

Tested my method? info_landmark is required on all maps. It teleports players and other items to the next chapter. So if there is only 1 info_landmark in the map it should be the start or the end of the chapter. IsFinaleMap() is self explanatory.
Timocop is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 08-06-2018 , 13:10   Re: [L4D2] How to detect first chapter?
Reply With Quote #9

Quote:
Originally Posted by Timocop View Post
Tested my method? info_landmark is required on all maps. It teleports players and other items to the next chapter. So if there is only 1 info_landmark in the map it should be the start or the end of the chapter. IsFinaleMap() is self explanatory.
It's the best candidate so far imo, I was just seeing if anyone else had a solution. Thank you!
__________________
Silvers is offline
Spirit_12
Veteran Member
Join Date: Dec 2012
Location: Toronto, CA
Old 08-06-2018 , 14:52   Re: [L4D2] How to detect first chapter?
Reply With Quote #10

Quote:
Originally Posted by Silvers View Post
@MasterMind420 Thanks, I believe these get called for saferooms on 2nd map too etc. I could try.


Because the plugin uses no gamedata and works as is by clicking "Get plugin" so I want to avoid any extra requirements. Weather Control plugin for those wondering.
You don't have to provide a separate gamedata file. You can always set the address via PrepSDKCall_SetSignature inside the plugin. Although I'm not a fan of that method, but it will work.
__________________
Spirit_12 is offline
Reply



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 02:00.


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