SA-MP Forums Archive
Giveweapon issues - 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 issues (/showthread.php?tid=343791)



Giveweapon issues - vIBIENNYx - 18.05.2012

Okay, basically, I am trying to create a command that can spawn a selected player a weapon with a defined amount of ammo, this issue is: Whenever I try to spawn a weapon it either breaks the command, says that a "Fist" is spawned and no weapon spawns or nothing happens at all..

Here is all relevant code:

pawn Код:
new WeaponNames[47][] =
{
    "Fist","BrassKnuckles","Golfclub","Nitestick","Knife","BaseballBat","Shovel","Poolcue","Katana","Chainsaw","PurpleDildo","SmallWhiteVibrator","LargeWhiteVibrator","SilverVibrator",
    "Flowers","Cane","Grenade","Tearcas Grenade","Molotov Cocktail","Jetpack"," "," ","9mm","Silenced9mm","Deagle","Shotgun","Sawn-OffShotgun","SPAS-12",
    "MicroUzi","MP5","AK-47","M4","Tec-9","Rifle","Sniperrifle","RPG","Heatseeker","Flamethrower","Minigun","SatchelCharge","Detonator","SprayCan","FireExtinguisher",
    "Camera","NightvisionGoggles", "ThermalGoggles","Parachute"
};
^^ Above is the weapon name declarations and having them in the correct order in the array to read them properly.

pawn Код:
command(giveweapon, playerid, params[])
{
    new sWeapon;
    new str[128];
    new wepid, id, ammo;
   
    if(sscanf(params, "udd", id, wepid, ammo)) return SendClientMessage(playerid, 0x66666666, "Usage: /giveweapon [Player ID] [Weapon ID] [Ammo] * You can only give 5000 ammo with the weapon *");
    {
        //sWeapon = GetWeaponModelIDFromName(wepid);
        //if(sWeapon < 1 || sWeapon > 47) return SendClientMessage(playerid, 0x66666666, "That weapon model or ID doesn't exist.");
        if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0x66666666, "That player is not connected.");
        if(ammo > 5000 || ammo < 0) return SendClientMessage(playerid, 0x66666666, "You can only give between 1-5000 ammo");
        if(playerid == id)
        {
            format(str, sizeof(str), "You have given yourself a %s [ID %d] with '%d' ammo.", WeaponNames[sWeapon], sWeapon, ammo);
            SendClientMessage(id, 0x99000000, str);
            GivePlayerWeapon(id, wepid, ammo);
        }
        else
        {
            format(str, sizeof(str), "You have given %s a '%s [ID %d]' with '%d' ammo.", RemoveUnderScore(id), WeaponNames[sWeapon], sWeapon, ammo);
            SendClientMessage(playerid, 0x99000000, str);
            format(str, sizeof(str), "You have been given a '%s [ID %d]' with '%d' ammo by %s", WeaponNames[sWeapon], sWeapon, ammo, RemoveUnderScore(playerid));
            SendClientMessage(id, 0x99000000, str);
            GivePlayerWeapon(id, wepid, ammo);
        }
    }
    return 1;
}
^^ That is the actual command script, it is not finished as you can clearly see, I am having issue with it

pawn Код:
GetWeaponModelIDFromName(wname[])
{
    for(new i = 0; i < 47; i++)
    {
        if (i == 19 || i == 20 || i == 21) continue;
        if (strfind(WeaponNames[i], wname, true) != -1)
        {
            return i;
        }
    }
    return 1;
}
^^ That is the stock I use to actually read the correct name from the array..

Any / immediate help would be appreciated.


Re: Giveweapon issues - vIBIENNYx - 18.05.2012

Hang on, I think i found the issue.. Will edit the first post with the correct script if I do


Re: Giveweapon issues - MP2 - 18.05.2012

pawn Код:
if(sscanf(params, "us[256]", id, wepid, ammo))
You have two specifiers (u and s) but 3 variables.


Re: Giveweapon issues - vIBIENNYx - 18.05.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
pawn Код:
if(sscanf(params, "us[256]", id, wepid, ammo))
You have two specifiers (u and s) but 3 variables.
Yeah, just edited my post, the issue is retrieving the names from the array, see lines

pawn Код:
//sWeapon = GetWeaponModelIDFromName(wepid);
//if(sWeapon < 1 || sWeapon > 47) return SendClientMessage(playerid, 0x66666666, "That weapon model or ID doesn't exist.");
That is where the issue is, if I "wepid" to "params" (Which is the only function that doesn't produce an error) nothing happens, the correct weapon now spawns with the correct amount of ammo, the issue is receiving the name and ID respectively.


Re: Giveweapon issues - vIBIENNYx - 18.05.2012

Sorry for the double post AGAIN but..

I seem to have fixed it, except with this code:

pawn Код:
command(giveweapon, playerid, params[])
{
    new sWeapon;
    new str[128];
    new id, ammo;
   
    if(sscanf(params, "usd[20]", id, params, ammo)) return SendClientMessage(playerid, 0x66666666, "Usage: /giveweapon [Player ID] [Weapon ID] [Ammo] * You can only give 5000 ammo with the weapon *");
    {
        sWeapon = GetWeaponModelIDFromName(params);
        if(sWeapon < 1 || sWeapon > 47) return SendClientMessage(playerid, 0x66666666, "That weapon model or ID doesn't exist.");
        if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0x66666666, "That player is not connected.");
        if(ammo > 5000 || ammo < 0) return SendClientMessage(playerid, 0x66666666, "You can only give between 1-5000 ammo");
        if(playerid == id)
        {
            format(str, sizeof(str), "You have given yourself a %s [ID %d] with '%d' ammo.", WeaponNames[sWeapon], sWeapon, ammo);
            SendClientMessage(id, 0x99000000, str);
            GivePlayerWeapon(id, sWeapon, ammo);
        }
        else
        {
            format(str, sizeof(str), "You have given %s a '%s [ID %d]' with '%d' ammo.", RemoveUnderScore(id), WeaponNames[sWeapon], sWeapon, ammo);
            SendClientMessage(playerid, 0x99000000, str);
            format(str, sizeof(str), "You have been given a '%s [ID %d]' with '%d' ammo by %s", WeaponNames[sWeapon], sWeapon, ammo, RemoveUnderScore(playerid));
            SendClientMessage(id, 0x99000000, str);
            GivePlayerWeapon(id, sWeapon, ammo);
        }
    }
    return 1;
}
It won't allow me to search via ID, only by name.. Meaning that well, if someone wants Weapon ID: 5, it will spawn them an MP5, not Weapon ID 5.


AW: Re: Giveweapon issues - Nero_3D - 18.05.2012

Just use the custom specifier weapon, it should be included in the newest sscanf include

pawn Код:
// we use k<function>
    if(sscanf(params, "uk<weapon>d", id, sWeapon, ammo)) return SendClientMessage(playerid, 0x66666666, "Usage: /giveweapon [Player ID] [Weapon ID] [Ammo] * You can only give 5000 ammo with the weapon *");
// If its an invalid weapon the custom function returns -1
        if(sWeapon == -1) return SendClientMessage(playerid, 0x66666666, "That weapon model or ID doesn't exist.");



Re: AW: Re: Giveweapon issues - vIBIENNYx - 18.05.2012

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just use the custom specifier weapon, it should be included in the newest sscanf include

pawn Код:
// we use k<function>
    if(sscanf(params, "uk<weapon>d", id, sWeapon, ammo)) return SendClientMessage(playerid, 0x66666666, "Usage: /giveweapon [Player ID] [Weapon ID] [Ammo] * You can only give 5000 ammo with the weapon *");
// If its an invalid weapon the custom function returns -1
        if(sWeapon == -1) return SendClientMessage(playerid, 0x66666666, "That weapon model or ID doesn't exist.");
Thanks for the help but now, with that code you gave me, replacing those two line I always get the message:

You have given %s a 'Brass Knuckles [ID 1]' with '%d' ammo.

This is with a combination of different names and ID's, no weapons are given, only Brass Knuckles are displayed and given..


Re: AW: Re: Giveweapon issues - vIBIENNYx - 18.05.2012

Okay, I fixed it by commenting one of the lines out..

Now, the ID works the name works, but it has to be EXACT and Case Sensitive, is there a way to change this?


AW: Re: AW: Re: Giveweapon issues - Nero_3D - 19.05.2012

Quote:
Originally Posted by vIBIENNYx
Посмотреть сообщение
Okay, I fixed it by commenting one of the lines out..

Now, the ID works the name works, but it has to be EXACT and Case Sensitive, is there a way to change this?
Just create your own custom sscanf function, the custom weapon function can be found within the include


Re: Giveweapon issues - vIBIENNYx - 19.05.2012

Thanks, working on it now.. Thanks to you both..