1

Following is a function to commit suicide in game

forward killPlayer(playerid);
public killPlayer(playerid)
{
    new query[128];
    if(GetPVarInt(playerid, "commitSuicide") == 1) 
    {
        mysql_format(MainPipeline, query, sizeof(query), "INSERT INTO `kills` (`id`, `killerid`, `killedid`, `date`, `weapon`) VALUES (NULL, %d, %d, NOW(), '/kill')", GetPlayerSQLId(playerid), GetPlayerSQLId(playerid));
        mysql_tquery(MainPipeline, query, "OnQueryFinish", "i", SENDDATA_THREAD);
        SetPVarInt(playerid, "commitSuicide", 0);
        SetHealth(playerid, 0);
    }
    else
        return SendClientMessageEx(playerid, COLOR_RED, "You have taken damage during the 10 seconds, therefore you couldn't commit suicide.");
    return 1;
}

What does "i" do in the following line of code?

mysql_tquery(MainPipeline, query, "OnQueryFinish", "i", SENDDATA_THREAD);

... and what does "ii" do in here?

PlayerInfo[playerid][pAccount] += amount;
                mysql_format(MainPipeline, szQuery, sizeof(szQuery), "UPDATE `accounts` SET `Bank`=%d WHERE `id` = %d", PlayerInfo[playerid][pAccount], GetPlayerSQLId(playerid));
                mysql_tquery(MainPipeline, szQuery, "OnQueryFinish", "ii", SENDDATA_THREAD, playerid);
            }

Related documentation: https://team.sa-mp.com/wiki/MySQL_R40.html#Format_specifiers_2

Git repository: https://github.com/NextGenerationGamingLLC/SA-MP-Development/

Please help me understand it

1 Answers1

0

These are format specifiers, mimicking the behaviour of functions like CallRemoteFunction which is in turn inspired by format. The reason for their existence is that Pawn doesn't pass the "type" of the arguments following "i", which would make strings indistinguishable from scalar values. The i means "integer", indicating that the following value is an integer. Likewise, "ii" indicates that two more arguments follow, both integers. This is necessary in order to store their values and use them again next time OnQueryFinish is to be called.

IS4
  • 11,945
  • 2
  • 47
  • 86