AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   get user name for comparing (https://forums.alliedmods.net/showthread.php?t=40842)

shino 07-04-2006 16:16

get user name for comparing
 
so, i would like to get player's name and compare it with the name of player i have picked when he wrote something. here's the code:
Code:
new TA[32],LA[32],LeaderA[32],CheckSay[128],TeamA,TeamALeaderDefined,BCTeamARdy public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);     register_cvar("bc_teamA","NiP");     register_clcmd("say","check");     BCTeamARdy = 0     TeamALeaderDefined = 0     get_cvar_string("bc_teamA",TeamA,31); } public check(id) {     read_args( CheckSay, 127 );     remove_quotes( CheckSay );     format(LA,31,"!leader %s",TeamA);     format(TA,31,"%s ready",TeamA);     if(equal(CheckSay,LA)) {         TeamALeaderDefined = 1         get_user_name(id,LeaderA,31); // *** got his name ***         server_cmd("say %s has become leader of %s.",LeaderA,TeamA);         client_print(id,print_center,"It is very important for you to not rename from now on!");     }     if(TeamALeaderDefined == 1) {         if(equal(get_user_info(id,"name"),LeaderA)) { // here's the problem             if(equal(CheckSay,TA)) {                 BCTeamARdy = 1                 client_print(0,print_chat,"%s is ready!",TeamA );                 set_cvar_num("sv_restartround",2);             }         } else {             client_print(id,print_chat,"You are not authorized for this action")         }     } }

this is just a part of the code, so i might forgot some things.

how should i get his name?

L0neW0lf 07-04-2006 18:13

Re: get user name for comparing
 
You could use get_user_name(id, name[], len)

An example:
new name[18]
get_user_name(id, name, 17
)
client_print(id, print_chat, "Your name is: %s", name)

L0neW0lf 07-04-2006 18:17

Re: get user name for comparing
 
Prematuer post can be deleted!

L0neW0lf 07-04-2006 18:17

Re: get user name for comparing
 
I cant figure out precicly what you want?¿?

But an example how to compare name with your list:

Code:
new name[18] get_user_name(id, name, 17) if(equali(name[17],myName[17]) { //event or function } else { //event or function }


You can use equal instead of equali.
equal is case sensetive
equali is NOT case sensetive

/Lone Wolf

shino 07-05-2006 04:33

Re: get user name for comparing
 
Code:
public check(id) {         new LeadACheck[32]     read_args( CheckSay, 127 );     remove_quotes( CheckSay );     format(LA,31,"!leader %s",TeamA);     format(LB,31,"!leader %s",TeamB);     format(TA,31,"%s ready",TeamA);     format(TB,31,"%s ready",TeamB);     if(equal(CheckSay,LA)) {         TeamALeaderDefined = 1         get_user_name(id,LeaderA,31);         server_cmd("say %s has become leader of %s.",LeaderA,TeamA);         client_print(id,print_center,"It is very important for you to not rename from now on!");     }     if(TeamALeaderDefined == 1) {         if(equal(CheckSay,TA)) {             get_user_name(id,LeadACheck,31);             if(LeadACheck == LeaderA) {                         BCTeamARdy = 1                 client_print(0,print_chat,"%s is ready!",TeamA );                 set_cvar_num("sv_restartround",2);             }         } else {             client_print(id,print_chat,"You are not authorized for this action")         }     } }

when compiling, it shows:
Code:

Error: Array must be indexed (variable "LeadACheck") on line 76

L0neW0lf 07-05-2006 04:51

Re: get user name for comparing
 
Cant se the line numbers, but my guess is that it is this one:
Code:
if(LeadACheck == LeaderA)




Try these i instead:
Code:
if(equal(LeadACheck,LeaderA)) or if(LeadACheck = LeaderA) or if(LeadACheck[31]==LeaderA[31])



I havent figured it completly out the thing about = or == in if's

/Lone Wolf

shino 07-05-2006 04:53

Re: get user name for comparing
 
equal works great, thanks :P

in if's, == must be used

L0neW0lf 07-05-2006 04:54

Re: get user name for comparing
 
No problem :)


All times are GMT -4. The time now is 08:01.

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