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

mod detection code snippit?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-26-2009 , 09:03   mod detection code snippit?
Reply With Quote #1

I remember seeing it in several plugins (naris made them I think?) detects the mod based on the mod folder... I just can't find it.

Anyone know what I'm talking about and have it?
Dragonshadow is offline
Antithasys
Moderator
Join Date: Apr 2008
Old 09-26-2009 , 10:50   Re: mod detection code snippit?
Reply With Quote #2

PHP Code:
new String:sGameType[64];
GetGameFolderName(sGameTypesizeof(sGameType));
    
if (
StrEqual(sGameType"cstrike"false))
{
    
//something

__________________
[my plugins]

When you think about asking a question... consider what have you tried?
Antithasys is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 09-26-2009 , 10:53   Re: mod detection code snippit?
Reply With Quote #3

PHP Code:
#define GAME_ANY 0
#define GAME_CS 1
#define GAME_TF 2
#define GAME_HL 3
#define GAME_DOD 4

new Game GAME_ANY;

public 
OnPluginStart()
{    
    
// Getting a game name and doing game specific stuff
    
decl String:gameName[30];
    
GetGameFolderName(gameNamesizeof(gameName));
    
    
// CS stuff
    
if (StrEqual(gameName"cstrike"false))
    {
        
Game GAME_CS;
        
        
CS_Stuff();
    }
    
// TF stuff
    
else if (StrEqual(gameName"tf"false))
    {
        
Game GAME_TF;
        
        
TF_Stuff();
    }
    
// HL stuff
    
else if (StrEqual(gameName"hl2mp"false))
    {
        
Game GAME_HL;
        
        
HL_Stuff();
    }
    
// L4D is completely unsupported
    
else if (StrEqual(gameName"left4dead"false))
    {
        
SetFailState("This game is not supported");
    }
    
// For all other games we will do standart stuff
    
else
    {
        
Game GAME_ANY;
        
        
// Hooking commands for detecting of new game start
        
cvar_restartgame FindConVar("mp_restartgame");
        if (
cvar_restartgame != INVALID_HANDLE)
            
HookConVarChange(cvar_restartgameNewGameCommand);
        
        
cvar_restartround FindConVar("mp_restartround");
        if (
cvar_restartround != INVALID_HANDLE)
            
HookConVarChange(cvar_restartroundNewGameCommand);
        
        
// Hooking events for detecting of new game start
        
HookEvent("round_start"Event_NewGameStart);
        
HookEvent("round_end"Event_RoundEnd);
    }

This is an example from my savescores plugin. It looks a little bit big... I know but the main idea is that you only need GetGameFolderName function for getting game short name (folder name) and then just use StrEqual to match game names and do specific stuff.
In my example there is also Game variable that is integer and stores defined game number. This is useful during the plugin work because always using GetGameFolderName when there are many players on the server isn't a good idea. This will work much faster:
PHP Code:
if (Game == GAME_CS)
{
    
// do something

__________________
For admins: My plugins

For developers: Colors library

Last edited by exvel; 09-26-2009 at 11:02.
exvel is offline
Send a message via ICQ to exvel
javalia
Senior Member
Join Date: May 2009
Location: korea, republic of
Old 09-26-2009 , 11:01   Re: mod detection code snippit?
Reply With Quote #4

i am agreeing at all to exvel.
i made almost same thing with exvel`s one for my new mod, tremulous(in dev)
but i used enum lolf it is just my favorite lol
javalia is offline
exvel
SourceMod Donor
Join Date: Jun 2006
Location: Russia
Old 09-26-2009 , 11:04   Re: mod detection code snippit?
Reply With Quote #5

I think enums are better because there is no difference which number contains in the Game variable. But I wrote this code a long time ago and I didn't know about enums
__________________
For admins: My plugins

For developers: Colors library
exvel is offline
Send a message via ICQ to exvel
Antithasys
Moderator
Join Date: Apr 2008
Old 09-26-2009 , 11:22   Re: mod detection code snippit?
Reply With Quote #6

Ya. Take a look at the simple-plugins.inc file. It basically does this for you. And yes, it uses enums. lol.
__________________
[my plugins]

When you think about asking a question... consider what have you tried?
Antithasys is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 09-26-2009 , 17:11   Re: mod detection code snippit?
Reply With Quote #7

I use the attached include file with this function/enum:

PHP Code:
enum Mod undetectedtf2cstrikedodhl2mpinsurgencyother };
stock Mod:GameType undetected;

stock Mod:GetGameType()
{
    if (
GameType == undetected)
    {
        new 
String:modname[30];
        
GetGameFolderName(modnamesizeof(modname));
        if (
StrEqual(modname,"cstrike",false))
            
GameType=cstrike;
        else if (
StrEqual(modname,"tf",false)) 
            
GameType=tf2;
        else if (
StrEqual(modname,"dod",false)) 
            
GameType=dod;
        else if (
StrEqual(modname,"hl2mp",false)) 
            
GameType=hl2mp;
        else if (
StrEqual(modname,"Insurgency",false)) 
            
GameType=insurgency;
        else
            
GameType=other;
    }
    return 
GameType;

Attached Files
File Type: inc gametype.inc (1,000 Bytes, 79 views)
naris is offline
Dragonshadow
BANNED
Join Date: Jun 2008
Old 09-26-2009 , 18:07   Re: mod detection code snippit?
Reply With Quote #8

Quote:
Originally Posted by naris View Post
I use the attached include file with this function/enum:

PHP Code:
enum Mod undetectedtf2cstrikedodhl2mpinsurgencyother };
stock Mod:GameType undetected;

stock Mod:GetGameType()
{
    if (
GameType == undetected)
    {
        new 
String:modname[30];
        
GetGameFolderName(modnamesizeof(modname));
        if (
StrEqual(modname,"cstrike",false))
            
GameType=cstrike;
        else if (
StrEqual(modname,"tf",false)) 
            
GameType=tf2;
        else if (
StrEqual(modname,"dod",false)) 
            
GameType=dod;
        else if (
StrEqual(modname,"hl2mp",false)) 
            
GameType=hl2mp;
        else if (
StrEqual(modname,"Insurgency",false)) 
            
GameType=insurgency;
        else
            
GameType=other;
    }
    return 
GameType;

thank you
Dragonshadow 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 16:24.


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