AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Cvar by Strings (Or Flags) (https://forums.alliedmods.net/showthread.php?t=127271)

#8 SickneSS 05-19-2010 05:52

Cvar by Strings (Or Flags)
 
I Want to make a cvar ussing...

Example.

PHP Code:

new szString[4]
new 
Cvar

//Init
  
Cvar register_cvar("mycvar","abc")

//Function

get_pcvar_string(Cvar,szString,3)

if 
cvar 'a' = do this
if cvar 'a+b' = do this and that
if cvar 'b' = do that
if cvar 'abc' = do this,that and those 

...So...How???


if you don't understand what i mean,please tell me.

Other thing
How i can detect if a string is a number,if is not,block them?

And...

How i can set a random model when i use cs_set_user_team(id,CS_TEAM_CT,----)?

DoviuX 05-19-2010 08:05

Re: Cvar by Strings (Or Flags)
 
Maybe this will help ?

PHP Code:

if(get_user_team(id) == CS_TEAM_CT)
{
          
cs_set_user_model(idCT_MODELrandom(0sizeof CT_MODEL)])



#8 SickneSS 05-19-2010 08:15

Re: Cvar by Strings (Or Flags)
 
Yes,i think,i need to make a enum with the CTS models?,because in the cstrike.inc
the models are all in one enum

DoviuX 05-19-2010 09:10

Re: Cvar by Strings (Or Flags)
 
Maybe something like this help.

PHP Code:

new const CT_MODELS[][]
{
    
"models/ct/firstmodel.mdl",
    
"models/ct/secondmodel.mdl",
    
"models/ct/thirdmodel.mdl"
}

public 
plugin_precache()
{
    new 
iNum
    
for (iNum 0iNum sizeof CT_MODELSiNum++)
        
engfunc(EngFunc_PrecacheModelCT_MODELS[iNum])
}

public 
whatever(id)
{
    if(
get_user_team(id) == CS_TEAM_CT)
    {
        
cs_set_user_model(idCT_MODELSrandom(0sizeof CT_MODELS)])
    }



#8 SickneSS 05-19-2010 09:57

Re: Cvar by Strings (Or Flags)
 
I don't think so

Bugsy 05-19-2010 10:05

Re: Cvar by Strings (Or Flags)
 
Why do you want to have a + in the flags? Why not just use a list of flags like used for admin flags. You can then use read_flags and bit flags for each option.

unnyquee 05-19-2010 10:14

Re: Cvar by Strings (Or Flags)
 
PHP Code:

#include <amxmodx>

#define ACCESS_WHATEVER_1 (1<<0) // a
#define ACCESS_WHATEVER_2 (1<<1) // b
#define ACCESS_WHATEVER_3 (1<<2) // c
// and so on..

new g_cFlags;

public 
plugin_init()
{
      
register_plugin("Flags?""0.0""#8 SickneSS");
      
      
g_cFlags register_cvar("plugin_flags""abc");
}

public 
your_public(/* args */)
{
      static 
szFlags[32];
      
      
get_pcvar_string(g_cFlagsszFlagscharsmax(szFlags));
      
      if(
read_flags(szFlags) & ACCESS_WHATEVER_1)
      {
            
// got the flag 'a'
      
}
      
      if(
read_flags(szFlags) & ACCESS_WHATEVER_2)
      {
            
// got the flag 'b'
      
}

      if(
read_flags(szFlags) & ACCESS_WHATEVER_3)
      {
            
// got the flag 'c'
      
}
      
      
// and so on again..



#8 SickneSS 05-19-2010 10:49

Re: Cvar by Strings (Or Flags)
 
Quote:

Originally Posted by Bugsy (Post 1184924)
Why do you want to have a + in the flags? Why not just use a list of flags like used for admin flags. You can then use read_flags and bit flags for each option.

I Don't Know How,if this dont's works...

Quote:

Originally Posted by unnyquee (Post 1184938)
PHP Code:

#include <amxmodx>

#define ACCESS_WHATEVER_1 (1<<0) // a
#define ACCESS_WHATEVER_2 (1<<1) // b
#define ACCESS_WHATEVER_3 (1<<2) // c
// and so on..

new g_cFlags;

public 
plugin_init()
{
      
register_plugin("Flags?""0.0""#8 SickneSS");
      
      
g_cFlags register_cvar("plugin_flags""abc");
}

public 
your_public(/* args */)
{
      static 
szFlags[32];
      
      
get_pcvar_string(g_cFlagsszFlagscharsmax(szFlags));
      
      if(
read_flags(szFlags) & ACCESS_WHATEVER_1)
      {
            
// got the flag 'a'
      
}
      
      if(
read_flags(szFlags) & ACCESS_WHATEVER_2)
      {
            
// got the flag 'b'
      
}

      if(
read_flags(szFlags) & ACCESS_WHATEVER_3)
      {
            
// got the flag 'c'
      
}
      
      
// and so on again..



I will read the admin.sma

btw Thanks!

lazarev 05-19-2010 11:21

Re: Cvar by Strings (Or Flags)
 
PHP Code:

    static connectenabler[6];
    
get_pcvar_string(kz_ljs_connectenablerconnectenabler5);
    
format(connectenabler5"_%s"connectenabler);

    if( 
contain(connectenabler"a") > )
        
gHasColorChat[id] = true;
    else
        
gHasColorChat[id] = false


Bugsy 05-19-2010 11:59

Re: Cvar by Strings (Or Flags)
 
Using bit flags would be cheaper.
PHP Code:

enum _:Flags (<<=1)
{
     
FlagA 1,  //'a'
     
FlagB,  //'b'
     
FlagC,  //'c'
     
FlagD,  //'d '
     
FlagE   //'e'
}

new 
iFlags read_flagsszFlags );

if ( 
iFlags FlagA )
{
        
//player has flag a




All times are GMT -4. The time now is 16:53.

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