AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Setting a CVAR (https://forums.alliedmods.net/showthread.php?t=184238)

Liverwiz 05-02-2012 16:01

Setting a CVAR
 
Can you make a CVAR set to -1 if you're retrieving the CVAR with get_pcvar_num(g_cost)?

Bilal Pro 05-02-2012 16:29

Re: Setting a CVAR
 
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))
    }



fysiks 05-02-2012 21:16

Re: Setting a CVAR
 
Quote:

Originally Posted by Liverwiz (Post 1700666)
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.

Kreation 05-02-2012 21:24

Re: Setting a CVAR
 
Quote:

Originally Posted by Bilal Pro (Post 1700681)
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.

fysiks 05-02-2012 21:31

Re: Setting a CVAR
 
Quote:

Originally Posted by Kreation (Post 1700851)
@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.

joaquimandrade 05-02-2012 21:57

Re: Setting a CVAR
 
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.

fysiks 05-03-2012 07:43

Re: Setting a CVAR
 
Quote:

Originally Posted by joaquimandrade (Post 1700863)
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.

Liverwiz 05-03-2012 10:02

Re: Setting a CVAR
 
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.....

fysiks 05-04-2012 03:45

Re: Setting a CVAR
 
Quote:

Originally Posted by Liverwiz (Post 1701140)
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.

Liverwiz 05-05-2012 08:58

Re: Setting a CVAR
 
Quote:

Originally Posted by fysiks (Post 1701779)
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?


All times are GMT -4. The time now is 00:20.

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