/advertise - max chars
#1

I have this command /ad, but when u use too many chars, the name cuts off. For example I do

/ah Selling [blablabla] and a lot of pancakes

It will show

Advertisement: Selling ... and a lot of pancakes, contact Hy (should be Hyper..)

This is what I have it the command and what I guess should be changed:

format(string, sizeof(string), "Advertisement: %s, contact %s(%i)" ,cmdtext[4],player,playerid);
SendClientMessageToAll(COLOR_ORANGE,string);
Reply
#2

pawn Код:
if(strlen(cmdtext[4]) > 100)
  return SendCleintMessage(playerid, 0xFFFFFFAA, " Your advertisment can only contain 100 characters!");
strlen = string length
basically you are checking if the input is longer then 100 cords, if it is, dont do the ad.
Reply
#3

Ah thanks! That works
Reply
#4

By the way, make the strlen to 128, it's the max characters that can be shown.
Reply
#5

Quote:
Originally Posted by MenaceX^
By the way, make the strlen to 128, it's the max characters that can be shown.
Yes, but there should also fit "Advertisement" and player's name.
Reply
#6

I made it 50, otherwise it'll to through the whole screen. Can't I make it go to the next line or sumthing?
Reply
#7

If you want

pawn Код:
/**
 *  Sends a wrapped message to player with indentation
 *  @param  playerid    The playerid to send the message to
 *  @param  colour      The colour of the message
 *  @param  msg         The message to send
 *  @param  maxlength   The length to wrap to
 *  @param  prefix      The string to indent with
 */

stock SendWrappedMessageToPlayer(playerid, colour, const msg[], maxlength=85, const prefix[]="  ")
{
    new length = strlen(msg);
    if(length <= maxlength) {
        SendClientMessage(playerid, colour, msg);
        return;
    }
    new string[MAX_INPUT], idx;
    for(new i, space, plen, bool:useprefix; i < length; i++) {
        if(i - idx + plen >= maxlength) {
            if(idx == space || i - space >= 25) {
                strmid(string, msg, idx, i);
                idx = i;
            } else {
                strmid(string, msg, idx, space);
                idx = space + 1;
            }
            if(useprefix) {
                strins(string, prefix, 0);
            } else {
                plen = strlen(prefix);
                useprefix = true;
            }
            SendClientMessage(playerid, colour, string);
        } else if(msg[i] == ' ') {
            space = i;
        }
    }
    if(idx < length) {
        strmid(string, msg, idx, length);
        strins(string, prefix, 0);
        SendClientMessage(playerid, colour, string);
    }
    return;
}
pawn Код:
/**
 *  Sends a wrapped message to all players with indentation
 *  @param  colour      The colour of the message
 *  @param  msg         The message to send
 *  @param  maxlength   The length to wrap to
 *  @param  prefix      The string to indent with
 */

stock SendWrappedMessageToAll(colour, const msg[], maxlength=85, const prefix[]="  ")
{
    new length = strlen(msg);
    if(length <= maxlength) {
        SendClientMessageToAll(colour, msg);
        return;
    }
    new string[MAX_INPUT], idx;
    for(new i, space, plen, bool:useprefix; i < length; i++) {
        if(i - idx + plen >= maxlength) {
            if(idx == space || i - space >= 25) {
                strmid(string, msg, idx, i);
                idx = i;
            } else {
                strmid(string, msg, idx, space);
                idx = space + 1;
            }
            if(useprefix) {
                strins(string, prefix, 0);
            } else {
                plen = strlen(prefix);
                useprefix = true;
            }
            SendClientMessageToAll(colour, string);
        } else if(msg[i] == ' ') {
            space = i;
        }
    }
    if(idx < length) {
        strmid(string, msg, idx, length);
        strins(string, prefix, 0);
        SendClientMessageToAll(colour, string);
    }
    return;
}
Reply
#8

Ok thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)