AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get different info form one cvar (https://forums.alliedmods.net/showthread.php?t=87274)

GoGoGo 03-09-2009 09:16

Get different info form one cvar
 
Hi

How to get different info from one cvar (in cfg file). I mean how to transform:
Code:

some_cvar "lol"
some_cvar "lol2"
some_cvar "lol3"
some_cvar "lol4"

(this code is written in config/some_cvar.cfg)
to
Code:

cvar [0] = lol
cvar [1] = lol2
cvar [2] = lol3
cvar [3] = lol4

(And plugin transform it to this form)
Sorry 4 bad description but I had no idea how to tell this.

TheRadiance 03-09-2009 09:26

Re: Get different info form one cvar
 
Example:
PHP Code:

...

#define MAX_CVARS 4
#define MAX_LENGTH 32

...

new const 
g_szCvarsMAX_CVARS ][ MAX_LENGTH ]

...

new 
szCvar1MAX_LENGTH ]
new 
szCvar2MAX_LENGTH ]
get_cvar_string"some_cvar"szCvar1sizeof szCvar1 ) - )
get_cvar_string"some_cvar"szCvar2sizeof szCvar2 ) - )

g_szCvars] = szCvar1
g_szCvars
] = szCvar2 


Bugsy 03-09-2009 10:22

Re: Get different info form one cvar
 
Are you trying to convert individual cvar pointer variables to an array of cvar pointers?

PHP Code:

new g_Cvar[5];

enum
{
    
ITEM1,
    
ITEM2,
    
ITEM3,
    
ITEM4,
    
ITEM5
}

public 
plugin_init()
{
    
g_Cvar[ITEM1] = register_cvar"item1" "val1" );
    
g_Cvar[ITEM2] = register_cvar"item2" "val2" );
    
g_Cvar[ITEM3] = register_cvar"item3" "val3" );
    
g_Cvar[ITEM4] = register_cvar"item4" "val4" );
    
g_Cvar[ITEM5] = register_cvar"item5" "val5" );
}

new 
szVal[5];
get_pcvar_string g_Cvar[ITEM1] , szVal ); 


xPaw 03-09-2009 10:59

Re: Get different info form one cvar
 
i think he wants todo like for example amx_imessage, you can do multiple thing with that

and btw its not cvar, its like an console command :]

GoGoGo 03-09-2009 12:35

Re: Get different info form one cvar
 
Yes, I don't want to use 5 items, I want to use one command.

First method is not working for me, but these two definitions (max cvar and lenght) are good :P

AntiBots 03-09-2009 12:44

Re: Get different info form one cvar
 
See register_srvcmd("amx_addserver", "addserver")

http://forums.alliedmods.net/showpos...66&postcount=6

GoGoGo 03-09-2009 13:05

Re: Get different info form one cvar
 
Ok one more thing

I can check args, but how to go to next line

some_cvar "lol"
some_cvar "lol2"


First line is checked by read arg 1, but how to check lol2?

fysiks 03-09-2009 13:15

Re: Get different info form one cvar
 
Quote:

Originally Posted by GoGoGo (Post 777172)
Ok one more thing

I can check args, but how to go to next line

some_cvar "lol"
some_cvar "lol2"


First line is checked by read arg 1, but how to check lol2?


It will be read by read_argv(1), it doesn't change. Everythime that "some_cvar" is executed you will be starting over essentially (if you are registering it as a server command).

GoGoGo 03-09-2009 13:20

Re: Get different info form one cvar
 
So what code should I add to make it work?

fysiks 03-09-2009 13:30

Re: Get different info form one cvar
 
PHP Code:

#include <amxmodx>
new Array:my_array_of_strings
public plugin_init() 
{
 
register_srvcmd("some_cvar""add_value_to_array")
}
public 
add_value_to_array()
{
 new 
my_string[32]
 
read_argv(1my_string31)
 
ArrayPushString(my_array_of_stringsmy_string)
 return 
PLUGIN_HANDLED


Then use "my_array_of_strings[#]" anywhere in the plugin. But remember to check the size of the array so you don't go "out of bounds"


All times are GMT -4. The time now is 09:02.

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