/giveallweapon problem [Weapon Name]
#1

well..so i've made a command with /giveallweapon and it works well..but the only issue i face is when it sends the message to the players..it doesn't show the weapon's name:
Quote:

CMD:giveallweapons(playerid, params[])
{
new weaponid,model[50],ammo;
if(pInfo[playerid][Admin]<4) return SendClientMessage(playerid, RED, "ERROR: You are not authorized to use this command");
if(sscanf(params, "si", model, ammo)) return SendClientMessage(playerid, RED, "ERROR: /giveallweapon [weaponid] [ammo]");
weaponid = GetWeaponNameID(model);
if(weaponid > 47 || weaponid < 1) return SendClientMessage (playerid, RED, "ERROR: Invailed weapon name");
foreach(Player,i)
{
GivePlayerWeapon(i, weaponid, ammo);
PlayerPlaySound(i, 1057,0.0,0.0,0.0);
}
format(str, SOS, "Administrator %s has given all players weapon [%s] with [%i] ammo ", pInfo[playerid][Name], weaponid, ammo);
SendClientMessageToAll(BLUE, str);
format(str, SOS, "Admin: %s has used command GIVEALLWEAPONS", pInfo[playerid][Name]);
SendCMDAdmin(BLUE, str);
return 1;
}

Quote:

stock GetWeaponNameID(wname[])
{
for(new i = 0; i < 42; i++)
{
if (strfind(WeaponNames[i], wname, true) != -1)
return i+4;
}
return -1;
}

Reply
#2

Try with:

PHP код:
new GunName[47][20] = 
{
    
"Fist","Brass Knuckles","Golf Club","Nightstick","Knife","Basebal Bat","Shovel","Pool Cue","Katana","Chainsaw","Double-ended Dildo","Dildo","Vibrator",
    
"Silver Vibrator","Flowers","Cane","Grenade","Tear Gas","Molotv Cocktail","?","?","?","9mm","Silenced 9mm","Desert Eagle","Shotgun","Sawnoff-Shotgun",
    
"Combat Shotgun","Micro-SMG","MP5","Ak-47","M4","Tec9","Country Rifle","Sniper Rifle","RPG","HS-RPG","Flame-Thrower","Minigun","Satchel Charge","Detonator",
    
"Spray Can","Fire Extinguisher","Camera","Night Goggles","Thermal Goggles","Parachute"
};
// Example of use:
CMD:mygun(playerid)
{
    new 
text[48];
    
format(text,sizeof text,"You've got a nice: {FFFFFF}%s",GunName[GetPlayerWeapon(playerid)]);
    
SendClientMessage(playerid,0xFFDD22FF,text);
    return 
1;

Your command should be:

PHP код:
CMD:giveallweapons(playeridparams[])
{
new 
weaponid,model[50],ammo;
if(
pInfo[playerid][Admin]<4) return SendClientMessage(playeridRED"ERROR: You are not authorized to use this command");
if(
sscanf(params"si"modelammo)) return SendClientMessage(playeridRED"ERROR: /giveallweapon [weaponid] [ammo]");
weaponid GetWeaponNameID(model);
if(
weaponid 47 || weaponid 1) return SendClientMessage (playeridRED"ERROR: Invailed weapon name");
foreach(
Player,i)
{
GivePlayerWeapon(iweaponidammo);
PlayerPlaySound(i1057,0.0,0.0,0.0);
}
format(strSOS"Administrator %s has given all players weapon [%s] with [%i] ammo "pInfo[playerid][Name], GunName[weaponid], ammo);
SendClientMessageToAll(BLUEstr);
format(strSOS"Admin: %s has used command GIVEALLWEAPONS"pInfo[playerid][Name]);
SendCMDAdmin(BLUEstr);
return 
1;

Font: arakuta
https://sampforum.blast.hk/showthread.php?tid=435457
Reply
#3

"weaponid" is integer and you use %s specifier in format to get the name of it which won't happen. Since you have an array with the names, just use it and index the weaponid itself.

A native function exists by the way: https://sampwiki.blast.hk/wiki/GetWeaponName

Just for more: If you open sscanf2.inc and scroll at the bottom, you'll notice a custom specifier called "weapon":
pawn Код:
SSCANF:weapon(string[])
{
    ...
}
You can replace in the if/else if statements the function strcmp with strfind (remember if what returns is not equal to -1, the text was found) and simply use in sscanf (in commands):
pawn Код:
new weaponid, ammo;

if (sscanf(params, "k<weapon>i", weaponid, ammo)) return ... // send usage
if (weaponid == -1) return ... // invalid weapon name/ID
Reply
#4

Thank you all of helping me,it worked! +REP
btw:if you wont mind guys can anyone tell me what was the problem/error in my array?!
about getweaponname,well i didn't script for more than 1year i forgot about it :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)