SA-MP Forums Archive
Line repeating - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Line repeating (/showthread.php?tid=494437)



Line repeating - venomlivno8 - 13.02.2014

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)


Re: Line repeating - AaronFarley - 13.02.2014

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;
}



Re: Line repeating - Threshold - 13.02.2014

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.


Re: Line repeating - kooltuO - 13.02.2014

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.


Re: Line repeating - CuervO - 13.02.2014

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


Re: Line repeating - ColeMiner - 13.02.2014

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.