error argument ...
#1

pawn Код:
CMD:giveweapon(playerid,params[])
{
        if(pInfo[playerid][Adminlevel] < 4) return SCM(playerid, COLOR_RED,""ERROR_MESSAGE"");
        new TargetID,targetname[50],weaponname[50],weaponammo;
        if(sscanf(params,"us[50]d",TargetID,weaponname,weaponammo)) return SCM(playerid, COLOR_RED, "Usage: /giveweapon [playerid] [weapon id/weapon name] [ammo]");
        new string[128],weapon[50],wea;
        GetPlayerName(TargetID,targetname,sizeof(TargetID));
        if(!isNumeric(weaponname))
        {
            wea = GetWeaponIDFromName(weaponname);
            GetWeaponName(wea,weapon,50);
        }
        else
        {
            wea = GetWeaponName(weaponname,weapon,50);
        }
        if(IsPlayerConnected(TargetID) && TargetID != INVALID_PLAYER_ID)
        {
            if(!IsValidWeapon(wea)) return SCM(playerid,COLOR_RED,"Invalid Weapon ID or Name");
            format(string, sizeof(string), "**Weapon: %s (%d) (Admin Weapon) %s (%d) with %d rounds of ammo", targetname,TargetID, weapon, wea, weaponammo); SCMA(COLOR_HOTPINK,string);
            return GivePlayerWeapon(TargetID, wea, weaponammo);
        } else return SCM(playerid,COLOR_RED,"** Player is not connected");
}
pawn Код:
(9425) : error 035: argument type mismatch (argument 1)
line 9425
pawn Код:
wea = GetWeaponName(weaponname,weapon,50);
Reply
#2

What is being returned by getweaponname()?
Reply
#3

what do u mean
Reply
#4

GetWeaponName returns 0 (success)/1 (failure).

The first argument is the weaponid which is integer and you used a string. Assuming GetWeaponIDFromName returns the weaponid from the name (from an array):
pawn Код:
CMD:giveweapon(playerid,params[])
{
    if (pInfo[playerid][Adminlevel] < 4) return SCM(playerid, COLOR_RED, ERROR_MESSAGE);
    new TargetID, weaponname[32], weaponammo;
    if (sscanf(params, "rs[32]d", TargetID, weaponname, weaponammo)) return SCM(playerid, COLOR_RED, "Usage: /giveweapon [playerid] [weapon id/weapon name] [ammo]");
    if (!IsPlayerConnected(TargetID)) return SCM(playerid, COLOR_RED, "** Player is not connected");
    new wea;
    if (!isNumeric(weaponname)) wea = GetWeaponIDFromName(weaponname);
    else wea = strval(weaponname);
    if (!IsValidWeapon(wea)) return SCM(playerid, COLOR_RED, "Invalid Weapon ID or Name");
    new targetname[MAX_PLAYER_NAME], string[128];
    GetPlayerName(TargetID, targetname, sizeof (TargetID));
    format(string, sizeof (string), "**Weapon: %s (%d) (Admin Weapon) %s (%d) with %d rounds of ammo", targetname, TargetID, WEAPON_NAME_ARRAY[wea], wea, weaponammo);
    SCMA(COLOR_HOTPINK, string);
    GivePlayerWeapon(TargetID, wea, weaponammo);
    return 1;
}
Edit this line with the name of the array you use for the weapon names:
pawn Код:
format(string, sizeof(string), "**Weapon: %s (%d) (Admin Weapon) %s (%d) with %d rounds of ammo", targetname, TargetID, WEAPON_NAME_ARRAY[wea], wea, weaponammo);
Also make sure that IsValidWeapon function will block a weaponid greater than 46 or negative so it won't cause any run time error 4.
Reply
#5

how do i get the weapon name now u removed it ??
Reply
#6

There is an array that has the weapons' name stored and you retrieve the weaponid from the name in GetWeaponIDFromName function. If you can't find the name, post the function.
Reply
#7

pawn Код:
stock GetWeaponIDFromName(WeaponName[])
{
    if(strfind("molotov",WeaponName,true)!=-1) return 18;
    for(new i = 0; i <= 46; i++)
    {
        switch(i)
        {
            case 0,19,20,21,44,45: continue;
            default:
            {
                new name[32]; GetWeaponName(i,name,32);
                if(strfind(name,WeaponName,true) != -1) return i;
            }
        }
    }
    return -1;
}
Reply
#8

Okay, use GetWeaponNameEx function from the wiki: https://sampwiki.blast.hk/wiki/GetWeaponName

and replace to:
pawn Код:
GetWeaponNameEx(weaponid, weaponname, sizeof (weaponname));
format(string, sizeof (string), "**Weapon: %s (%d) (Admin Weapon) %s (%d) with %d rounds of ammo", targetname, TargetID, weaponname, wea, weaponammo);
Reply
#9

There is nothing like GetWeaponNameEX shall i change it to GetWeaponName
Reply
#10

No, it is at the link I sent you (at the bottom of it).
pawn Код:
stock GetWeaponNameEx(weaponid, weapon[], len)
{
    switch (weaponid)
    {
        case 18: return weapon[0] = 0, strcat(weapon, "Molotov Cocktail", len), true;
        case 44: return weapon[0] = 0, strcat(weapon, "Thermal Goggles", len), true;
        case 45: return weapon[0] = 0, strcat(weapon, "Night Vision Goggles", len), true;
        default: return GetWeaponName(weaponid, weapon, len);
    }
    return false;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)