AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   about id = str_to_num (https://forums.alliedmods.net/showthread.php?t=125960)

epic . 05-04-2010 01:12

about id = str_to_num
 
Code:

public plugin_init()
{
    register_srvcmd("bot","bot_interface")
}
 
public bot_interface()
{
    new sid[8],id
    read_argv(1,sid,7)
    id = str_to_num(sid)
    A_function(id)
 
    return PLUGIN_CONTINUE
}

What does the "id" means here ?

wrecked_ 05-04-2010 01:20

Re: about id = str_to_num
 
It's a player index. For example, if sid was equal to "27", id would be 27. It converts the string to a number and stores the numerical value in id.

epic . 05-04-2010 01:33

Re: about id = str_to_num
 
I still confused.
What`s the difference between this :
Code:

public bot_interface()
{
    for ( new i = 0 ; i < iNum ; i++ )
    {
        id = iPlayers[i];
    }
}


joaquimandrade 05-04-2010 01:38

Re: about id = str_to_num
 
Quote:

Originally Posted by epic . (Post 1169862)
I still confused.
What`s the difference between this :
Code:

public bot_interface()
{
    for ( new i = 0 ; i < iNum ; i++ )
    {
        id = iPlayers[i];
    }
}


In the first situation, a command executed in the console by a player is being processed. Like if you do in console

Code:

command 27
The id is in the middle of a string, so it is converted from a string to a number. "27" becomes 27.

In the second situation you are using a loop that is used to do some action over all players (using their ID's).

Basically, "ID" means the same in both examples but its used in different contexts.

epic . 05-04-2010 02:03

Re: about id = str_to_num
 
Thanks for help. The matter is : There is a plugin use the code that I posted in the thread, to make Bots do a function.
It just "new sid[8]", it doesn`t equal sid[8] to any numbers, how can the "A_function" know the "id" is the bots?

K.K.Lv 05-04-2010 03:44

Re: about id = str_to_num
 
Quote:

Originally Posted by epic . (Post 1169862)
I still confused.
What`s the difference between this :
Code:

public bot_interface()
{
    for ( new i = 0 ; i < iNum ; i++ )
    {
        id = iPlayers[i];
    }
}


I think you can do like this :
PHP Code:

public bot_interface()
{
    static 
rag[8]
    
read_ragv(1rag7)
    for ( new 
iNum i++ )
    {
        
id iPlayers[i];
        if (
id == str_to_num(rag))
                
A_function(id)
                break
    }


but I think it's not a good way !:mrgreen:
so you need not to use loop !

fysiks 05-04-2010 18:00

Re: about id = str_to_num
 
Quote:

Originally Posted by epic . (Post 1169851)
Code:

public plugin_init()
{
    register_srvcmd("bot","bot_interface")
}
 
public bot_interface()
{
    new sid[8],id
    read_argv(1,sid,7)
    id = str_to_num(sid)
    A_function(id)
 
    return PLUGIN_CONTINUE
}

What does the "id" means here ?

Quote:

Originally Posted by wrecked_ (Post 1169856)
It's a player index. For example, if sid was equal to "27", id would be 27. It converts the string to a number and stores the numerical value in id.

You are assuming the first argument is a player id because he used the variable name "id". But, infact, it will be what ever string is passed as the first argument of the server command that which is then converted to a integer. So, if you type in

Code:

bot 12325434
id will be 12325434 which definitely is not a player id.


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

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