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

Best way to find a server command integer?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-08-2014 , 00:42   Best way to find a server command integer?
Reply With Quote #1

Hi,

Quick question, which way is better/faster to get a server command value?

For this example I want to get the mp_maxrounds integer and divide it by 2 so I know when it is half time.

PHP Code:
public OnPluginStart()
{
g_h_max_rounds FindConVar ("mp_maxrounds");
}

CheckScores() //checked at end of every round
{
    if (
GetScore() == (GetConVarInt(g_h_max_rounds))/2)// half time
    
{
// code
        

or

PHP Code:
CheckScores() //checked at end of every round
{
    if (
GetScore() == (GetConVarInt(FindConVar("mp_maxrounds"))/2)// half time
    
{
// code
        

Or should I store it and HookConVarChange with it divided by 2?
PHP Code:
new maxrounds 15;

public 
OnPluginStart()
{
HookConVarChange(FindConVar("mp_maxrounds"), OnMaxRoundChangeMP);
}

public 
OnMaxRoundChangeMP(Handle:cvar, const String:oldVal[], const String:newVal[])
{
    
maxrounds = (GetConVarInt(FindConVar("mp_maxrounds"))/2);

    if (
g_live)
    {
        
CheckScores();
    }
}

CheckScores() //checked at end of every round
{
    if (
GetScore() == maxrounds)// half time
    
{
// code
        

Or is it a much of a muchness and the top way just looks cleaner?

Looking to remove a lot of convar's from one of my plugins back to the normal server commands.
__________________

Last edited by versatile_bfg; 09-08-2014 at 01:52.
versatile_bfg is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 09-08-2014 , 04:29   Re: Best way to find a server command integer?
Reply With Quote #2

Better way would be hooking events. AFAIK announce_phase_end is called when halftime is reached, and cs_intermission when the map ends.
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-08-2014 , 05:29   Re: Best way to find a server command integer?
Reply With Quote #3

Quote:
Originally Posted by Root_ View Post
Better way would be hooking events. AFAIK announce_phase_end is called when halftime is reached, and cs_intermission when the map ends.
This isn't the only command I want. Also helps with scoring, OT and other stuff. Just using this part as an example to fix up the rest the same way.
__________________
versatile_bfg is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-08-2014 , 09:41   Re: Best way to find a server command integer?
Reply With Quote #4

FindConVar can be somewhat expensive, so it's recommended you just do it once and save the Handle it returns.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
versatile_bfg
Veteran Member
Join Date: Feb 2012
Old 09-08-2014 , 19:24   Re: Best way to find a server command integer?
Reply With Quote #5

Quote:
Originally Posted by Powerlord View Post
FindConVar can be somewhat expensive, so it's recommended you just do it once and save the Handle it returns.
Cheers. So top one is the go. =)
__________________
versatile_bfg is offline
Reply


Thread Tools
Display Modes

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 06:13.


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