SA-MP Forums Archive
/giveweapon command outputs player name instead of weapon name... - 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: /giveweapon command outputs player name instead of weapon name... (/showthread.php?tid=423443)



/giveweapon command outputs player name instead of weapon name... - Apenmeeuw - 17.03.2013

hey all,

i made this /giveweapon command, but somehow it says: Administrator ApenMeeuw has given you a ApenMeeuw... instead of Administrator ApenMeeuw has given you a Tec-9, for example..


pawn Код:
CMD:giveweapon(playerid, params[])
{
    if(IsPlayerNAdminLevel(playerid, LEVEL_GIVEWEAPON))
    {
        new targetid, WeapName[34], Weap[34];
        if(sscanf(params, "us[34]", targetid, WeapName)) return UsageMessage(playerid, "giveweapon", "[playerid]", "[weaponname]", "");
        if(targetid == INVALID_PLAYER_ID) return InvPid(playerid);
        SendCommandToAdmins(playerid, "giveweapon");
        GivePlayerWeapon(targetid, GetWeaponIDFromName(WeapName), 5000);
        new string[128];
        format(string, sizeof(string), "Administrator {FFFFFF}%s(%d) "EMBED_ARASIA"has given you a {FFFFFF}%s", PlayersName(playerid), playerid, GetWeaponName(GetWeaponIDFromName(WeapName),Weap,32));
        SendClientMessage(targetid, COLOR_ARASIA, string);
        format(string, sizeof(string), "You have given {FFFFFF}%s(%d) "EMBED_ARASIA"a {FFFFFF}%s", PlayersName(targetid), targetid, GetWeaponName(GetWeaponIDFromName(WeapName),Weap,32));
        SendClientMessage(playerid, COLOR_ARASIA, string);
    }
    else return ErrorMessage(playerid, LEVEL_GIVEWEAPON);
    return 1;
}
whats wrong with that?

the GetWeaponIDFromName:
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;
}

whats wrong with this code?

greets


Re: /giveweapon command outputs player name instead of weapon name... - stabker - 17.03.2013

Try it

pawn Код:
CMD:giveweapon(playerid, params[])
{
    if(IsPlayerNAdminLevel(playerid, LEVEL_GIVEWEAPON))
    {
        new targetid, WeapName[34], Weap[34];
        if(sscanf(params, "us[34]", targetid, WeapName)) return UsageMessage(playerid, "giveweapon", "[playerid]", "[weaponname]", "");
        if(targetid == INVALID_PLAYER_ID) return InvPid(playerid);
        SendCommandToAdmins(playerid, "giveweapon");
        new weapid = GetWeaponIDFromName(WeapName);
        GivePlayerWeapon(targetid, weapid, 5000);
        GetWeaponName(weapid,Weap,32);
        new string[128];
        format(string, sizeof(string), "Administrator {FFFFFF}%s(%d) "EMBED_ARASIA"has given you a {FFFFFF}%s", PlayersName(playerid), playerid, Weap);
        SendClientMessage(targetid, COLOR_ARASIA, string);
        format(string, sizeof(string), "You have given {FFFFFF}%s(%d) "EMBED_ARASIA"a {FFFFFF}%s", PlayersName(targetid), targetid, Weap);
        SendClientMessage(playerid, COLOR_ARASIA, string);
    }
    else return ErrorMessage(playerid, LEVEL_GIVEWEAPON);
    return 1;
}



Re: /giveweapon command outputs player name instead of weapon name... - Apenmeeuw - 17.03.2013

it works thanks