AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   set randomly a name to each player (https://forums.alliedmods.net/showthread.php?t=245771)

internel 08-06-2014 17:35

set randomly a name to each player
 
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?

Flick3rR 08-06-2014 18:28

Re: set randomly a name to each player
 
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 


internel 08-06-2014 19:44

Re: set randomly a name to each player
 
that's exactly what I was talking about!!! thank you so much :D!

internel 08-06-2014 21:00

Re: set randomly a name to each player
 
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?

fysiks 08-06-2014 21:49

Re: set randomly a name to each player
 
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.

internel 08-07-2014 19:04

Re: set randomly a name to each player
 
Quote:

Originally Posted by fysiks (Post 2180103)
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 :D

thanks fysiks and Flick3rR for answering :)


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

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