17.07.2013, 20:51
Quote:
Two things:
1) You just gave me -rep for the 3 digit random number code I posted a few posts back (don't forget that mods can see names). If you know a better way of writing that code I'm more than happy to hear it. I'm not bothered about the decrease itself, but if you're going to get upset about, and accuse me of something, don't have done the exact same thing yourself! 2) Whoever did -rep you (if someone claimed to be me it probably wasn't me), I fully support their decision regardless (mods can also view old post edits) - strtok is a terrible method of coding, there was a discussion about it recently in this very thread. In that case discussion didn't do much as the original function that sparked that debate is still there. Clearly your version has now gone, proving -rep as the better incentive to not post rubbish. |
2) Sorry about that. I thought you -repped me lol, I lost like a huge amount so I thought it was you, but what should I care about a number saved in a SQL database, lol.
Okay to stay on topic, here's another function I just pulled out of my ass:
pawn Код:
stock SendClientMessageEx(playerid, color, const string[], {Float,_}:...)
{
new
temp[12],
value[128],
formatted[255],
argIndex = 3,
argCount = numargs();
strcat(formatted, string, sizeof(formatted));
for (new i = 0; i < strlen(formatted) && argIndex < argCount; i ++)
{
if (formatted[i] != '%')
continue;
else switch (formatted[i + 1])
{
case 'c', 'd', 'f', 'i':
{
strmid(temp, formatted, i, i + 2);
format(value, sizeof(value), temp, getarg(argIndex));
}
case 's':
{
for (new j, ch = 0; (ch = getarg(argIndex, j)) != '\0'; j ++) {
value[j] = ch;
if (j + 1 < sizeof(value)) value[j + 1] = '\0';
}
}
case '.', '0':
{
strmid(temp, formatted, i, i + 4);
format(value, sizeof(value), temp, getarg(argIndex));
}
default:
{
continue;
}
}
strdel(formatted, i, (formatted[i + 1] == '.' || formatted[i + 1] == '0') ? (i + 4) : (i + 2));
strins(formatted, value, i);
argIndex++;
}
return SendClientMessage(playerid, color, formatted);
}
pawn Код:
new playername[24];
GetPlayerName(playerid, playername, sizeof(playername));
SendClientMessageEx(playerid, -1, "Hello there, %s. You have $%d money.", playername, GetPlayerMoney(playerid));