01.01.2011, 20:32
If you really need the stock version:
By Ryder:
Or the use the macro, its faster.
By Ryder:
pawn Код:
stock SendFormatMessage(playerid, color, const string[], { Float, _ }: ...)
{
new
tempString[128],
parts[64],
tempLen,
totalFound,
i,
j,
t
;
memcpy(tempString, string, _, (strlen(string) + 1) * 4);
for(i = 0; tempString[i] != 0; ++i)
{
for(j = 0; parts[j] != 0; ++j)
{
parts[j] = '\0';
}
switch(tempString[i])
{
case 's', 'S', 'i', 'I', 'd', 'D', 'f', 'F', 'c', 'C', 'x', 'X', 'b', 'B':
{
if(tempString[(i > 0) ? (i - 1) : (i)] != '%')
{
continue;
}
else if(tempString[(i > 0) ? (i - 1) : (i)] == '%')
{
++totalFound;
if(tempString[i] == 's' || tempString[i] == 'S')
{
for(j = 0; getarg(totalFound + 2, j) != 0; ++j)
{
parts[j] = getarg(totalFound + 2, j);
}
}
switch(tempString[i])
{
case 'd', 'D', 'i', 'I': format(parts, sizeof(parts), "%d", getarg(totalFound + 2));
case 'f', 'F': format(parts, sizeof(parts), "%.02f", getarg(totalFound + 2));
case 'c', 'C': format(parts, sizeof(parts), "%c", getarg(totalFound + 2));
case 'x', 'X': format(parts, sizeof(parts), "%x", getarg(totalFound + 2));
case 'b', 'B': format(parts, sizeof(parts), "%b", getarg(totalFound + 2));
}
tempLen = strlen(parts);
if(tempLen > 2)
{
for(j = 0; j != (tempLen - 2); ++j)
{
strins(tempString, "_", (i + 1));
}
for(j = 0, t = 0; tempString[j] != 0; ++j)
{
if(j >= (i - 1) && t < tempLen)
{
tempString[j] = parts[t];
++t;
}
}
continue;
}
else if(tempLen == 2)
{
for(j = 0, t = 0; tempString[j] != 0; ++j)
{
if(j == i || j == (i - 1))
{
tempString[j] = parts[t];
++t;
}
}
continue;
}
else if(tempLen < 2)
{
strdel(tempString, i, i+1);
for(j = 0, t = 0; tempString[j] != 0; ++j)
{
if(j == (i - 1))
{
tempString[j] = parts[t];
++t;
}
}
continue;
}
}
}
}
}
if(playerid != INVALID_PLAYER_ID)
SendClientMessage(playerid, color, tempString);
else
SendClientMessageToAll(color, tempString);
return 1;
}