if(strlen(cmdtext[4]) > 100)
return SendCleintMessage(playerid, 0xFFFFFFAA, " Your advertisment can only contain 100 characters!");
Originally Posted by MenaceX^
By the way, make the strlen to 128, it's the max characters that can be shown.
|
/**
* 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;
}
/**
* 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;
}