02.04.2013, 14:47
(
Последний раз редактировалось Jewell; 04.04.2013 в 03:36.
Причина: Improved the code.
)
Detect Invalid Color Tags in GameTextForAll/GameTextForPlayer
Edit:Improved the code to auto fix invalid color tags. (delete invalid tags from the string).
Code:
pawn Код:
stock IsValidTag(text) //The valid colors
{
switch(text)
{
case 'G': return 1;
case 'P': return 1;
case 'B': return 1;
case 'R': return 1;
case 'Y': return 1;
case 'H': return 1;
case 'W': return 1;
case 'N': return 1;
case 'g': return 1;
case 'p': return 1;
case 'b': return 1;
case 'r': return 1;
case 'y': return 1;
case 'h': return 1;
case 'w': return 1;
case 'n': return 1;
}
return 0;
}
pawn Код:
stock GametextForAllEx(text[], time, style)
{
new i = 0, pos;
while (text[i])
{
if((pos = strfind(text[i],"~",true)) != -1)
{
if(text[i] == '~' && IsValidTag(text[i+1]) && text[i+2] == '~')
i = i+2;
else
if(text[i] == '~')
{
strdel(text[i],pos,pos+1);
continue;
}
}
i++;
}
return GameTextForAll(text, time, style);
}
pawn Код:
stock GameTextForPlayerEx(playerid, text[], time, style)
{
new i = 0, pos;
while (text[i])
{
if((pos = strfind(text[i],"~",true)) != -1)
{
if(text[i] == '~' && IsValidTag(text[i+1]) && text[i+2] == '~')
i = i+2;
else
if(text[i] == '~')
{
strdel(text[i],pos,pos+1);
continue;
}
}
i++;
}
return GameTextForPlayer(playerid, text, time, style);
}
pawn Код:
new string[128] = "~B~Invalid ~N~colo~U~r ~tags ~N~detected";
GametextForAllEx(string,8000,3); //Replace the GametextForAll with GametextForAllEx
Quote:
~B~Invalid ~N~colour tags ~N~detected |