SA-MP Forums Archive
What's wrong with this name on/off cmd - 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: What's wrong with this name on/off cmd (/showthread.php?tid=403327)



What's wrong with this name on/off cmd - Fiore - 29.12.2012

It doesnt give errors, just doesnt work.

pawn Код:
CMD:name(playerid, params[])
{
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(PlayerInfo[playerid][pLevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You must be level 3+ to use this command.");
    if(sscanf(params, "u", playerid)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /name [on]/[off]");
    if(!strcmp(params, "on", true))
    {
        SendClientMessage(playerid,COLOR_LIME,"[NAME] Your name has been successfully hidden !");
        GameTextForPlayer(playerid,"~r~showname off",3000,1);
        for(new i = 0; i != MAX_PLAYERS; i++)
        {
            ShowPlayerNameTagForPlayer(i, playerid, 0);
        }
    }
    else if(!strcmp(params, "off", true))
    {
        SendClientMessage(playerid,COLOR_LIME,"[NAME] Your name has been successfully unhidden !");
        GameTextForPlayer(playerid,"~g~showname on",3000,1);
        for(new i = 0; i != MAX_PLAYERS; i++)
        {
            ShowPlayerNameTagForPlayer(i, playerid, 1);
        }
    }
    return 1;
}



Re: What's wrong with this name on/off cmd - aslan890 - 29.12.2012

Quote:
Originally Posted by Fiore
Посмотреть сообщение
It doesnt give errors, just doesnt work.

pawn Код:
CMD:name(playerid, params[])
{
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(PlayerInfo[playerid][pLevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You must be level 3+ to use this command.");
    if(sscanf(params, "u", playerid)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /name [on]/[off]");
    if(!strcmp(params, "on", true))
    {
        SendClientMessage(playerid,COLOR_LIME,"[NAME] Your name has been successfully hidden !");
        GameTextForPlayer(playerid,"~r~showname off",3000,1);
        for(new i = 0; i != MAX_PLAYERS; i++)
        {
            ShowPlayerNameTagForPlayer(i, playerid, 0);
        }
    }
    else if(!strcmp(params, "off", true))
    {
        SendClientMessage(playerid,COLOR_LIME,"[NAME] Your name has been successfully unhidden !");
        GameTextForPlayer(playerid,"~g~showname on",3000,1);
        for(new i = 0; i != MAX_PLAYERS; i++)
        {
            ShowPlayerNameTagForPlayer(i, playerid, 1);
        }
    }
    return 1;
}
Try this:

Код:
CMD:name(playerid, params[])
{
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(PlayerInfo[playerid][pLevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You must be level 3+ to use this command.");
    if(sscanf(params, "ui", playerid)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /name [on]/[off]");
    if(!strcmp(params, "on", true))
    {
        SendClientMessage(playerid,COLOR_LIME,"[NAME] Your name has been successfully hidden !");
        GameTextForPlayer(playerid,"~r~showname off",3000,1);
        for(new i = 0; i != MAX_PLAYERS; i++)
        {
            ShowPlayerNameTagForPlayer(i, playerid, 0);
        }
    }
    else if(!strcmp(params, "off", true))
    {
        SendClientMessage(playerid,COLOR_LIME,"[NAME] Your name has been successfully unhidden !");
        GameTextForPlayer(playerid,"~g~showname on",3000,1);
        for(new i = 0; i != MAX_PLAYERS; i++)
        {
            ShowPlayerNameTagForPlayer(i, playerid, 1);
        }
    }
    return 1;
}



Re: What's wrong with this name on/off cmd - Fiore - 29.12.2012

Doesn't work, any suggestions?


Re: What's wrong with this name on/off cmd - aslan890 - 29.12.2012

Quote:
Originally Posted by Fiore
Посмотреть сообщение
Doesn't work, any suggestions?
Sorry don't know


Re: What's wrong with this name on/off cmd - Threshold - 29.12.2012

Well first of all, you are using the sscanf parameter 'u' to retrieve a string such as 'on' and 'off'. The u parameter is specifically used for playerids/parts of player names.

You need to change this to s.
pawn Код:
CMD:name(playerid, params[])
{
    new string[5];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(PlayerInfo[playerid][pLevel] < 3) return SendClientMessage(playerid, COLOR_GREY, "You must be level 3+ to use this command.");
    if(sscanf(params, "s", string)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /name [on]/[off]");
    if(strcmp(string, "on", true) == 0)
    {
        SendClientMessage(playerid,COLOR_LIME,"[NAME] Your name has been successfully hidden !");
        GameTextForPlayer(playerid,"~r~showname off",3000,1);
        for(new i = 0; i != MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                ShowPlayerNameTagForPlayer(i, playerid, 0);
            }
        }
    }
    else if(strcmp(string, "off", true) == 0)
    {
        SendClientMessage(playerid,COLOR_LIME,"[NAME] Your name has been successfully unhidden !");
        GameTextForPlayer(playerid,"~g~showname on",3000,1);
        for(new i = 0; i != MAX_PLAYERS; i++)
        {
            if(IsPlayerConnected(i))
            {
                ShowPlayerNameTagForPlayer(i, playerid, 1);
            }
        }
    }
    else return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /name [on]/[off]");
    return 1;
}