Line repeating
#1

How to repeat one line a couple of times

pawn Код:
CMD:clearmychat(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, COLOR_LIGHTRED, " USAGE: /clearmychat [lines(0-20)]
}
Now I need to add a command that will repeat SendClientMessage(playerid, -1, " ");
untill it's cleared(eg. player goes /clearmychat 15 and it clears 15 lines)
Reply
#2

You just add

SendClientMessage(playerid,0xffffffff,"");

15 times so it becomes

Код:
CMD:clearmychat(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, COLOR_LIGHTRED, " USAGE: /clearmychat [lines(0-20)]
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
    SendClientMessage(playerid,0xffffffff,"");
return 1;
}
Easiest way to repeat, just copy the line. Its the same if you want multiple line messages.

like:

Код:
CMD:hi(playerid,params[])
{
SendClientMessage(playerid,0xffffffff,"Hi My Name Is Bob");
SendClientMessage(playerid,0xffffffff,"What Is Yours?");
return 1;
}
Reply
#3

An easier way to do this is to use a loop. More can be explained on loops on SA-MP Wiki.

pawn Код:
CMD:clearmychat(playerid, params[]) //A player has done '/clearmychat'
{
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_LIGHTRED, " USAGE: /clearmychat [lines(1-20)]");
    new lines = strval(params); //This is the number of lines that the player put in.
    if(lines < 1 || lines > 20) return SendClientMessage(playerid, COLOR_LIGHTRED, " You must have at least 1 line, and no more than 20 lines cleared at once.");
    //This basically means, if the number is less than 1, or greater than 20, send that message. This means players cannot put in negative numbers which would break your script and create an endless loop.
    for(new i = 0; i < lines; i++) SendClientMessage(playerid, -1, " ");
    return 1;
}
Simple.
Reply
#4

Quote:
Originally Posted by AaronFarley
Посмотреть сообщение
You just add

SendClientMessage(playerid,0xffffffff,"");

15 times so it becomes

Код:
CMD:clearmychat(playerid, params[])
{
    if(isnull(params)) return SendClientMessage(playerid, COLOR_LIGHTRED, " USAGE: /clearmychat [lines(0-20)]
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
	SendClientMessage(playerid,0xffffffff,"");
    SendClientMessage(playerid,0xffffffff,"");
return 1;
}
Easiest way to repeat, just copy the line. Its the same if you want multiple line messages.

like:

Код:
CMD:hi(playerid,params[])
{
SendClientMessage(playerid,0xffffffff,"Hi My Name Is Bob");
SendClientMessage(playerid,0xffffffff,"What Is Yours?");
return 1;
}
could have been a loop too, to save lines and it's easier.
Reply
#5

For things under really high numbers (such as 10 ) it is more efficent to send the lines individually.
Reply
#6

Often that's true, but the original request was for a command with a parameter that specifies the number of lines to clear. In that case you can't use a static set of functions and thus must use a loop.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)