COMMAND:giveweapon(playerid, params[]) { new targetid,weaponid,ammo; if(sscanf(params, "uii", targetid, weaponid, ammo)) SendClientMessage(playerid, COLOR_GREY, "USAGE: /giveweapon [player] [weapon] [ammo]"); else { if (PlayerInfo[playerid][LoggedIn] == false) return SendClientMessage(playerid, COLOR_WHITE, "You must be logged in to use this."); if (!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE, "This player is not connected !"); if(IsPlayerNPC(targetid)) return SendClientMessage(playerid, COLOR_GREY, "Can't do this to a NPC."); if (GetPVarInt(playerid, "Jailed") != 0) return true; if(GetPVarInt(playerid, "Admin") >= 3) { new gunname[32]; new sendername[24]; new pName[24]; new str1[128]; GetPlayerName(playerid, pName, 24); GetPlayerName(targetid, sendername, 24); GiveNameSpace(pName); GiveNameSpace(sendername); GetWeaponName(weaponid, gunname, sizeof(gunname)); format(str1, sizeof(str1), "Server: %s has given %s a %s.", pName, gunname, sendername); SendAdminMessage(COLOR_ORANGE, str1); GivePlayerWeaponEx(playerid, weaponid, ammo); AdminLog(playerid,"giveweapon",str1); } else { SendClientMessage(playerid, COLOR_RED, "You do not have access to this command !"); } } return 1; } stock GivePlayerWeaponEx(playerid, weaponid, ammo) { if(weaponid >= 2 && weaponid <= 15) { SetPVarInt(playerid, "MeeleWeapon", weaponid); if(GetPVarInt(playerid, "MeeleWeapon") < 0) SetPVarInt(playerid, "MeeleWeapon", 0); GivePlayerWeapon(playerid, weaponid, 1); return 1; } if(weaponid >= 22 && weaponid <= 24 && weaponid >= 28 && weaponid <= 29) { SetPVarInt(playerid, "SecondaryWeapon", weaponid); SetPVarInt(playerid, "SecondaryWeaponAmmo", ammo); if(GetPVarInt(playerid, "SecondaryWeapon") < 0) SetPVarInt(playerid, "SecondaryWeapon", 0); GivePlayerWeapon(playerid, weaponid, ammo); return 1; } if(weaponid >= 25 && weaponid <= 27 && weaponid >= 30 && weaponid <= 34) { SetPVarInt(playerid, "PrimaryWeapon", weaponid); SetPVarInt(playerid, "PrimaryAmmo", ammo); if(GetPVarInt(playerid, "PrimaryWeapon") < 0) SetPVarInt(playerid, "PrimaryWeapon", 0); GivePlayerWeapon(playerid, weaponid, ammo); return 1; } SendClientMessage(playerid, COLOR_ORANGE, "Error: That weapon isn't part of the script or can be bought at a 24/7"); return true; }
public OnPlayerCommandPerformed(playerid, cmdtext[], success){
if (PlayerInfo[playerid][LoggedIn] == false) return SendClientMessage(playerid, COLOR_WHITE, "You must be logged in to use this."), 0;
return 1;
}
getUserName(pid){
new s[24];
GetPlayerName(pid,s,24);
GiveNameSpace(s);
return s;
}
getWeaponName(wid){
new s[32];
GetWeaponName(wid,s,32);
return s;
}
GivePlayerWeaponEx(playerid, weaponid, ammo)
{
switch(weaponid){
case 2..15:{
SetPVarInt(playerid, "MeeleWeapon", weaponid);
if(GetPVarInt(playerid, "MeeleWeapon") < 0) SetPVarInt(playerid, "MeeleWeapon", 0);
GivePlayerWeapon(playerid, weaponid, 1);
}
case 22..24,28..29:{
SetPVarInt(playerid, "SecondaryWeapon", weaponid);
SetPVarInt(playerid, "SecondaryWeaponAmmo", ammo);
if(GetPVarInt(playerid, "SecondaryWeapon") < 0) SetPVarInt(playerid, "SecondaryWeapon", 0);
GivePlayerWeapon(playerid, weaponid, ammo);
}
case 25..27,30..34:{
SetPVarInt(playerid, "PrimaryWeapon", weaponid);
SetPVarInt(playerid, "PrimaryAmmo", ammo);
if(GetPVarInt(playerid, "PrimaryWeapon") < 0) SetPVarInt(playerid, "PrimaryWeapon", 0);
GivePlayerWeapon(playerid, weaponid, ammo);
}
default:{
SendClientMessage(playerid, COLOR_ORANGE, "Error: That weapon isn't part of the script or can be bought at a 24/7");
}
}
return 1;
}
COMMAND:giveweapon(playerid, params[])
{
if(GetPVarInt(playerid, "Admin") < 3)return SendClientMessage(playerid, COLOR_GREY, "You are not admin!");
new targetid,weaponid,ammo;
if(sscanf(params, "uii", targetid, weaponid, ammo)) return SendClientMessage(playerid, COLOR_GREY, "USAGE: /giveweapon [player] [weapon] [ammo]");
if (!IsPlayerConnected(targetid)) return SendClientMessage(playerid, COLOR_WHITE, "This player is not connected !");
//giving weapon : changed playerid to targetid
GivePlayerWeaponEx(targetid,weaponid,ammo);
//message for players
format(s,90,"Server: %s has given %s to %s.",getUserName(playerid),getWeaponName(weaponid),getUserName(targetid));
SendAdminMessage(COLOR_ORANGE, s);
AdminLog(playerid,"giveweapon",s);
return 1;
}
why are you using normal variables and pvars, maybe stick with one solution only
PHP Code:
|
COMMAND:giveweapon(playerid, params[])
{
if(PlayerInfo[playerid][Level] < 3) return SendError(playerid,"{E4EDF4}You must to be Admin Level 5 to use that command");
//--------------------------------------------------------------------------
new Player, Weapon[10], Ammo, WeaponID, WeapName[50];
//--------------------------------------------------------------------------
if(sscanf(params, "us[10]I(9999)", Player, Weapon, Ammo)) return
SendUsage(playerid, "/giveweapon [PlayerID] [Weapon ID/Weapon Name] [Ammo]");
//--------------------------------------------------------------------------
if(Ammo <= 0 || Ammo > 9999) return
SendError(playerid, "{E4EDF4}Invalid ammo entered");
//--------------------------------------------------------------------------
if(strval(Weapon) == 38) return
SendError(playerid, "{E4EDF4}This weapons is forbbiden!");
//--------------------------------------------------------------------------
if(!IsPlayerConnected(Player)) return
SendError(playerid, "{E4EDF4}Player is not connected.");
//--------------------------------------------------------------------------
if(IsNumeric(Weapon)) WeaponID = strval(Weapon);
else WeaponID = GetWeaponIDFromName(Weapon);
if(!IsValidWeapon(WeaponID)) return SendError(playerid, "{E4EDF4}Invalid weapon ID!");
//--------------------------------------------------------------------------
GetWeaponName(WeaponID, WeapName, 50), GivePlayerWeapon(Player, WeaponID, Ammo), CMDMessageToAdmins(playerid, "Give Weapon");
//--------------------------------------------------------------------------
FormatMSG(Player, COLOR_YELLOW, "Administrator {F81414}%s {FFFF1A}gave you a {F81414}%s(%d) {FFFF1A}with {F81414}%d {FFFF1A}rounds of ammo", PlayerName(playerid), WeapName, WeaponID, Ammo);
FormatMSG(playerid, COLOR_YELLOW, "You have given {F81414}%s {FFFF1A}a {F81414}%s(%d) {FFFF1A}with {F81414}%d {FFFF1A}rounds of ammo", PlayerName(Player), Player, WeapName, WeaponID, Ammo);
//--------------------------------------------------------------------------
return 1;
}
what crap is this, you dont even provide your formatmsg, senderror code?
and when you use sscanf you dont need to check if entered number is numeric |