Question!
#1

Hello guys, is there a command that print a part of my name. Just the first letter, Like if my name is Marcus Bauer. What will be the cmd, to show just "M"
Reply
#2

pawn Код:
//Command
{  
    new playerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
    strdel(playerName, 1, strlen(playerName));
    print(playerName);
}
Reply
#3

pawn Код:
stock ShortenName(playerid)
{
    new PlayerName[MAX_PLAYER_NAME];
    new Find, Final;
    GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
    Find = strfind(PlayerName, "_", false, 1);
    Final = strdel(PlayerName, 1, Find+1);
    return Final;
}
If you want to shorten their name, just use ShortenName(playerid);

Supposing that you are using the name Marcus_Bauer, this function will return M_Bauer
Reply
#4

Example of it's use in a script:
pawn Код:
if(strcmp(cmdtext, "/announce", true, 9) == 0)
{
    new string[256];
    format(string,sizeof(string),"%s has announced something.",ShortenName(playerid));
    SendClientMessageToAll(0xFF0000AA, string);
    return 1;
}
Reply
#5

I want to shorten Marcus_Bauer, like this:
M. Bauer
Is it possible?
Thank you all for the responses.
Reply
#6

Quote:
Originally Posted by PhoeNiX778
Посмотреть сообщение
I want to shorten Marcus_Bauer, like this:
M. Bauer
Is it possible?
Thank you all for the responses.
Well, i dont think you can.
Reply
#7

Can you test the code I gave you? What does it say when you use the command? I want to make sure I've done it right before finishing off this code.
Reply
#8

pawn Код:
stock GetPlayerShortName(playerid)
{
    new playerName[MAX_PLAYER_NAME], findString;
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
    findString = strfind(playerName, "_", true);
    if(findString != 0)
    {
        strdel(playerName, 1, findString+1);
        strins(playerName, ". ", 1);
    }
    return playerName;
}
If my name is RuiGy_Chan, it returns R. Chan.
The use is the same of clarencecuzz's code.
Reply
#9

Thank you RuiGy. What to do to make this work. Here is my script:
Код:
 if(strcmp(cmd, "/radio", true) == 0 || strcmp(cmd, "/r", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			GetPlayerName(playerid, sendername, sizeof(sendername));
			GiveNameSpace(sendername);
			if(PlayerInfo[playerid][pMaskUse] == 1) { format(sendername, sizeof(sendername), "Stranger_%d", PlayerInfo[playerid][pRandMask]); }
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[128];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/r)adio [radio chat]");
				return 1;
			}
			if(PlayerInfo2[Mute][playerid] == 1)
			{
				SendClientMessage(playerid, TEAM_CYAN_COLOR, "   You can't speak, you have been silenced !");
				return 1;
			}
			if(PlayerInfo[playerid][pJailed] > 0)
			{
				SendClientMessage(playerid, TEAM_CYAN_COLOR, "[INFO]: your radio has been confesgated, You will receive it at the front.");
				return 1;
			}
			if (PlayerInfo[playerid][pMember] == 9)
	        {
	        	SendClientMessage(playerid, COLOR_GREY, " Faction radio has been closed !");
				return 1;
	        }
		    if(PlayerInfo[playerid][pMember] > 0)
			{
			    format(string, sizeof(string), "** %s(radio): %s, over. **", sendername, result);
				ProxRadio(20.0, playerid, string);
				SendRadioMessage(PlayerInfo[playerid][pMember], TEAM_BLUE_COLOR, string);
				return 1;
		    }
			else
			{
				SendClientMessage(playerid, COLOR_GRAD2, "   You are not part of a Faction !");
				return 1;
			}
		}
		return 1;
	}
I want when I type /r Text . To print this: ** M. Bauer(radio): Text,over.**
Thank you all.
Reply
#10

pawn Код:
stock GetPlayerShortName(playerid)
{
    new playerName[MAX_PLAYER_NAME], findString;
    GetPlayerName(playerid, playerName, MAX_PLAYER_NAME);
    findString = strfind(playerName, "_", true);
    if(findString != 0)
    {
        strdel(playerName, 1, findString+1);
        strins(playerName, ". ", 1);
    }
    return playerName;
}

if(strcmp(cmd, "/radio", true) == 0 || strcmp(cmd, "/r", true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        GetPlayerName(playerid, sendername, sizeof(sendername));
        GiveNameSpace(sendername);
        if(PlayerInfo[playerid][pMaskUse] == 1) { format(sendername, sizeof(sendername), "Stranger_%d", PlayerInfo[playerid][pRandMask]); }
        new length = strlen(cmdtext);
        while ((idx < length) && (cmdtext[idx] <= ' ')){ idx++; }
        new offset = idx;
        new result[128];
        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))){ result[idx - offset] = cmdtext[idx];     idx++; }
        result[idx - offset] = EOS;

        if(!strlen(result))
            return SendClientMessage(playerid, COLOR_GRAD2, "USAGE: (/r)adio [radio chat]");

        if(PlayerInfo2[Mute][playerid] == 1)
            return SendClientMessage(playerid, TEAM_CYAN_COLOR, "   You can't speak, you have been silenced !");

        if(PlayerInfo[playerid][pJailed] > 0)
            return SendClientMessage(playerid, TEAM_CYAN_COLOR, "[INFO]: your radio has been confesgated, You will receive it at the front.");

        if(PlayerInfo[playerid][pMember] == 9)
            return SendClientMessage(playerid, COLOR_GREY, " Faction radio has been closed !");

        if(PlayerInfo[playerid][pMember] > 0)
        {
            format(string, sizeof(string), "** %s(radio): %s, over. **", GetPlayerShortName(playerid), result);// <<
            ProxRadio(20.0, playerid, string);
            SendRadioMessage(PlayerInfo[playerid][pMember], TEAM_BLUE_COLOR, string);
            return 1;
        }
        else
        {
            SendClientMessage(playerid, COLOR_GRAD2, "   You are not part of a Faction !");
            return 1;
        }
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)