PDA

View Full Version : Line repeating


venomlivno8
13/02/2014, 11:32 AM
How to repeat one line a couple of times

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)

AaronFarley
13/02/2014, 12:26 PM
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;
}

Threshold
13/02/2014, 12:48 PM
An easier way to do this is to use a loop. More can be explained on loops on SA-MP Wiki.

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.

kooltuO
13/02/2014, 12:50 PM
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.

CuervO
13/02/2014, 01:26 PM
For things under really high numbers (such as 10 ) it is more efficent to send the lines individually.

ColeMiner
13/02/2014, 01:34 PM
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.