Spliting Text
#1

Hello people of SA-MP,

I come to you all with a simple problem. Here's what I can't seem to find on the forums. I have searched and searched and searched for how to separate text into two separate lines when a certain amount of letters are used. If any of you have played on LS-RP, you will know what I mean. For those who haven't, here is a screenshot of what I am.



That is what I am trying to do, I have searched around with no luck. I guess I don't know what keywords to search for. I have tried split, spliting, split rules, spliting rules, etc. I have searched with no success and that is why I am posting, in hope that someone will be able to help me out with this small problem of mine.

Can someone either guide me to a place on the forums that will actually assist with this problem or can someone work with me to script this up or can someone just post what I need on this post. Thank you for your time!
Reply
#2

i think you can only type a certain ammount of letters in the text box, but if not you could just use,

pawn Код:
public OnPlayerText(playerid, text[]) {
 new String[100];
 if ( strlen(text) > 99 ) {
 if ( strlen(text) > 200 ) {
  SendClientMessage(playerid, 0x00ff00ff, "Text is to long !");
 } else {
  strcat(String, text, 100);
  SendClientMessage(playerid, 0x00ff00ff, String);
  strdel(String, 0, strlen(String));
  strcat(String, text[101], 200);
  SendClientMessage(playerid, 0x00ff00ff, String);
  strdel(String, 0, strlen(String));
 }
 }
}
or something like that

EDIT: Updated And Fixed !
Reply
#3

Forgive me, I'm just an idiot here.

Okay, I see how you are getting things to work. Now, if I wanted to make it work with say a /b command, how would I integrate it?

Here is my /b command for my server:

Код:
	if(strcmp(cmd, "/b", true) == 0 || strcmp(cmd, "/booc", true) == 0)
	{
	  if(IsPlayerConnected(playerid))
	  {
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[128];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_GREEN, "[USAGE:] (/b)ooc [local ooc chat]");
				return 1;
			}
			format(string, sizeof(string), "(( [%d] %s: %s ))", playerid, GetPlayerNameEx(playerid), result);
			ProxDetector(20.0, playerid, string,COLOR_GRAD1,COLOR_GRAD1,COLOR_GRAD1,COLOR_GRAD1,COLOR_GRAD1);
			printf("%s", string);
		}
		return 1;
	}
Again, forgive me and your help is MUCH APPRECIATED!

Quote:
Originally Posted by JaYmE
i think you can only type a certain ammount of letters in the text box, but if not you could just use,

pawn Код:
public OnPlayerText(playerid, text[]) {
 new String[100];
 if ( strlen(text) > 99 ) {
 if ( strlen(text) > 200 ) {
 SendClientMessage(playerid, 0x00ff00ff, "Text is to long !");
 } else {
 strcat(String, text, 100);
 SendClientMessage(playerid, 0x00ff00ff, String);
 strdel(String, 0, strlen(String));
 strcat(String, text[101], 200);
 SendClientMessage(playerid, 0x00ff00ff, String);
 strdel(String, 0, strlen(String));
 }
 }
}
or something like that

EDIT: Updated And Fixed !
Reply
#4

You can try experimenting with strmid and split, here's the split function:
pawn Код:
split(const strsrc[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc))
    {
      if(strsrc[i]==delimiter || i==strlen(strsrc))
        {
        len = strmid(strdest[aNum], strsrc, li, i, 128);
        strdest[aNum][len] = 0;
        li = i+1;
        aNum++;
        }
        i++;
    }
    return 1;
}
Reply
#5

Much appreciated,
I'll play around with it and see what I can get out of it. Cheers.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)