Raised This Month: $32 Target: $400
 8% 

Adding Enable CVar?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bmxican0091
Member
Join Date: Jan 2010
Location: Australia, Victoria.
Old 08-18-2010 , 08:40   Adding Enable CVar?
Reply With Quote #1

I am wanting to add a enable CVar to a plugin im editing, since im new to coding could someone please help me out with explenation and re-written code?

PHP Code:
/**
 * I did not create this plugin 
 * I am modifying it to add some features
 * Original plugin creator atom0s
 */
 
#pragma semicolon 1
 
#include <sourcemod>
#include <colors>
 
#define PLUGIN_VERSION "1.0"
 
new Handle:g_Cvarenabled INVALID_HANDLE;
 
public 
Plugin:myinfo =
{
     
name        "*NEW* Simple Admin Message",
     
author      "atom0s",
     
description "Display a message to admins when they connect.",
     
version     PLUGIN_VERSION,
        
url         "http://www.sourcemod.net/"
};
 
public 
OnPluginStart( )
{
  
CreateConVar("sm_simpleadminmsg_version"PLUGIN_VERSION"Simple Admin Message version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
}
 
public 
OnClientPostAdminCheckclient )
{
     new 
AdminId:aid GetUserAdminclient );
     if( 
aid != INVALID_ADMIN_ID )
     {
         
CreateTimer(10printMessageclient);
     }
}
 
public 
Action:printMessage(Handle:timerany:client) {
        
PrintToChatclient"Welcome admin!" );
        
PrintToChatclient"Please use sm_admin to open the admin menu!" );

__________________

bmxican0091 is offline
atom0s
Senior Member
Join Date: Jul 2009
Old 08-18-2010 , 08:45   Re: Adding Enable CVar?
Reply With Quote #2

Heres the original with your question implemented:
PHP Code:
#pragma semicolon 1
#include <sourcemod>

public Plugin:myinfo =
{
    
name        "Simple Admin Message",
    
author      "atom0s",
    
description "Display a message to admins when they connect.",
    
version     "1.0.0",
    
url         "N/A"
};

new 
Handle:g_CvarPluginEnabled INVALID_HANDLE;

public 
OnPluginStart( )
{
    
CreateConVar"simpleadminmsg_version""1.0.0""Simple Admin Message version."FCVAR_PLUGIN|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
g_CvarPluginEnabled CreateConVar"simpleadminmsg_enabled""1""Admin message enable flag." );
}

public 
OnClientPostAdminCheckclient )
{
    
// Don't continue if plugin is disabled.
    
if( !GetConVarBoolg_CvarPluginEnabled ) )
        return;

    new 
AdminId:aid GetUserAdminclient );
    if( 
aid != INVALID_ADMIN_ID )
    {
        
PrintToChatclient"Welcome admin!" );
        
PrintToChatclient"Please use sm_admin to open the admin menu!" );
    }

atom0s is offline
bmxican0091
Member
Join Date: Jan 2010
Location: Australia, Victoria.
Old 08-18-2010 , 08:54   Re: Adding Enable CVar?
Reply With Quote #3

Thanks for quick reply, so can i use the code like that on all plugins i want to add a Enable CVar to? Sorry im a bit of a noob with coding :S

PHP Code:
if( !GetConVarBoolg_CvarPluginEnabled ) )
    return; 
__________________


Last edited by bmxican0091; 08-18-2010 at 08:58.
bmxican0091 is offline
atom0s
Senior Member
Join Date: Jul 2009
Old 08-18-2010 , 09:33   Re: Adding Enable CVar?
Reply With Quote #4

The return may change depending on what the function you are exiting expects as a return. OnClientPostAdminCheck doesn't expect a return value, so simply using return; alone will leave the function gracefully.

However, in some cases you will have returns such as Action, bool, etc where you will need to return the specific type. In most cases it will either be Plugin_Continue or true for those return types, respectively.
atom0s is offline
bmxican0091
Member
Join Date: Jan 2010
Location: Australia, Victoria.
Old 08-18-2010 , 17:38   Re: Adding Enable CVar?
Reply With Quote #5

Thanks
__________________

bmxican0091 is offline
bmxican0091
Member
Join Date: Jan 2010
Location: Australia, Victoria.
Old 08-19-2010 , 02:18   Re: Adding Enable CVar?
Reply With Quote #6

Im getting two errors when i compile, help pls?

PHP Code:
// simpleadminmsg.sp(38) : warning 217: loose indentation
// simpleadminmsg.sp(41) : warning 213: tag mismatch 
Here is my source code below:

PHP Code:
/**
 * I did not create this plugin 
 * I am modifying it to add some features
 * Original plugin creator atom0s
 */
 
#pragma semicolon 1
 
#include <sourcemod>
#include <colors>
 
#define PLUGIN_VERSION "1.0"
 
public Plugin:myinfo =
{
     
name        "*NEW* Simple Admin Message",
     
author      "atom0s",
     
description "Display a message to admins when they connect.",
     
version     PLUGIN_VERSION,
        
url         "http://www.sourcemod.net/"
};
 
new 
Handle:g_CvarPluginEnabled INVALID_HANDLE;
 
public 
OnPluginStart( )
{
         
CreateConVar("sm_simpleadminmsg_version"PLUGIN_VERSION"Simple Admin Message version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
         
g_CvarPluginEnabled CreateConVar"sm_simpleadminmsg_enabled""1""Enables/Disables this plugin." );
}
 
public 
OnClientPostAdminCheckclient )
{
         if( !
GetConVarBoolg_CvarPluginEnabled ) )
         return;
 
         new 
AdminId:aid GetUserAdminclient );
         if( 
aid != INVALID_ADMIN_ID )
         {
            
CreateTimer(10printMessageclient);
         }
}
 
public 
Action:printMessage(Handle:timerany:client) {
        
PrintToChatclient"Welcome admin!" );
        
PrintToChatclient"Please use sm_admin to open the admin menu!" );

__________________

bmxican0091 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 08-19-2010 , 07:00   Re: Adding Enable CVar?
Reply With Quote #7

Quote:
Originally Posted by bmxican0091 View Post
Im getting two errors when i compile, help pls?

PHP Code:
// simpleadminmsg.sp(38) : warning 217: loose indentation
// simpleadminmsg.sp(41) : warning 213: tag mismatch 
...
simpleadminmsg.sp(38) : warning 217: loose indentation
You maybe get these errors because you copy code from here forum post and paste to your source file *.sp.
Forum post change TAB-spaces to normal SPACE.

simpleadminmsg.sp(41) : warning 213: tag mismatch
If you look line 41, there have been given integer value instead float.
you can change it
CreateTimer(10.0, printMessage, client);

But these are little warnings, plugin should be work... or give more errors during game :P


I wonder why you have include #include <colors>, but you never use it in code.
Read more [INC] Colors (1.0.4)
Bacardi is offline
bmxican0091
Member
Join Date: Jan 2010
Location: Australia, Victoria.
Old 08-19-2010 , 08:19   Re: Adding Enable CVar?
Reply With Quote #8

Quote:
Originally Posted by Bacardi View Post
simpleadminmsg.sp(3 : warning 217: loose indentation
You maybe get these errors because you copy code from here forum post and paste to your source file *.sp.
Forum post change TAB-spaces to normal SPACE.

simpleadminmsg.sp(41) : warning 213: tag mismatch
If you look line 41, there have been given integer value instead float.
you can change it
CreateTimer(10.0, printMessage, client);

But these are little warnings, plugin should be work... or give more errors during game


I wonder why you have include #include <colors>, but you never use it in code.
Read more [INC] Colors (1.0.4)
I have included colors because i am adding features, the plugin isnt finished yet, was just going to fix these errors first. Any ways thanks for the help
__________________

bmxican0091 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 15:49.


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