[Include] Delet Space
#1

This script optimizes your mod, and removes any extra spaces.
copy to the end of mod.
Code:
#define SPACE_CHARS ' ', '\t', '\r', '\n'

/*
    Обрежет по обоим краям строки все пробельные символы.
-----------
    Ничего не возвращает.
*/

stock trimSideSpaces ( string[] )
{
    new c, len = strlen(string);

    for ( ; c < len; c++ ) // вырежем пробелы в начале
    {
        switch ( string[c] )
        {
            case SPACE_CHARS : continue;
            default:
            {
                if ( c != 0 ) strmid( string, string, c, len, len );
                break;
            }
        }
    }

    for ( c = len - c - 1; c >= 0; c-- ) // вырежем пробелы в конце
    {
        switch ( string[c] )
        {
            case SPACE_CHARS : continue;
            default:
            {
                string[c + 1] = 0;
                break;
            }
        }
    }
}

#define cells *4

/*
    Заменяет группы пробельных символов на единичные пробелы
-----------
    Ничего не возвращает
*/

stock spaceGroupsToSpaces ( string[] )
{
    new len = strlen(string), c = len - 1, spaces;

    for ( ; c >= 0; c-- )
    {
        switch ( string[c] )
        {
            case SPACE_CHARS : spaces++;
            default :
            {
                if ( spaces > 1 )
                {
                    memcpy( string, string[c + spaces + 1], (c + 2) cells, (len - c - spaces - 1) cells, len );
                    len -= spaces - 1;
                }

                if ( spaces > 0 )
                {
                    string[c + 1] = ' ';
                    spaces        =  0;
                }
            }
        }
    }

    if ( spaces > 1 )
    {
        memcpy( string, string[c + spaces + 1], (c + 2) cells, (len - c - spaces - 1) cells, len );
        len -= spaces - 1;
    }
    if ( spaces > 0 ) string[c + 1] = ' ';

    string[len] = 0;
}
#undef SPACE_CHARS
How do I use it? Type:
Code:
		spaceGroupsToSpaces(result);
    		trimSideSpaces(result);
[/html]
in public's.
for example:
[html]
//----------------------------------[ooc]-----------------------------------------------
	if(strcmp(cmd, "/o", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(gPlayerLogged[playerid] == 0)
	        {
	            SendClientMessage(playerid, COLOR_GREY, " Вы не залогинены!");
	            return 1;
	        }
			if ((noooc) && PlayerInfo[playerid][pAdmin] < 1)
			{
				SendClientMessage(playerid, COLOR_PURPLE, "* OOC чат отключен!");
				return 1;
			}
			GetPlayerName(playerid, sendername, sizeof(sendername));
			new length = strlen(cmdtext);
			while ((idx < length) && (cmdtext[idx] <= ' '))
			{
				idx++;
			}
			new offset = idx;
			new result[64];
			while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
			{
				result[idx - offset] = cmdtext[idx];
				idx++;
			}
			result[idx - offset] = EOS;
			if(!strlen(result))
			{
				SendClientMessage(playerid, COLOR_GRAD2, " Используйте: (/o) [chat]");
				return 1;
			}
			if(PlayerInfo[playerid][pMuted] == 1)
			{
				SendClientMessage(playerid, TEAM_CYAN_COLOR, "Администратор отнял у вас возможность говорить в общем чате.");
				return 1;
			}
			spaceGroupsToSpaces(result);//this script:)
    		trimSideSpaces(result);//this script:)
			new word[256],Index;while(Index < strlen(result)) { // проверка сообщения на рекламу серверов и ее вырезание
			word = strtok(result,Index);
			if(Adv(word)==1||ZP(word)||U(word)||T(word)||N(word)||PP(word)||P(word)||V(word)||R(word)||PL(word)||ZV(word)||I(word)||ST(word)||PR(word)||DL(word)||RE(word)||VOC(word)||A(word)||NO(word)||TCZ(word)||BOP(word)){
					new i=strfind(result,word),j=i+strlen(word)-1; result[i++]='[';
					while(i<j) {result[i]='|';i++;}
					result[j]=']';
					BanEx(playerid, " Попытка рекламы сервера");
				}
		 	}
			realafk[playerid] = 1;
			format(string, sizeof(string), "(( %s[%d]: %s ))", sendername, playerid, result);
			OOCOff(COLOR_OOC,string);
			printf("%s", string);
		}
		return 1;
	}
Reply
#2

Wrong section I guess? Script looks good
Reply
#3

You are right.Mixed section, but sometimes professionals come thicket in Tut than in the "includes"
If needed, the moderator will move
Reply
#4

Good script, but can you please use [ pawn ] ?. HTML sax.
Reply
#5

ok
Reply
#6

If this is a tutorial,you should write sothin' about what you wrote there not just tell us to copy it
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)