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

[Solved] 1 == Infinite CVar Set?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 05-01-2012 , 12:32   [Solved] 1 == Infinite CVar Set?
Reply With Quote #1

I was attempting to find a script function to implement into one of my plugins to simply make it if someone sets the CVar to -1, it will act as infinite. (Or 1,000,000,000,000...)

I added this after the CreateConvar for the handle:

Code:
	sm_logo_spawntime = CreateConVar("sm_logo_spawntime", "2", "Time After Spawn to Show Phrase", _, true, -1.0, true, 60.0);
	z = GetConVarFloat(sm_logo_spawntime);
	HookConVarChange(sm_logo_spawntime, zCVarChanged);
	if(GetConVarFloat(sm_logo_spawntime) == -1.0)
	{
		SetConVarFloat(sm_logo_spawntime, 100000000.0)
	}
However this didn't work.

Last edited by ReFlexPoison; 05-01-2012 at 23:04. Reason: Solved
ReFlexPoison is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 05-01-2012 , 12:40   Re: 1 == Infinite CVar Set?
Reply With Quote #2

Your explanation is not good enough. What exactly do you want to do? If someone change that ConVar's value to -1 then what?
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 05-01-2012 , 13:31   Re: 1 == Infinite CVar Set?
Reply With Quote #3

you could just put a CVar that is a bool (0=off, 1=on) and call it sm_logo_infinitetime and if that CVar is 1, then don't even look at the spawntime cvar...
__________________
View my Plugins | Donate
TnTSCS is offline
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 05-01-2012 , 13:35   Re: 1 == Infinite CVar Set?
Reply With Quote #4

Quote:
Originally Posted by claudiuhks View Post
Your explanation is not good enough. What exactly do you want to do? If someone change that ConVar's value to -1 then what?
It is hooked to a timer that represents how long Hud Text will show on the screen.
Code from my Server Hud Logo plugin looking to update it soon.

I will probably look into what TnTSCS said.
ReFlexPoison is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 05-01-2012 , 19:51   Re: 1 == Infinite CVar Set?
Reply With Quote #5

Why not just say -1 is infinite, and leave it at that? No need to change cvars again.
__________________
11530 is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 05-01-2012 , 21:33   Re: 1 == Infinite CVar Set?
Reply With Quote #6

Something like this?

PHP Code:
public MyFunction( )
{
  
decl iNumber;
  
iNumber GetConVarIntg_hMyConVar );

  if( 
iNumber == -)
    
CreateTimer3.0TimerAdvertisements, -1TIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE );

  else if( 
iNumber == )
    
CreateTimer3.0TimerAdvertisements, -1TIMER_FLAG_NO_MAPCHANGE );

  else if( 
iNumber )
    
CreateTimer3.0TimerAdvertisementsiNumberTIMER_FLAG_NO_MAPCHANGE );
}

public 
ActionTimerAdvertisementsHandlehTimeranyiNumber )
{
  
/* My code here */;

  if( 
iNumber )
    
CreateTimer3.0TimerAdvertisementsiNumber 1TIMER_FLAG_NO_MAPCHANGE );

__________________

Last edited by claudiuhks; 05-01-2012 at 21:34.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-01-2012 , 23:24   Re: [Solved] 1 == Infinite CVar Set?
Reply With Quote #7

Quote:
Originally Posted by ReFlexPoison View Post
I was attempting to find a script function to implement into one of my plugins to simply make it if someone sets the CVar to -1, it will act as infinite. (Or 1,000,000,000,000...)

I added this after the CreateConvar for the handle:

Code:
	sm_logo_spawntime = CreateConVar("sm_logo_spawntime", "2", "Time After Spawn to Show Phrase", _, true, -1.0, true, 60.0);
	z = GetConVarFloat(sm_logo_spawntime);
	HookConVarChange(sm_logo_spawntime, zCVarChanged);
	if(GetConVarFloat(sm_logo_spawntime) == -1.0)
	{
		SetConVarFloat(sm_logo_spawntime, 100000000.0)
	}
However this didn't work.
Which mistake did you want us to point out first? The fact that you're trying to compare two Floats using == or the fact that you're trying to set your own convar to 100000000.0 after you limited to a max of 60 in the CreateConVar line?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
napalm00
Veteran Member
Join Date: Jun 2011
Location: Italy, sadly
Old 05-02-2012 , 01:17   Re: [Solved] 1 == Infinite CVar Set?
Reply With Quote #8

Quote:
Originally Posted by Powerlord View Post
The fact that you're trying to compare two Floats using ==
A comparison like this can be considered correct,it's not like you're comparing it with 1.462946251 * 10^36, duh.
__________________

Last edited by napalm00; 05-02-2012 at 01:17.
napalm00 is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 05-02-2012 , 01:31   Re: [Solved] 1 == Infinite CVar Set?
Reply With Quote #9

Yes, it's alright to compare two floats using operator ==
It's like you're comparing two floats using operator <

Instead of hardcode your ConVar's value to 100000 if it's value is equal with -1 you could better set it 100000 in your CFG file.
__________________

Last edited by claudiuhks; 05-02-2012 at 01:34.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 05-02-2012 , 02:06   Re: [Solved] 1 == Infinite CVar Set?
Reply With Quote #10

Well all I did was use an if else statement of:
Code:
		if(GetConVarFloat(sm_logo_holdtime) == -1) //Holdtime refers to t.
		{
			SetHudTextParams(x, y, 604800.0, red, green, blue, alpha, effect);
		}
		else
		{
			SetHudTextParams(x, y, t, red, green, blue, alpha, effect);
		}
Of course 604800 being the "infinite" time.

All the integers and floats are represented in CVars, which is why I was confused on how to do this. Wasn't really thinking completely, however this did the trick.

EDIT: And people can specify it larger than 604800 (which I doubt anyone will do), the CVar has no maximum.

Last edited by ReFlexPoison; 05-02-2012 at 12:03.
ReFlexPoison 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 02:32.


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