SA-MP Forums Archive
show rank when player texts - 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: show rank when player texts (/showthread.php?tid=423180)



show rank when player texts - Eminem 2ka9 - 16.03.2013

This is my code which i cannot seem to get working. It's basically supposed to display the players rank before the players name when they type. (Example: Private John: hello)


This is what i have at the moment.
pawn Код:
public OnPlayerText(playerid, text[])
{
 SetPlayerChatBubble(playerid, text, C_WHITE, 100.0, 10000);
 }
    new text[128];
    new string[128];
    format(string, sizeof(string), "** %s %s [%d]: %s", ClassName(playerid), Name(playerid), playerid, text);
    foreach(Player, i)
    }
return 1;
}



Re: show rank when player texts - Scenario - 16.03.2013

... can you show more of the code please? This doesn't really seem to give the full picture.

Also, include the ClassName function you're using.


Re: show rank when player texts - Eminem 2ka9 - 16.03.2013

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
... can you show more of the code please? This doesn't really seem to give the full picture.

Also, include the ClassName function you're using.
There is nothing else to it... i just may have positioned things incorrectly.
These may be helpful.

pawn Код:
stock RankName(playerid)
{
    new rank = Rank(playerid);
    new rankname[24];
    if(rank == 1) rankname = RANK1NAME;
    if(rank == 2) rankname = RANK2NAME;
    if(rank == 3) rankname = RANK3NAME;
    if(rank == 4) rankname = RANK4NAME;
    if(rank == 5) rankname = RANK5NAME;
    if(rank == 6) rankname = RANK6NAME;
    if(rank == 7) rankname = RANK7NAME;
    if(rank == 8) rankname = RANK8NAME;
    if(rank == 9) rankname = RANK9NAME;
    if(rank == 10) rankname = RANK10NAME;
    if(rank == 11) rankname = RANK11NAME;
    if(rank == 12) rankname = RANK12NAME;
    if(rank == 13) rankname = RANK13NAME;
    if(rank == 14) rankname = RANK14NAME;
    return rankname;
}



Re: show rank when player texts - Jstylezzz - 16.03.2013

You can't do somestring = "thisword", you need to format it.
In this case, you'd do
pawn Код:
if(rank == 1) {format(rankname,24,"%s",RANK1NAME);}



Re: show rank when player texts - Eminem 2ka9 - 16.03.2013

You see, i saw the code from below. The below one just does the same thing, instead it sends it to team chat.
I tried to remove the team chat, and just use it in normal chat.

pawn Код:
CMD:r(playerid, params[])
{
    new text[128];
    if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, C_GREY, "USAGE: /r [text]");

    new string[128];
    format(string, sizeof(string), "** %s %s [%d]: %s **", ClassName(playerid), Name(playerid), playerid, text);
    foreach(Player, i)
    {
        if(gTeam[playerid] == gTeam[i])
        {
            SendClientMessage(i, C_RADIOBLUE, string);
        }
    }
    return 1;
}



Re: show rank when player texts - Vince - 16.03.2013

Quote:
Originally Posted by Jari_Johnson*
Посмотреть сообщение
You can't do somestring = "thisword", you need to format it.
In this case, you'd do
pawn Код:
if(rank == 1) {format(rankname,24,"%s",RANK1NAME);}
False.


Re: show rank when player texts - Scenario - 16.03.2013

@Jari_Johnson*: I believe you can when doing it like he is, actually...

@OP: Use switch statements, they're much easier. Also, when doing several if statements, use if else, not just if. With the code under OnPlayerText, you were closing the OnPlayerText callback at the wrong time. You also simply formatted a string and didn't do anything to it. You opened up a loop with foreach, but (1) didn't need it and (2) didn't use it. Finally, you continued to "return 1", but when you don't want the standard message to send, you have to "return 0."

This should work, but it hasn't been tested!

pawn Код:
stock RankName(playerid) // returns the rankname on success, or 0/false on failure
{
    switch(Rank(playerid))
    {
        case 1: return RANK1NAME;
        case 2: return RANK2NAME;
        case 3: return RANK3NAME;
        case 4: return RANK4NAME;
        case 5: return RANK5NAME;
        case 6: return RANK6NAME;
        case 7: return RANK7NAME;
        case 8: return RANK8NAME;
        case 9: return RANK9NAME;
        case 10: return RANK10NAME;
        case 11: return RANK11NAME;
        case 12: return RANK12NAME;
        case 13: return RANK13NAME;
        case 14: return RANK14NAME;
    }
    return false;
}

public OnPlayerText(playerid, text[])
{
    SetPlayerChatBubble(playerid, text, C_WHITE, 100.0, 10000);

    new
        text[128],
        string[128]
    ;
   
    format(string, sizeof(string), "** %s %s [%d]: %s", RankName(playerid), Name(playerid), playerid, text);
    SendClientMessageToAll(C_WHITE, string);
    return 0;
}



Re: show rank when player texts - Eminem 2ka9 - 16.03.2013

@Realcop - I added your RankName stock instead of mine, and replaced your OnPlayerText with mine, but my compiler crashed.

I put back my original stock, and only added your OnPlayerText, and i only got 1 warning.

pawn Код:
warning 219: local variable "text" shadows a variable at a preceding level
This is the line:
pawn Код:
text[128],



Re: show rank when player texts - Eminem 2ka9 - 16.03.2013

I ran the game.. the rank appears but, my text doesn;t.


Re: show rank when player texts - Bicentric - 16.03.2013

Quote:
Originally Posted by Eminem 2ka9
Посмотреть сообщение
@Realcop - I added your RankName stock instead of mine, and replaced your OnPlayerText with mine, but my compiler crashed.

I put back my original stock, and only added your OnPlayerText, and i only got 1 warning.

pawn Код:
warning 219: local variable "text" shadows a variable at a preceding level
This is the line:
pawn Код:
text[128],
You're getting that warning because you're using the variable 'text' twice.

pawn Код:
public OnPlayerText(playerid, text[]) //In the callback header here
{
    SetPlayerChatBubble(playerid, text, C_WHITE, 100.0, 10000);

    new
        text[128], //And you're also defining it here, how will the compiler know which one from which?
        string[128]
    ;
   
    format(string, sizeof(string), "** %s %s [%d]: %s", RankName(playerid), Name(playerid), playerid, text);
    SendClientMessageToAll(C_WHITE, string);
    return 0;
}
Since you're not using it, the best solution is to remove it.

pawn Код:
public OnPlayerText(playerid, text[]) //In the callback header here
{
    SetPlayerChatBubble(playerid, text, C_WHITE, 100.0, 10000);

    new
        string[128]
    ;
   
    format(string, sizeof(string), "** %s %s [%d]: %s", RankName(playerid), Name(playerid), playerid, text);
    SendClientMessageToAll(C_WHITE, string);
    return 0;
}