SA-MP Forums Archive
using format in my own function? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: using format in my own function? (/showthread.php?tid=469383)



using format in my own function? - showdown - 13.10.2013

Hello,

I am messing around with scripting for sa-mp. I would like to be able to use something similar to format, only in my own custom function.

For example, if I have this code:
Код:
new sPlayer[MAX_PLAYER_NAME];
GetPlayerName(playerid, sPlayer, MAX_PLAYER_NAME);

new Query[128];
format(Query, 128, "INSERT INTO `"SQL_USERS_TABLE"` (`money`) VALUES ('%d') WHERE `username`=`%s`", 1000, sPlayer);

mysql_query(Query);
Is it possible to instead have a function like "format_mysql_query".

Код:
new sPlayer[MAX_PLAYER_NAME];
GetPlayerName(playerid, sPlayer, MAX_PLAYER_NAME);

format_mysql_query("INSERT INTO `"SQL_USERS_TABLE"` (`money`) VALUES ('%d') WHERE `username`=`%s`", 1000, sPlayer);
which would combine format and mysql_query. Or something similar for format_SendClientMessage?

Thanks a lot,
showdown


Re: using format in my own function? - Fierro - 13.10.2013

pawn Код:
public format_mysql_query(const string[],...)
{
    new query[350],sargs[128];
    for(new i = 0; i < numargs(); i++)
    {
        sargs[i] = getarg(i);
    }
    format(query,sizeof(query),string,sargs);
    return mysql_query(query);
}
Untested. Adjust the size of sargs as you see fit if it does work.


Re: using format in my own function? - showdown - 13.10.2013

I wasn't able to make that work.

I seem to remember in the past having seen a macro for SendClientMessage that somehow combined format and SendClientMessage. But I can't find it anywhere so far.

If anyone knows how to do this please let me know.