Problem with /giveweapon
#1

Hi guys! I've made a /giveweapon command, where you specify the weapon ID and the amount of ammo. However, whatever i type in as ammo it will come out as 0. This is the code:

pawn Код:
command(agiveweapon, playerid, params[])
{
    new WeaponN[ 60 ], Names[ 2 ][ MAX_PLAYER_NAME ], string[ 128 ], id, weaponid, ammo;
    if( sscanf( params, "ud", id, weaponid, ammo ) )
    {
        if( Player[playerid][AdminLevel] >= 3 )
        {
            SendClientMessage( playerid, COLOR_GREY, "SYNTAX: /agiveweapon [playerid/name] [weaponid] [ammo] " );
        }
        else
        {
            SendClientMessage( playerid, COLOR_GREY, "You are not authorized to use that command.");
        }
    }
    else
    {
        if( Player[playerid][AdminLevel] >= 3 )
        {
            if(IsPlayerConnectedEx(id) )
            {
                if(weaponid >= 1 && weaponid < 47)
                {
               
                    GetPlayerName( id, Names[ 0 ], MAX_PLAYER_NAME );
                    GetPlayerName( playerid, Names[ 1 ], MAX_PLAYER_NAME );
                   
                    if(weaponid == 19)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "Please use /jetpack instead.");
                    }
                    else if(weaponid == 38)
                    {
                        if(IsPlayerAdmin(playerid))
                        {
                            GetWeaponName(weaponid, WeaponN, sizeof(WeaponN) );
                            GivePlayerWeapon(id, weaponid, ammo);
                            format( string, sizeof( string ), "You have given %s a %s (Weapon ID: %d. Ammo: %d).", UnderscoreToSpaceName(id), WeaponN, weaponid, ammo);
                            SendClientMessage( playerid, COLOR_LIGHTBLUE, string);
                            format( string, sizeof( string ), "Admin %s has given you a %s. Ammo: %d", UnderscoreToSpaceName(playerid), WeaponN, ammo );
                            SendClientMessage(id, COLOR_LIGHTBLUE, string);
                            format( string, sizeof( string ), "[ADMMSG:] Admin %s has given %s a %s. (Ammo: %d)", Names[ 1 ], Names[ 0 ], WeaponN, ammo);
                            SendToAdmins(ADMINACTION, string, 1);
                            AdminActionsLog( string );
                        }
                        else
                        {
                            SendClientMessage(playerid, COLOR_GREY, "You are not authorized to spawn that weapon.");
                        }
                    }
                    else
                    {
                        GetWeaponName(weaponid, WeaponN, sizeof(WeaponN) );
                        GivePlayerWeapon(id, weaponid, ammo);
                        format( string, sizeof( string ), "You have given %s a %s (Weapon ID: %d. Ammo: %d).", UnderscoreToSpaceName(id), WeaponN, weaponid, ammo);
                        SendClientMessage( playerid, COLOR_LIGHTBLUE, string);
                        format( string, sizeof( string ), "Admin %s has given you a %s. Ammo: %d", UnderscoreToSpaceName(playerid), WeaponN, ammo );
                        SendClientMessage(id, COLOR_LIGHTBLUE, string);
                        format( string, sizeof( string ), "[ADMMSG:] Admin %s has given %s a %s. (Ammo: %d)", Names[ 1 ], Names[ 0 ], WeaponN, ammo);
                        SendToAdmins(ADMINACTION, string, 1);
                        AdminActionsLog( string );
                    }
                }
                else
                {
                    SendClientMessage( playerid, COLOR_GREY, "Invalid weapon ID." );
                }
            }
            else
            {
                SendClientMessage( playerid, COLOR_GREY, "Invalid ID." );
            }
        }
        else
        {
            SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use that command.");
        }
    }
    return 1;
}
Thanks in advance!

Donut Seller
Reply
#2

if( sscanf( params, "ud", id, weaponid, ammo ) )
I'm not that familar with sscanf however it looks as if you are checking for 2 variables only..
try if(sscanf(params, "udd", id, weaponid, ammo))

correct me if I'm wrong with this, 'cause I haven't used sscanf ever before...
Reply
#3

Thanks! Works perfect. I assume d stands for what kind of value it is? Same thing in format(string, where you always put %d for a number, right?
Reply
#4

Quote:
Originally Posted by Bates
Посмотреть сообщение
Thanks! Works perfect. I assume d stands for what kind of value it is? Same thing in format(string, where you always put %d for a number, right?
Have you looked at this thread?

https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#5

Perfect. THanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)