как передать параметры в функцию

lifeisabitch

Участник
Автор темы
59
2
Извините, я плохо говорю по-русски, говорю через Google-переводчик.

Интересно, можно ли таким образом передать через функцию неограниченное количество параметров или как-то правильно?

Code:
CMD:giveweap(playerid, params[])
{
    if(sscanf(params, "dd", params[0], params[1])) return CustomMessage(playerid, "/giveweap [Weap] [Ammo]");
    if(params[0] < 0 || params[0] > 46) return CustomMessage(playerid, "ID between 0 and 46");
    if(params[1] < 1 || params[1] > 999) return CustomMessage(playerid, "From 1 to 999");
    GivePlayerWeapon(playerid, params[0], params[1]);
    CustomMessage(playerid, "Now you have the %d gun with %d bullets", params[0], params[1]);
    return 1;
}

stock CustomMessage(playerid, msg[], ...)
{
    new cstms[256];
    format(cstms, sizeof(cstms), "%s {ffffff}- %s %s", InfoServer, msg, ...);
    SendClientMessage(playerid, -1, cstms);
    return 1;
}
 

Ну погоди!

Участник
98
35
U must use this, example code:
Код:
CMD:giveweap(playerid, params[])
{
    if(sscanf(params, "dd", params[0], params[1])) return CustomMessage(playerid, "/giveweap [Weap] [Ammo]");
    if(params[0] < 0 || params[0] > 46) return CustomMessage(playerid, "ID between 0 and 46");
    if(params[1] < 1 || params[1] > 999) return CustomMessage(playerid, "From 1 to 999");
    GivePlayerWeapon(playerid, params[0], params[1]);
    new string[64];
    format(string, sizeof string, "Now you have the %d gun with %d bullets", params[0], params[1]);
    CustomMessage(playerid, string, params[0], params[1]);
    return 1;
}

stock CustomMessage(playerid, string[], weaponid, bullets)
{
    new cstms[256];
    format(cstms, sizeof(cstms), "%s {ffffff}- %i %i", InfoServer, weaponid, bullets);
    SendClientMessage(playerid, -1, cstms);
    return 1;
}

%i or %d — INT Value
In pawn «...» u need use to be fully array, example:
Код:
new someArray[100] = {1, 2, 3, ...}; // In array values: 1,2,3,4,5,6 and next
At arguments u need create a new string or integer at function body
 

lifeisabitch

Участник
Автор темы
59
2
U must use this, example code:
Код:
CMD:giveweap(playerid, params[])
{
    if(sscanf(params, "dd", params[0], params[1])) return CustomMessage(playerid, "/giveweap [Weap] [Ammo]");
    if(params[0] < 0 || params[0] > 46) return CustomMessage(playerid, "ID between 0 and 46");
    if(params[1] < 1 || params[1] > 999) return CustomMessage(playerid, "From 1 to 999");
    GivePlayerWeapon(playerid, params[0], params[1]);
    new string[64];
    format(string, sizeof string, "Now you have the %d gun with %d bullets", params[0], params[1]);
    CustomMessage(playerid, string, params[0], params[1]);
    return 1;
}

stock CustomMessage(playerid, string[], weaponid, bullets)
{
    new cstms[256];
    format(cstms, sizeof(cstms), "%s {ffffff}- %i %i", InfoServer, weaponid, bullets);
    SendClientMessage(playerid, -1, cstms);
    return 1;
}

%i or %d — INT Value
In pawn «...» u need use to be fully array, example:
Код:
new someArray[100] = {1, 2, 3, ...}; // In array values: 1,2,3,4,5,6 and next
At arguments u need create a new string or integer at function body



but I wanted to be able to use this CustomMessage in any command regardless of the parameter, would it be possible?