/giveweapon isn't working.
#1

So I made a custom weapon giving function for my anti-cheat but the /giveweapon command isn't working. In the giveweapon function after typing /giveweapon 0 24 50 it says

SendClientMessage(playerid, COLOR_ORANGE, "Error: That weapon isn't part of the script or can be bought at a 24/7");

Code:
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;
}
Reply
#2

why are you using normal variables and pvars, maybe stick with one solution only
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success){
    if (
PlayerInfo[playerid][LoggedIn] == false) return SendClientMessage(playeridCOLOR_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(playeridweaponidammo)
{
    switch(
weaponid){
        case 
2..15:{
            
SetPVarInt(playerid"MeeleWeapon"weaponid);
            if(
GetPVarInt(playerid"MeeleWeapon") < 0SetPVarInt(playerid"MeeleWeapon"0);
            
GivePlayerWeapon(playeridweaponid1);
        }
        case 
22..24,28..29:{
            
SetPVarInt(playerid"SecondaryWeapon"weaponid);
            
SetPVarInt(playerid"SecondaryWeaponAmmo"ammo);
            if(
GetPVarInt(playerid"SecondaryWeapon") < 0SetPVarInt(playerid"SecondaryWeapon"0);
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
25..27,30..34:{
            
SetPVarInt(playerid"PrimaryWeapon"weaponid);
            
SetPVarInt(playerid"PrimaryAmmo"ammo);
            if(
GetPVarInt(playerid"PrimaryWeapon") < 0SetPVarInt(playerid"PrimaryWeapon"0);
            
GivePlayerWeapon(playeridweaponidammo);
        }
        default:{
            
SendClientMessage(playeridCOLOR_ORANGE"Error: That weapon isn't part of the script or can be bought at a 24/7");
        }
    }
    return 
1;
}
COMMAND:giveweapon(playeridparams[])
{
    if(
GetPVarInt(playerid"Admin") < 3)return SendClientMessage(playeridCOLOR_GREY"You are not admin!");
    new 
targetid,weaponid,ammo;
    if(
sscanf(params"uii"targetidweaponidammo)) return SendClientMessage(playeridCOLOR_GREY"USAGE: /giveweapon [player] [weapon] [ammo]");
    if (!
IsPlayerConnected(targetid)) return SendClientMessage(playeridCOLOR_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_ORANGEs);
    
AdminLog(playerid,"giveweapon",s);
    return 
1;

Reply
#3

Quote:
Originally Posted by codExpert
View Post
why are you using normal variables and pvars, maybe stick with one solution only
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success){
    if (
PlayerInfo[playerid][LoggedIn] == false) return SendClientMessage(playeridCOLOR_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(playeridweaponidammo)
{
    switch(
weaponid){
        case 
2..15:{
            
SetPVarInt(playerid"MeeleWeapon"weaponid);
            if(
GetPVarInt(playerid"MeeleWeapon") < 0SetPVarInt(playerid"MeeleWeapon"0);
            
GivePlayerWeapon(playeridweaponid1);
        }
        case 
22..24,28..29:{
            
SetPVarInt(playerid"SecondaryWeapon"weaponid);
            
SetPVarInt(playerid"SecondaryWeaponAmmo"ammo);
            if(
GetPVarInt(playerid"SecondaryWeapon") < 0SetPVarInt(playerid"SecondaryWeapon"0);
            
GivePlayerWeapon(playeridweaponidammo);
        }
        case 
25..27,30..34:{
            
SetPVarInt(playerid"PrimaryWeapon"weaponid);
            
SetPVarInt(playerid"PrimaryAmmo"ammo);
            if(
GetPVarInt(playerid"PrimaryWeapon") < 0SetPVarInt(playerid"PrimaryWeapon"0);
            
GivePlayerWeapon(playeridweaponidammo);
        }
        default:{
            
SendClientMessage(playeridCOLOR_ORANGE"Error: That weapon isn't part of the script or can be bought at a 24/7");
        }
    }
    return 
1;
}
COMMAND:giveweapon(playeridparams[])
{
    if(
GetPVarInt(playerid"Admin") < 3)return SendClientMessage(playeridCOLOR_GREY"You are not admin!");
    new 
targetid,weaponid,ammo;
    if(
sscanf(params"uii"targetidweaponidammo)) return SendClientMessage(playeridCOLOR_GREY"USAGE: /giveweapon [player] [weapon] [ammo]");
    if (!
IsPlayerConnected(targetid)) return SendClientMessage(playeridCOLOR_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_ORANGEs);
    
AdminLog(playerid,"giveweapon",s);
    return 
1;

u need to add to onplayercommandperformed that u also cant use any cmd if ur not spawned
Reply
#4

what?
most likely player is spawned when he is loggedin in roleplay server
Reply
#5

Try this
HTML 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;
}
Reply
#6

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
Reply
#7

Quote:
Originally Posted by codExpert
View Post
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
If him is a good scripter,hi will know what him must to do. And the command,is not complicated,I have a stunt server,not rpg,I know it's not the same,but,if you are talented,and having some brain,everithyng is easy to make.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)