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

SetConVarInt vs. ServerCommand


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 05-02-2012 , 07:57   SetConVarInt vs. ServerCommand
Reply With Quote #1

Which is more efficient?

SetConVarInt(FindConVar("mp_waitingforplayers _cancel"), 1);

ServerCommand("mp_waitingforplayers_cancel 1");
__________________
Dr. McKay is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 05-02-2012 , 08:23   Re: SetConVarInt vs. ServerCommand
Reply With Quote #2

I've always seen it recommended not to use the ServerCommand where possible. The ServerCommand is delayed by 1 frame or something. You can use the ServerExecute command to process the command buffer. If you are setting many cvars eventually the buffer will be full and not set those truncated.

Best method:
Put FindConVar in OnPluginStart and store the returned value in a global handle. Then use SetConVarInt with that global handle. FindConVar is expensive and should not be used any where else except in OnPluginStart().
__________________

Last edited by Silvers; 05-02-2012 at 08:23.
Silvers is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 05-02-2012 , 09:00   Re: SetConVarInt vs. ServerCommand
Reply With Quote #3

Thing is, this will only be done once per round, and that's the only cvar I'm setting. I don't care if it's delayed by one frame.
__________________
Dr. McKay is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 05-02-2012 , 09:07   Re: SetConVarInt vs. ServerCommand
Reply With Quote #4

SetConVarInt + FindConVar is considerably faster, more efficient and more "correct" than using ServerCommand.
__________________
asherkin is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 05-02-2012 , 09:09   Re: SetConVarInt vs. ServerCommand
Reply With Quote #5

Quote:
Originally Posted by asherkin View Post
SetConVarInt + FindConVar is considerably faster, more efficient and more "correct" than using ServerCommand.
Alrighty then, thanks Fennec Fox.

__________________

Last edited by Dr. McKay; 05-02-2012 at 09:15.
Dr. McKay is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 05-02-2012 , 10:16   Re: SetConVarInt vs. ServerCommand
Reply With Quote #6

Like asherkin said, of course SetConVarInt is more faster and reliable, this call will update the server's engine instead of sending a server command which is going to be parsed then executed.
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
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 18:27.


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