AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   auto-name change problem (https://forums.alliedmods.net/showthread.php?t=140564)

xiaojian 10-14-2010 00:05

auto-name change problem
 
Use rename.ini file to change one's name,rename.ini is like this
PHP Code:

;currentname newname
name1 newname1
name2 newname2 


Hunter-Digital 10-14-2010 00:33

Re: need help,Thanks
 
Well, try to go through the loop to understand...

You're changing the player name to default name on each fail to compare the name, you should use somethnig to detect if the name wasn't changed.

Code:

new bool:changed = false

for(new i =0; i < g_totalNames; i++)
{
  if(equali(name, g_szName[i]))
  {
      set_user_info(id, "name", g_NewName[i])
      changed = true /* note that the name was changed */
      break /* stop the loop */
  }
}

if(!changed) /* if player's name wasn't in the list, set to default name */
  set_user_info(id, "name", g_DefaultName)

You should also stick to hungarian notation or NOT, because you note some and some not... wich is quite confusing.

You should also provide a informative title about what the problem is, I was one step away from skipping this thread if I wasn't so bored :}

Hunter-Digital 10-14-2010 04:05

Re: need help,Thanks
 
A short name about the thread's text, that's a title, in your case: "naming problem", "name loop problem", "auto-name change problem", etc.

This is scripting help not requests and you obviously didn't learn anything since you just placed my code inside a loop when I deliberly posted the loop so you'll see that there are some things that must NOT be in the loop... but now you're back to your initial problem.

And client_infochanged() is called when a player changes his name... or any other information using setinfo or such, you might want to search for the corect info getting methods.

xiaojian 10-14-2010 04:19

Re: auto-name change problem
 
i chaged the title.
when a player changes his name,my idea is :if his new name isn't in the name list of name.ini ,then plugin handled.

Hunter-Digital 10-14-2010 04:20

Re: auto-name change problem
 
Then why do you keep changing it to default name ?
Do you even understand what those codes do ?

xiaojian 10-14-2010 05:08

Re: auto-name change problem
 
Quote:

Originally Posted by Hunter-Digital (Post 1324369)
Then why do you keep changing it to default name ?
Do you even understand what those codes do ?

i just wonder why
if (equali(name, g_szName[i]))
{
//
}
else
{
//
} is useless.
i want to learn how to make it sense.

Hunter-Digital 10-14-2010 05:18

Re: auto-name change problem
 
Quote:

Originally Posted by xiaojian (Post 1324382)
i just wonder why
if (equali(name, g_szName[i]))
{
//
}
else
{
//
} is useless.
i want to learn how to make it sense.

Quote:

Originally Posted by Hunter-Digital (Post 1324293)
You're changing the player name to default name on each fail to compare the name ...

I guess you don't understand LOOPS, that code is executed multiple times, and if you use an else and change the name there, it would change the name every time the if() is not true, it's logic.

I also added comments to the code to reinforce the information.

And I didn't said it's useless, I just explained your issue.

If you don't really know anything about amxx scripting I recommend you start reading the pawn tutorial: http://wiki.amxmodx.org/Pawn_Tutorial

xiaojian 10-14-2010 05:44

Re: auto-name change problem
 
Quote:

Originally Posted by Hunter-Digital (Post 1324391)
I guess you don't understand LOOPS, that code is executed multiple times, and if you use an else and change the name there, it would change the name every time the if() is not true, it's logic.

I also added comments to the code to reinforce the information.

And I didn't said it's useless, I just explained your issue.

If you don't really know anything about amxx scripting I recommend you start reading the pawn tutorial: http://wiki.amxmodx.org/Pawn_Tutorial

thank you!


All times are GMT -4. The time now is 10:28.

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