SA-MP Forums Archive
CMD player name... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: CMD player name... (/showthread.php?tid=609082)



CMD player name... - xxxSpeedxxx - 08.06.2016

Can i make this cmd check if the player name is example Red_John and if it is let him use it.Only him!

PHP код:
COMMAND:glazba(playerid,params[])
{
    
    if (
APlayerData[playerid][LoggedIn] == true && APlayerData[playerid][PlayerLevel] > 4)
    {
        new 
Link[128];
        if(
sscanf(params"s[128]"Link)) return SendClientMessage(playerid0xFF0000FF"{FF0000}Komanda:{FF0000} {FFFFFF}/Glazba <Link> {FFFFFF}");
        for (new 
i=0MAX_PLAYERSi++)
        {
            if(
IsPlayerConnected(i) && !IsPlayerNPC(i)){
                
PlayAudioStreamForPlayer(iLink);
            }
        }
        return 
1;
    }
    return 
0;




Re: CMD player name... - Stinged - 08.06.2016

To make the actual command, you only need GetPlayerName and strcmp

But the command I posted has everything fixed and done better.
I'll explain everything in // comments.

Код:
COMMAND:glazba(playerid,params[])
{
    if (APlayerData[playerid][LoggedIn] == true && APlayerData[playerid][PlayerLevel] > 4)
    {
        new player_name[24];
        GetPlayerName(playerid, player_name, sizeof (player_name));
        if (!strcmp(player_name, "Red_John", false))
        {
            // zcmd has "params[]", which is already a string.
            // You shouldn't use sscanf when you only want to use a string.
            if (isnull(params)) return SendClientMessage(playerid, 0xFF0000FF, "Komanda: {FFFFFF}/Glazba ");
            // Your old SendClientMessage was this:
            // SendClientMessage(playerid, 0xFF0000FF, "{FF0000}Komanda:{FF0000} {FFFFFF}/Glazba {FFFFFF}");
            // What it meant was:
            // RED REDKomanda:RED WHITE/Glazba WHITE
            // While mine means: REDKomanda: WHITE/Glazba 
            for (new i=0; i < MAX_PLAYERS; i++)
            {
                (IsPlayerConnected(i) && !IsPlayerNPC(i))
                {
                    PlayAudioStreamForPlayer(i, params);
                }
            }
        }
        return 1;
    }
    return 0;
}



Re: CMD player name... - Gammix - 08.06.2016

Use https://sampwiki.blast.hk/wiki/Strcmp

pawn Код:
if (!strcmp("Red_John", name))
{
    // Yes he is Red_John
}
else
{
    // No he ain't
}



Re: CMD player name... - xxxSpeedxxx - 08.06.2016

Quote:
Originally Posted by Stinged
Посмотреть сообщение
To make the actual command, you only need GetPlayerName and strcmp

But the command I posted has everything fixed and done better.
I'll explain everything in // comments.

Код:
COMMAND:glazba(playerid,params[])
{
    if (APlayerData[playerid][LoggedIn] == true && APlayerData[playerid][PlayerLevel] > 4)
    {
        new player_name[24];
        GetPlayerName(playerid, player_name, sizeof (player_name));
        if (!strcmp(player_name, "Red_John", false))
        {
            // zcmd has "params[]", which is already a string.
            // You shouldn't use sscanf when you only want to use a string.
            if (isnull(params)) return SendClientMessage(playerid, 0xFF0000FF, "Komanda: {FFFFFF}/Glazba ");
            // Your old SendClientMessage was this:
            // SendClientMessage(playerid, 0xFF0000FF, "{FF0000}Komanda:{FF0000} {FFFFFF}/Glazba {FFFFFF}");
            // What it meant was:
            // RED REDKomanda:RED WHITE/Glazba WHITE
            // While mine means: REDKomanda: WHITE/Glazba 
            for (new i=0; i < MAX_PLAYERS; i++)
            {
                (IsPlayerConnected(i) && !IsPlayerNPC(i))
                {
                    PlayAudioStreamForPlayer(i, params);
                }
            }
        }
        return 1;
    }
    return 0;
}
This error
Код:
C:\Users\NeXuS\Desktop\ng\include\PlayerCommands.inc(39 -- 40) : error 029: invalid expression, assumed zero
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Here
Код:
                (IsPlayerConnected(i) && !IsPlayerNPC(i))
                {
                    PlayAudioStreamForPlayer(i, params)
What's the problem?


Re: CMD player name... - Konstantinos - 08.06.2016

Код:
if (IsPlayerConnected(i) && !IsPlayerNPC(i))
At least use player pool since you don't use foreach/y_iterate:
pawn Код:
// replace:
for (new i=0; i < MAX_PLAYERS; i++)
// with:
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
which is faster.