Help with this commands
#1

Hello,i've this 2 commands:

pawn Код:
CMD:nameon(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, true);
    GameTextForPlayer(playerid, "~W~Nametags ~g~On", 5000, 5);
    return 1;
}

CMD:nameoff(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, false);
    GameTextForPlayer(playerid, "~W~Nametags ~R~OFF", 5000, 5);
    return 1;
}
The problem is: How to fuse this 2 commands in only one?So if player use /name,nametags will show,if he type again /name,it will be hided.How?
Reply
#2

You need a variable, to see if the player has nametags on or off:
pawn Код:
new bool: pNames[MAX_PLAYERS];

CMD:name(playerid, params[])
{
    if(pNames[playerid] == false)
    {
        for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, false);
        GameTextForPlayer(playerid, "~W~Nametag ~g~On", 5000, 5);
        pNames[playerid] = true; // which means the player can see names now
    }
    else
    {
        for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, false);
        GameTextForPlayer(playerid, "~W~Nametags ~R~OFF", 5000, 5);
        pNames[playerid] = false; // Which means the player can't see name tags now.
    }
    return 1;
}
Don't forget about:
pawn Код:
public OnPlayerStreamIn(playerid, forplayerid)
Reply
#3

Quote:
Originally Posted by antonio112
Посмотреть сообщение
You need a variable, to see if the player has nametags on or off:
pawn Код:
new bool: pNames[MAX_PLAYERS];

CMD:name(playerid, params[])
{
    if(pNames[playerid] == false)
    {
        for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, false);
        GameTextForPlayer(playerid, "~W~Nametag ~g~On", 5000, 5);
        pNames[playerid] = true; // which means the player can see names now
    }
    else
    {
        for(new i = 0; i < MAX_PLAYERS; i++) ShowPlayerNameTagForPlayer(playerid, i, false);
        GameTextForPlayer(playerid, "~W~Nametags ~R~OFF", 5000, 5);
        pNames[playerid] = false; // Which means the player can't see name tags now.
    }
    return 1;
}
Ahh,thank you!
Reply
#4

Could also be done using this:
Код:
new bool:NameTag[MAX_PLAYERS];

CMD:name(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    if(NameTag[playerid] == false)
    {
    ShowPlayerNameTagForPlayer(playerid, i, true);
    GameTextForPlayer(playerid, "~W~Nametags ~g~On", 5000, 5);
    NameTag[playerid] = true;
    }else{
    ShowPlayerNameTagForPlayer(playerid,i,false);
    GameTextForPlayer(playerid, "~W~Nametags ~r~off", 5000, 5);
    NameTag[playerid] = false;
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by peugeot
Посмотреть сообщение
Could also be done using this:
Код:
new bool:NameTag[MAX_PLAYERS];

CMD:name(playerid, params[])
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    if(NameTag[i] == false)
    {
    ShowPlayerNameTagForPlayer(playerid, i, true);
    GameTextForPlayer(playerid, "~W~Nametags ~g~On", 5000, 5);
    NameTag[i] = true;
    }else{
    ShowPlayerNameTagForPlayer(playerid,i,false);
    GameTextForPlayer(playerid, "~W~Nametags ~r~off", 5000, 5);
    NameTag[i] = false;
    }
    return 1;
}
No it couldn't. The way you did it, it's that when I type /name, it hides my name, so other players can't see it.

What the author asked for, is when he types /name, he won't see other players name. So yea, it's not the same.
Reply
#6

I accidently, added "i" to the other var though, but you dont have to use for(new i = 0; i < MAX_PLAYERS; i++) twice thats what I meant, I used it only once at top instead of adding it to both "cases".
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)