Raised This Month: $ Target: $400
 0% 

Setting a CVAR


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-02-2012 , 16:01   Setting a CVAR
Reply With Quote #1

Can you make a CVAR set to -1 if you're retrieving the CVAR with get_pcvar_num(g_cost)?
Liverwiz is offline
Bilal Pro
Senior Member
Join Date: Mar 2012
Location: Holland
Old 05-02-2012 , 16:29   Re: Setting a CVAR
Reply With Quote #2

Yes you can, for example

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>

#define PLUGIN "Example"
#define VERSION "1.0"
#define AUTHOR "Bilal"

new Xp
new Player_XP[33]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)

    
Xp register_cvar("test_xp""1")
    
register_clcmd("say /test""CmdGive")
}

public 
CmdGive(id)
{
    if (
is_user_connected(id)
    {
        
Player_XP[id] -= get_pcvar_num(Xp)
        
client_print(idprint_chat"You have decreased %d xp!"get_pcvar_num(Xp))
    }

__________________
  • Point System with rank titles for sale [X] [100% private]
  • VIP Menu for sale [X] [100% private]
  • HnS shop more features for sale [X] [100% private]
Contact: Bilalzaandam1234, on steam if you are interested.

Last edited by Bilal Pro; 05-02-2012 at 16:29.
Bilal Pro is offline
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 05-02-2012 , 21:24   Re: Setting a CVAR
Reply With Quote #3

Quote:
Originally Posted by Bilal Pro View Post
Yes you can, for example

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>

#define PLUGIN "Example"
#define VERSION "1.0"
#define AUTHOR "Bilal"

new Xp
new Player_XP[33]

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)

    
Xp register_cvar("test_xp""1")
    
register_clcmd("say /test""CmdGive")
}

public 
CmdGive(id)
{
    if (
is_user_connected(id)
    {
        
Player_XP[id] -= get_pcvar_num(Xp)
        
client_print(idprint_chat"You have decreased %d xp!"get_pcvar_num(Xp))
    }

That doesn't go with his question at all..

@fysiks: I think he is referring to -1 as the cvar, then getting the cvar and will it still return -1.

So:

Code:
#include <amxmodx> new pCvar; public plugin_init() {     pCvar = register_cvar("your_cvar", "-1");     func(); } public func() {     new iValue;         iValue = get_pcvar_num(pCvar);         client_print(0, print_chat, "Your cvar value is %i", iValue); }

Although, I'm not sure if it will default it to 0 or not.
__________________
Hi.
Kreation is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-02-2012 , 21:31   Re: Setting a CVAR
Reply With Quote #4

Quote:
Originally Posted by Kreation View Post
@fysiks: I think he is referring to -1 as the cvar, then getting the cvar and will it still return -1.
If that is true then that is way too trivial and needn't be asked.
__________________
fysiks is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 05-02-2012 , 21:57   Re: Setting a CVAR
Reply With Quote #5

I think he wants to force the cvar to be get as float so he wants it to be -1 if it is tried to get it as int, -1 representing blowing it up.
joaquimandrade is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-03-2012 , 07:43   Re: Setting a CVAR
Reply With Quote #6

Quote:
Originally Posted by joaquimandrade View Post
I think he wants to force the cvar to be get as float so he wants it to be -1 if it is tried to get it as int, -1 representing blowing it up.
Well, that's not something that really makes sense because the coder has to know how to use the cvar and should therefore use it correctly.
__________________
fysiks is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-02-2012 , 21:16   Re: Setting a CVAR
Reply With Quote #7

Quote:
Originally Posted by Liverwiz View Post
Can you make a CVAR set to -1 if you're retrieving the CVAR with get_pcvar_num(g_cost)?
That doesn't make sense. Try explaining again in more detail.
__________________
fysiks is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-03-2012 , 10:02   Re: Setting a CVAR
Reply With Quote #8

What i want to do is set the cost of something via CVAR. -1 represents not needing to purchase (equip automatically) 0 would be free (still has to choose to equip it) and anything above that, obviously, would be the set price.

Code:
new pcvar_cost = register_cvar("Cost", 0)
if(get_pcvar_num(pcvar_cost) == -1)
     print("THAT SHIT'S FREE!")
else
     print("Fat chicks need love too....they just gotta pay.")
I'd test it myself....but i recently lost my test server due to god knows what. In the process of fixing it.....
Liverwiz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-04-2012 , 03:45   Re: Setting a CVAR
Reply With Quote #9

Quote:
Originally Posted by Liverwiz View Post
What i want to do is set the cost of something via CVAR. -1 represents not needing to purchase (equip automatically) 0 would be free (still has to choose to equip it) and anything above that, obviously, would be the set price.

Code:
new pcvar_cost = register_cvar("Cost", 0)
if(get_pcvar_num(pcvar_cost) == -1)
     print("THAT SHIT'S FREE!")
else
     print("Fat chicks need love too....they just gotta pay.")
I'd test it myself....but i recently lost my test server due to god knows what. In the process of fixing it.....
You already know what to do it sounds like. Also, your code doesn't match your words, FYI.
__________________
fysiks is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-05-2012 , 08:58   Re: Setting a CVAR
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
You already know what to do it sounds like. Also, your code doesn't match your words, FYI.
I'm asking if the OP were to put -1 in as the CVAR in their amxx.cfg, would it bug out?
Liverwiz 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 00:20.


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