Is there a way
#1

You get weapon names, Like you would get vehicle names.

For example

pawn Код:
YCMD:giveweapon(playerid, params[], help)
{
    new pid;
    new str[128];
    new weapon[32];
    new ammo;
    if(PlayerInfo[playerid][pAdmin] < 8 && !IsPlayerAdmin(playerid)) return
        SendClientMessage(playerid, COLOR_GREY, ADMIN_CMD_ERROR);
    if (help) return
        SendClientMessage(playerid, COMMAND_HELP_COLOR, "Gives a player a gun.");
    if (sscanf(params, "us[32]d", pid,weapon,ammo)) return
        SendClientMessage(playerid, COMMAND_PRINT, "Usage: /giveweapon <playerid/name> <weaponid> <ammo amount>.");
    if(!IsPlayerConnected(pid)) return
       SendClientMessage(playerid, ERROR_COLOR, PCONNECT);
    new wepname = GetWeaponModelIDFromName(weapon); //Made this up
    format(str, sizeof (str), "You have given %s [%d] Weapon id [%d] With %d amount of ammo %s",GetName(pid),pid,weapon,ammo,wepname);
    SendClientMessage(playerid, COMMAND_PRINT, str);
    GivePlayerWeapon(pid,wepname,ammo);
    return 1;
}
I wanna get weapon id from weapon name. Like if i type /giveweapon 0 m4 420 It would give me a m4

GetWeaponName i belive won't work.
Reply
#2

pawn Код:
stock GetWeaponID(name[])
{
    for(new wps=0; wps < 48; wps++)
    {
        if (wps==19||wps==20||wps== 21) continue;
        if (strfind(WeaponNames[wps],name, true) != -1) {
            return wps;
        }
    }
    return -1;
}
pawn Код:
new WeaponNames[][] = {
    {"Unarmed (Fist)"},{"Brass Knuckles"}, {"Golf Club"}, {"Night Stick"}, {"Knife"}, {"Baseball Bat"}, {"Shovel"}, {"Pool Cue"}, {"Katana"}, {"Chainsaw"},
    {"Purple Dildo"}, {"Big White Vibrator"}, {"Medium White Vibrator"}, {"Small White Vibrator"}, {"Flowers"}, {"Cane"}, {"Grenade"}, {"Teargas"},{"Molotov"},
    {" "},{" "},{" "},{"Colt "},{"Colt  (Silenced)"},{"Desert Eagle"},{"Normal Shotgun"},{"Sawnoff Shotgun"},{"Combat Shotgun"}, {"Micro Uzi (Mac )"},
    {"MP"},{"AK"},{"M4"},{"Tec"},{"Country Rifle"},{"Sniper Rifle"},{"Rocket Launcher"},{"Heat-Seeking Rocket Launcher"},{"Flamethrower"}, {"Minigun"},
    {"Satchel Charge"},{"Detonator"},{"Spray Can"},{"Fire Extinguisher"},{"Camera"},{"Night Vision Goggles"},{"Infrared Vision Goggles"},{"Parachute"},{"Fake Pistol"}
};

...
pawn Код:
YCMD:giveweapon(playerid, params[], help)
{
    new pid;
    new str[128];
    new weapon[32];
    new ammo;
    if(PlayerInfo[playerid][pAdmin] < 8 && !IsPlayerAdmin(playerid)) return
        SendClientMessage(playerid, COLOR_GREY, ADMIN_CMD_ERROR);
    if (help) return
        SendClientMessage(playerid, COMMAND_HELP_COLOR, "Gives a player a gun.");
    if (sscanf(params, "us[32]d", pid,weapon,ammo)) return
        SendClientMessage(playerid, COMMAND_PRINT, "Usage: /giveweapon <playerid/name> <weaponid> <ammo amount>.");
    if(!IsPlayerConnected(pid)) return
       SendClientMessage(playerid, ERROR_COLOR, PCONNECT);
    new wepname = GetWeaponID(weapon);
    format(str, sizeof (str), "You have given %s [%d] Weapon id [%d] With %d amount of ammo %s",GetName(pid),pid,weapon,ammo,WeaponNames[weaponid]);
    SendClientMessage(playerid, COMMAND_PRINT, str);
    GivePlayerWeapon(pid,wepname,ammo);
    return 1;
}

prob some warning but fix it
Reply
#3

fully tested:
pawn Код:
COMMAND:giveweapon(playerid,params[]) {
    new
        weap[30],
        weapname[50],
        id,
        name1[30],
        name2[30],
        ammo,
        text[128];
    if(sscanf(params,"usi",id,weap,ammo))
        return SendClientMessage(playerid,red,"USAGE: /giveweapon [id] [weapon name] [ammo]");
    if(PlayerInfo[playerid][pAdminLevel] >= 4) {
        if(IsPlayerConnected(id)) {
            GetPlayerName(playerid,name1,sizeof(name1));
            GetPlayerName(id,name2,sizeof(name2));
            GetWeaponName(GetWeaponIDFromName(weap),weapname,sizeof(weapname));
            format(text,sizeof(text),"Administrator \"%s\" has given \"%s\" a weapon: %s, ammo: %i.",name1,name2,weapname,ammo);
            GivePlayerWeapon(id,GetWeaponIDFromName(weap), ammo);
            SendClientMessageToAll(COLOR_LIGHTBLUE,text);
        } else {
            return SendClientMessage(playerid,red,"Invalid ID");
        }
    } else {
        return SendClientMessage(playerid,red,"Only lvl4 admins can use this command. Looking for a way to get a weapon? /help!");
    }
    return 1;
}
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;
}
:]
Reply
#4

Quote:
Originally Posted by [ISS]jumbo
Посмотреть сообщение
pawn Код:
stock GetWeaponID(name[])
{
    for(new wps=0; wps < 48; wps++)
    {
        if (wps==19||wps==20||wps== 21) continue;
        if (strfind(WeaponNames[wps],name, true) != -1) {
            return wps;
        }
    }
    return -1;
}
pawn Код:
new WeaponNames[][] = {
    {"Unarmed (Fist)"},{"Brass Knuckles"}, {"Golf Club"}, {"Night Stick"}, {"Knife"}, {"Baseball Bat"}, {"Shovel"}, {"Pool Cue"}, {"Katana"}, {"Chainsaw"},
    {"Purple Dildo"}, {"Big White Vibrator"}, {"Medium White Vibrator"}, {"Small White Vibrator"}, {"Flowers"}, {"Cane"}, {"Grenade"}, {"Teargas"},{"Molotov"},
    {" "},{" "},{" "},{"Colt "},{"Colt  (Silenced)"},{"Desert Eagle"},{"Normal Shotgun"},{"Sawnoff Shotgun"},{"Combat Shotgun"}, {"Micro Uzi (Mac )"},
    {"MP"},{"AK"},{"M4"},{"Tec"},{"Country Rifle"},{"Sniper Rifle"},{"Rocket Launcher"},{"Heat-Seeking Rocket Launcher"},{"Flamethrower"}, {"Minigun"},
    {"Satchel Charge"},{"Detonator"},{"Spray Can"},{"Fire Extinguisher"},{"Camera"},{"Night Vision Goggles"},{"Infrared Vision Goggles"},{"Parachute"},{"Fake Pistol"}
};

...
pawn Код:
YCMD:giveweapon(playerid, params[], help)
{
    new pid;
    new str[128];
    new weapon[32];
    new ammo;
    if(PlayerInfo[playerid][pAdmin] < 8 && !IsPlayerAdmin(playerid)) return
        SendClientMessage(playerid, COLOR_GREY, ADMIN_CMD_ERROR);
    if (help) return
        SendClientMessage(playerid, COMMAND_HELP_COLOR, "Gives a player a gun.");
    if (sscanf(params, "us[32]d", pid,weapon,ammo)) return
        SendClientMessage(playerid, COMMAND_PRINT, "Usage: /giveweapon <playerid/name> <weaponid> <ammo amount>.");
    if(!IsPlayerConnected(pid)) return
       SendClientMessage(playerid, ERROR_COLOR, PCONNECT);
    new wepname = GetWeaponID(weapon);
    format(str, sizeof (str), "You have given %s [%d] Weapon id [%d] With %d amount of ammo %s",GetName(pid),pid,weapon,ammo,WeaponNames[weaponid]);
    SendClientMessage(playerid, COMMAND_PRINT, str);
    GivePlayerWeapon(pid,wepname,ammo);
    return 1;
}

prob some warning but fix it
Thank you for the quick reply. I tried somthing similar to this but i didn't have the brackets like that. I just had 1 opening and one closing bracket.

It would give me a weapon but the wrong one. (the one i did)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)