SA-MP Forums Archive
sscanf error - 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: sscanf error (/showthread.php?tid=373174)



sscanf problem - jameskmonger - 29.08.2012

pawn Код:
CommandDescription<spawnweapon> = @"Spawn a weapon for the specified player.";
YCMD(GROUP_ADMIN, GROUP_MANAGEMENT, GROUP_RCON):spawnweapon(playerid, params[], help) {
    if(help) {
        SendClientMessage(playerid, COLOR_COMMAND_HELP, @"Spawn a weapon for a specified player");
    } else {
        new target, weapon, ammo;
        if(sscanf(params, "rk<weapon>i(-1)", target, weapon, ammo)) {
            SendClientMessage(playerid, COLOR_COMMAND_USAGE, @"* Usage: /spawnweapon [player] [weapon] [OPTIONAL: ammo-amount]");
        } else {
            if(playerid == INVALID_PLAYER_ID) {
                SendClientMessage(playerid, COLOR_COMMAND_ERROR, @"Invalid player ID");
                return 1;
            }
            if(weapon != -1) {
                if(ammo == -1) {
                    GivePlayerWeapon(target, weapon, 99999);
                    SendClientMessage(playerid, 0xFF87E9FF, @"You have given %p %w with unlimited ammo.", target, weapon);
                    SendClientMessage(target, 0xFF87E9FF, @"%p has given you %w with unlimited ammo.", playerid, weapon);
                } else {
                    GivePlayerWeapon(target, weapon, ammo);
                    SendClientMessage(playerid, 0xFF87E9FF, @"You have given %p %w with %d round of ammo.", target, weapon, ammo);
                    SendClientMessage(target, 0xFF87E9FF, @"%p has given you %w with %d rounds of ammo.", playerid, weapon, ammo);
                }
            } else {
                SendClientMessage(playerid, COLOR_COMMAND_ERROR, @"You entered an invalid weapon.");
            }
        }
    }
    return 1;
}
If I type /spawnweapon 1 24, it should assume the default ammo value (-1) and carry on with the code. However, it simply gives me the "Usage: /spawnweapon [player] [weapon] [OPTIONAL: ammo-amount]" message. Can someone help me?


Re: sscanf error - jameskmonger - 29.08.2012

Bump


Re: sscanf error - Misiur - 29.08.2012

pawn Код:
"rk<weapon>i(-1)"
//Changes to
"rk<weapon>I(-1)"



Re: sscanf error - jameskmonger - 29.08.2012

Ah, thankyou. :P