How to split a /me up into 2 lines?
#1

This is my /me and /do script:

pawn Код:
public OnPlayerCommandText( playerid, cmdtext[ ] )
{
    if ( !strcmp( cmdtext, "/me", true, 3 ) )
    {
        if ( cmdtext[ 3 ] != ' ' || !cmdtext[ 4 ] )
            return SendClientMessage( playerid, -1, "USAGE: /me (action)" );

        new
            tempString[ 128 ],
            pName[ 24 ]
        ;

        GetPlayerName( playerid, pName, sizeof pName );

        format( tempString, sizeof tempString, "*%s%s", RemoveUnderScore(playerid), cmdtext[ 3 ] );

        SendClosestMessage( playerid, COLOR_PINK, tempString );

        return 1;
    }

    if ( !strcmp( cmdtext, "/do", true, 3 ) )
    {
        if ( cmdtext[ 3 ] != ' ' || !cmdtext[ 4 ] )
            return SendClientMessage( playerid, -1, "USAGE: /do (action)" );

        new
            tempString[ 128 ],
            pName[ 24 ]
        ;

        GetPlayerName( playerid, pName, sizeof pName );
        new stringpos;
        if (((stringpos = strfind(" ", pName))) != -1)
{
    pName[stringpos] = ' ';
}
        format( tempString, sizeof tempString, "* (( %s )) %s" , RemoveUnderScore(playerid), cmdtext[ 3 ] );

        SendClosestMessage( playerid, COLOR_PINK, tempString );

        return 1;
    }

    return 0;
}
How do I split the /me's and /do's up so that when they are too long, they go onto the 2nd line?
Reply
#2

Try with if(strlen(cmdtext) < [how much you think it long])
{
//here create 2 temp strings and new variable that will get cmdtext to some lenght and stor it into first string and the rest of message store into second and then use 2xSendClientMessage
Reply
#3

Post the SendClosestMessage function.
Reply
#4

I don't see how will that help
Reply
#5

I will modify that function. Is that so hard ?
Reply
#6

Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
I don't see how will that help
He is just trying to steal your function.
Reply
#7

pawn Код:
strmid(chat3,chat2,75,160);
strdel(chat2,81,160);
CostumFormat(chat4,"%s-",chat2);
CostumFormat(chat5,"-%s",chat3);
SendClientMessage(i,color4,chat4);
SendClientMessage(i,color4,chat5);
A piece from my include.
Reply
#8

Its not hard to split it to 2 messages but that will not allow you to send longer message since samp's maximum input string is 128
Reply
#9

So smartass'es ( like Dimi & Steven82 ) that's why I told him to gimme that function ; I made those commands with SendClientMessage, not SendClosestMessage.

http://imageshack.us/f/840/samp033w.png/
http://imageshack.us/f/825/samp034bo.png/

PHP код:
    if (!strcmp(cmdtext"/me"true3))
    {
        if (
cmdtext[3] != ' ' || !cmdtext[4])
            return 
SendClientMessage(playerid, -1"USAGE: /me (action)");
        new 
string[128], tempStr[128], Str[128];
        
format(stringsizeof(string), "%s"cmdtext[3]);
        if(
strlen(string) > (128 MAX_PLAYER_NAME))
        {
            
strmid(tempStrstring0, (128 MAX_PLAYER_NAME));
            
format(Strsizeof(Str), "*%s%s"ReturnName(playerid), tempStr);
            
SendClientMessage(playerid0xFFAABBCCStr);
            
strdel(string0, (128 MAX_PLAYER_NAME));
            
format(tempStrsizeof(tempStr), "*%s %s"ReturnName(playerid), string);
            
SendClientMessage(playerid0xFFAABBCCtempStr);
        }
        else
        {
            
format(stringsizeof string"*%s%s"ReturnName(playerid), cmdtext[3]);
            
SendClientMessage(playerid0xFFAABBCCstring);
        }
//      SendClosestMessage(playerid, COLOR_PINK, tempString);
        
return 1;
    }
    if (!
strcmp(cmdtext"/do"true3))
    {
        if (
cmdtext[3] != ' ' || !cmdtext[4])
            return 
SendClientMessage(playerid, -1"USAGE: /do (action)");
        new 
string[128], tempStr[128], Str[128];
        
format(stringsizeof(string), "%s"cmdtext[3]);
        if(
strlen(string) > (128 MAX_PLAYER_NAME))
        {
            
strmid(tempStrstring0, (128 MAX_PLAYER_NAME));
            
format(Strsizeof(Str), "* (( %s ))%s"ReturnName(playerid), tempStr);
            
SendClientMessage(playerid0xFFAABBCCStr);
            
strdel(string0, (128 MAX_PLAYER_NAME));
            
format(tempStrsizeof(tempStr), "* (( %s )) %s"ReturnName(playerid), string);
            
SendClientMessage(playerid0xFFAABBCCtempStr);
        }
        else
        {
            
format(stringsizeof string"* (( %s ))%s"ReturnName(playerid), cmdtext[3]);
            
SendClientMessage(playerid0xFFAABBCCstring);
        }
        
//SendClosestMessage(playerid, COLOR_PINK, tempString);
        
return 1;
    } 
And Gramercy Riffs, i suggest you to use strtok for commands, because the way how you try to find the parameters, is a bad idea. Because if you type /me or /measdf or /meetmeatthehotel or anything else which starts with me, you'll get the USAGE advertise message. Same as /do.
Reply
#10

Thank you very much.

Is strtok easier than the method I'm using?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)