Raised This Month: $ Target: $400
 0% 

set randomly a name to each player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
internel
Member
Join Date: Nov 2012
Old 08-06-2014 , 17:35   set randomly a name to each player
Reply With Quote #1

I need some help with this >.<, I'm want to set to each player a Name/Tag/etc, for example:

PHP Code:
enum {
    
London,
    
Manchester,
    
Liverpool,
    
Glasgow,
    
Dundee,
    
Aberdeen,
    
Paris,
    
Berlin,
    
//And so on... Until we have 32 different names

But the name that the player gets, can't repeat with another client. So, let's say, I'm London but there can't be another player called London.

I'm trying to figure up, but I don't get anywhere >.<, any help please?
internel is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-06-2014 , 18:28   Re: set randomly a name to each player
Reply With Quote #2

Well, worked fine on first view. Had no time to get in details. Just have to replace all the names with your ones.
PHP Code:
#include <amxmodx>

const MAXPLAYERS 33

public plugin_init()
{
    
register_plugin("Some Random Names""1.0""Flicker")
}

new 
NameIndex[MAXPLAYERS]

new const 
g_szNames[MAXPLAYERS 1][]=
{
    
"name1",
    
"name2",
    
"name3",
    
"name4",
    
"name5",
    
"name6",
    
"name7",
    
"name8",
    
"name9",
    
"name10",
    
"name11",
    
"name12",
    
"name13",
    
"name14",
    
"name15",
    
"name16",
    
"name17",
    
"name18",
    
"name19",
    
"name20",
    
"name21",
    
"name22",
    
"name23",
    
"name24",
    
"name25",
    
"name26",
    
"name27",
    
"name28",
    
"name29",
    
"name30",
    
"name31",
    
"name32"
}

new 
bool:NameUsed[sizeof g_szNames]

public 
client_putinserver(id)
{
    new 
iRand random(sizeof g_szNames)
    
    while(
NameUsed[iRand])
        
iRand random(sizeof g_szNames)
    
    
set_user_info(id"name"g_szNames[iRand])
    
    
NameUsed[iRand] = true
    NameIndex
[id] = iRand
}

public 
client_disconnect(id)
    
NameUsed[NameIndex[id]] = false 
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
internel
Member
Join Date: Nov 2012
Old 08-06-2014 , 19:44   Re: set randomly a name to each player
Reply With Quote #3

that's exactly what I was talking about!!! thank you so much !
internel is offline
internel
Member
Join Date: Nov 2012
Old 08-06-2014 , 21:00   Re: set randomly a name to each player
Reply With Quote #4

sorry for the double post, but I need some help with this again. I'm playing with it and tried to set the name into a var. So when the round starts, each player receives a message saying his/her name.

"Your name is London/Manchester/Hong-Kong/Santiago"

But it only says the number of the name and not the word. (Like "Your name is 9" instead of "Your name is name9")

PHP Code:
#include <amxmodx>
#include <fun>

const MAXPLAYERS 33

new NameIndex[MAXPLAYERS]

new 
name[33]

new const 
g_szNames[MAXPLAYERS 1][]=
{
    
"name1",
    
"name2",
    
"name3",
    
"name4",
    
"name5",
    
"name6",
    
"name7",
    
"name8",
    
"name9",
    
"name10",
    
"name11",
    
"name12",
    
"name13",
    
"name14",
    
"name15",
    
"name16",
    
"name17",
    
"name18",
    
"name19",
    
"name20",
    
"name21",
    
"name22",
    
"name23",
    
"name24",
    
"name25",
    
"name26",
    
"name27",
    
"name28",
    
"name29",
    
"name30",
    
"name31",
    
"name32"
}

new 
bool:NameUsed[sizeof g_szNames]

public 
plugin_init()
{
    
register_plugin("Names""1.0""Flicke3rR")
    
register_logevent("logevent_round_start"2"1=Round_Start")
    
}

public 
logevent_round_start()
{
    for (new 
id 0id 1id++)
    {
        new 
iRand random(sizeof g_szNames)
        while(
NameUsed[iRand])
            
iRand random(sizeof g_szNames)
            
        
name[id] = iRand
            
        NameUsed
[iRand] = true
        NameIndex
[id] = iRand
        client_print
(idprint_chat"Your name is %s"name[id])
    }
    return 
PLUGIN_HANDLED;
}

public 
client_disconnect(id)
    
NameUsed[NameIndex[id]] = false 
Any ideas?

Last edited by internel; 08-06-2014 at 21:01.
internel is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-06-2014 , 21:49   Re: set randomly a name to each player
Reply With Quote #5

name[id] should instead be g_szNames[NameIndex[id]]

Oh, and you never set the user's name.

Also, if you are going to re-assign names on every round, you need to reset the NameUsed array to false.

You should remove entirely the "name" array. It serves no purpose.
__________________

Last edited by fysiks; 08-06-2014 at 21:57.
fysiks is offline
internel
Member
Join Date: Nov 2012
Old 08-07-2014 , 19:04   Re: set randomly a name to each player
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
name[id] should instead be g_szNames[NameIndex[id]]

Oh, and you never set the user's name.

Also, if you are going to re-assign names on every round, you need to reset the NameUsed array to false.

You should remove entirely the "name" array. It serves no purpose.
thank you!! , that helped

thanks fysiks and Flick3rR for answering
internel is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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