AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Assigning variables to cvars (https://forums.alliedmods.net/showthread.php?t=13698)

Anthraxnz 05-26-2005 05:25

Assigning variables to cvars
 
im trying to write a war pluging for cs, iv got most of it working except i wanted to create a random password to secure the server.

what i need to know if its even possible, can you take a bunch of random numbers from a variable and assign it to the cvar sv_password ?

heres what i got so far

Code:
public password_generator() {     new password         password = random_num( 0,5 )     server_cmd("sv_password",password )         return PLUGIN_HANDLED }

thanks

WaZZeR++ 05-26-2005 09:46

maybe:
Code:
    server_cmd("sv_password %s",password )

Basic-Master 05-26-2005 10:02

Re: Assigning variables to cvars
 
Code:
public password_generator() {     new password[2] // this is a string with 2 slots         num_to_str(random_num( 0,5 ), password, 1) // assign random value to string     set_cvar_string("sv_password", password) // set cvar         return PLUGIN_HANDLED }

Anthraxnz 05-26-2005 10:50

thanks will give that a try

Anthraxnz 05-26-2005 11:09

thanks that works fine, but does any one have any ideas on how to fill the array with say 5 random numers?

i tried to use a while loop and feed it into the array that way, but it didnt work :(

was something like this
Code:
new i while ( password[i] != 5 ) {     num_to_str(random_num( 0,9 ), password[ i ], 1)         i++ } set_cvar_string("sv_password", password)

WaZZeR++ 05-26-2005 11:31

hevt you set pasword to 5 arrays?
new password[4]

and why have password in the while, try to use ( i <= 5 )

Anthraxnz 05-26-2005 11:33

i got this so far
Code:
public password_generator() {     new password[5]         num_to_str(random_num( 0,9 ), password, 5)     set_cvar_string("sv_password", password)         client_print(0, print_chat, "Server Password is: %s",password)     client_print(0, print_chat, "Server Password is: %s",password)     client_print(0, print_chat, "Server Password is: %s",password)     client_print(0, print_chat, "Server Password is: %s",password)     client_print(0, print_chat, "Server Password is: %s",password)          return PLUGIN_HANDLED   }

this works fine but its only puts one integer into the variable password.
Any ideas?

Anthraxnz 05-26-2005 22:40

never mind i did a more basic way, just assigned 1 random number to each space in the array by putting that random number code 5 times
Code:
    new password[6]             num_to_str(random_num( 0,9 ), password[0], 1)     num_to_str(random_num( 0,9 ), password[1], 1)     num_to_str(random_num( 0,9 ), password[2], 1)     num_to_str(random_num( 0,9 ), password[3], 1)     num_to_str(random_num( 0,9 ), password[4], 1)

Basic-Master 05-27-2005 04:58

this works well, too:
Code:
new password[6] // 5 chars num_to_str(random_num(10000,99999), password, 5) set_cvar_string("sv_password", password) client_print(0, print_chat, "Server password is now: %s", password)


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

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