AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CVARS? (https://forums.alliedmods.net/showthread.php?t=185458)

Waleed 05-17-2012 17:25

CVARS?
 
Hey,There.


How to make CVARS for our own plugin like "csdm_active 1/0"

If it is register_cvar( , , , ,) //explain the 4 arguments please,How to set it to 1/0 condition: 1 - on/ 0 - off

Also what are flags like ADMIN_KICK
where can I get info about all flags?

Bilal Pro 05-17-2012 17:34

Re: CVARS?
 
Example.

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new cvar // new array

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
cvar register_cvar("cvar_on""1"// were registering the cvar


and then at your function.

PHP Code:

public function(id)
{
    if (!(
cvar == 1)) // if it isnt 1 ! = not
    
{
        return 
PLUGIN_HANDLED
    
}
    
    
// continue code


EDIT: u can get the flags info at. addons/amxmodx/configs/users.ini

Liverwiz 05-17-2012 17:46

Re: CVARS?
 
Quote:

Originally Posted by Bilal Pro (Post 1710896)
new cvar // new array

Correction: it is a POINTER (pcvar) pointer to cvar
you retrieve the data with get_pcvar_num/float/flags etc

<VeCo> 05-18-2012 04:42

Re: CVARS?
 
PHP Code:

 if (!(cvar == 1)) 

This should be:

PHP Code:

if(get_pcvar_num(cvar) != 1

That means if the value of the CVAR is not equal to 1. If you want to specify it only for 0 you can make it like this:

PHP Code:

if(get_pcvar_num(cvar) == 0

Or:

PHP Code:

if(!get_pcvar_num(cvar)) 


fysiks 05-18-2012 05:21

Re: CVARS?
 
Quote:

Originally Posted by Bilal Pro (Post 1710896)
Example.

PHP Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new cvar // new array

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
cvar register_cvar("cvar_on""1"// were registering the cvar


and then at your function.

PHP Code:

public function(id)
{
    if (!(
cvar == 1)) // if it isnt 1 ! = not
    
{
        return 
PLUGIN_HANDLED
    
}
    
    
// continue code


EDIT: u can get the flags info at. addons/amxmodx/configs/users.ini

Seriously, stop trying to help. You don't know what you are doing.

Bilal Pro 05-18-2012 05:38

Re: CVARS?
 
Lol, when you are changing the cvar you are changing the array so what is wrong on this -.-

<VeCo> 05-18-2012 06:10

Re: CVARS?
 
The "cvar" variable is just an id, not the CVAR value itself. You need to use that id with get_pcvar_* to retrieve the value.

akcaliberg 05-18-2012 07:13

Re: CVARS?
 
@Bilal Pro

seriously, do you know scripting ? I don't know pawn scripting exactly. But I even know how to use a cvar.

mottzi 05-18-2012 07:18

Re: CVARS?
 
BTW: Bilal Pro, the variable you created isn't an array.

Liverwiz 05-18-2012 08:54

Re: CVARS?
 
If all that confused you, without getting any real answers....here is a CORRECT example of how to define, initialize, and use a CVAR

This is pretty much a Copypasta of an old plugin of mine

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <hamsandwich>        // WITH CHEESE!

#define PLUGIN    "CVAR Example"
#define AUTHOR    "LIverwiz"
#define VERSION    "0.1"
      
new g_16k_pcvar  // define your global cvar pointer (where your code stores the server's CVAR)

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
g_16k_pcvar register_cvar("amxx_16k""2")  // Making that CVAR in the server (amxx_16k) and then storing the pointer to your global
                               // As you can see i chose 2 to be the default value (in case the OP doesn't give it one, the server just uses these defined default values
    
    
RegisterHam(Ham_Spawn"player""ham_startMoney"1// you get to learn some hamsandwich too!
}


public 
ham_startMoney(id)
{            
    new 
i_cvarFlag get_pcvar_num(g_16k_pcvar)  // This gets your CVAR and stores its actual value to a variable (i chose i_cvarFlag)
    
if( (i_cvarFlag == || i_cvarFlag == 3) && !is_user_bot(id))  //This uses that variable and tests how the program is going to function, depending on what the OP defines it as
        
give_money(id)


Now i'm sure i got some of the lingo wrong for some of the PAWN purists. But This is a working example of how to give players money at spawn.

NOTE: give_money() function is NOT shown. It is defined later in the code. I just cut the code down for ease of reading. Good luck! :attack:


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

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