/givewep command problem -
Face9000 - 05.04.2013
Hello there, i got a big (?) problem with this /givewep command i made. Sometimes it works and it gives the correct weapon i type, sometimes it doesn't, sometimes doesn't even give the weapon at the player. Wtf?
pawn Код:
CMD:givewep(playerid,params[])
{
if(pInfo[playerid][Logged] == 0) return SCM(playerid,0x0080C0FF,"Please login before using this command.");
if(pInfo[playerid][Admin] >= 3)
{
if(GetPVarInt(playerid,"CmdTime")>GetTickCount())return SCM(playerid,0xFF0000FF,"Please wait before using this command again.");
new Target;
new Weapid;
new amt;
if(sscanf(params,"uid",Weapid,amt)) return SCM(playerid,0xff0000FF,"Usage /givewep [playerid] [weaponid] [ammo]");
if(Target == INVALID_PLAYER_ID) return SCM(playerid,red,"Error: Wrong player ID");
if(Weapid == 36 || Weapid == 37 || Weapid == 38 || Weapid == 41 || Weapid == 43 || Weapid == 44 || Weapid == 45) return SCM(playerid,0xff0000FF,"Error: Invalid weapon id.");
if(Weapid < 0 || Weapid > 46) return SCM(playerid,0xFFFFFFFF,"You have entered an invalid weapon id.");
if(amt > 999) return SCM(playerid,0xff0000FF,"Error: You can give a max of 999 ammo for weapon.");
GivePlayerWeapon(Target,Weapid,amt);
new tname[MAX_PLAYER_NAME];
GetPlayerName(Target,tname,sizeof(tname));
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid,pname,sizeof(pname));
new tstring[110];
new pstring[110];
new echos[128];
format(tstring,sizeof(tstring),"You have received weapon id %d with %d ammo from %s (%d).",Weapid,amt,pname,playerid);
format(pstring,sizeof(pstring),"You have given weapon id %d with %d ammo to %s (%d).",Weapid,amt,tname,Target);
format(echos,sizeof(echos),"1,8** Admin %s (%d) has given weapon id %d with %d ammo to %s (%d)",pname,playerid,Weapid,amt,tname,Target);
SCM(Target,COLOR_BLUE,tstring);
SCM(playerid,COLOR_BLUE,pstring);
IRC_GroupSay(gGroupID, IRC_CHANNEL, echos);
IRC_GroupSay(gGroupID, IRC_ACHANNEL, echos);
SetPVarInt(playerid,"CmdTime",GetTickCount()+2000);
pInfo[Target][AdminActions]++;
}
return 1;
}
Got no errors/warnings when compiling.
Re: /givewep command problem -
MattyG - 05.04.2013
pawn Код:
CMD:givewep(playerid,params[])
{
if(pInfo[playerid][Logged] == 0) return SCM(playerid,0x0080C0FF,"Please login before using this command.");
if(pInfo[playerid][Admin] >= 3)
{
if(GetPVarInt(playerid,"CmdTime")>GetTickCount())return SCM(playerid,0xFF0000FF,"Please wait before using this command again.");
new Target;
new Weapid;
new amt;
if(sscanf(params,"uid",Target, Weapid,amt)) return SCM(playerid,0xff0000FF,"Usage /givewep [playerid] [weaponid] [ammo]");
if(Target == INVALID_PLAYER_ID) return SCM(playerid,red,"Error: Wrong player ID");
if(Weapid == 36 || Weapid == 37 || Weapid == 38 || Weapid == 41 || Weapid == 43 || Weapid == 44 || Weapid == 45) return SCM(playerid,0xff0000FF,"Error: Invalid weapon id.");
if(Weapid < 0 || Weapid > 46) return SCM(playerid,0xFFFFFFFF,"You have entered an invalid weapon id.");
if(amt > 999) return SCM(playerid,0xff0000FF,"Error: You can give a max of 999 ammo for weapon.");
GivePlayerWeapon(Target,Weapid,amt);
new tname[MAX_PLAYER_NAME];
GetPlayerName(Target,tname,sizeof(tname));
new pname[MAX_PLAYER_NAME];
GetPlayerName(playerid,pname,sizeof(pname));
new tstring[110];
new pstring[110];
new echos[128];
format(tstring,sizeof(tstring),"You have received weapon id %d with %d ammo from %s (%d).",Weapid,amt,pname,playerid);
format(pstring,sizeof(pstring),"You have given weapon id %d with %d ammo to %s (%d).",Weapid,amt,tname,Target);
format(echos,sizeof(echos),"1,8** Admin %s (%d) has given weapon id %d with %d ammo to %s (%d)",pname,playerid,Weapid,amt,tname,Target);
SCM(Target,COLOR_BLUE,tstring);
SCM(playerid,COLOR_BLUE,pstring);
IRC_GroupSay(gGroupID, IRC_CHANNEL, echos);
IRC_GroupSay(gGroupID, IRC_ACHANNEL, echos);
SetPVarInt(playerid,"CmdTime",GetTickCount()+2000);
pInfo[Target][AdminActions]++;
}
return 1;
}
Try that, also try correcting those indents, makes the code look strange
Re: /givewep command problem -
Face9000 - 05.04.2013
Can you tell me what was the problem?
Re: /givewep command problem -
BigGroter - 05.04.2013
pawn Код:
if(sscanf(params,"uid",Weapid,amt)) return SCM(playerid,0xff0000FF,"Usage /givewep [playerid] [weaponid] [ammo]");
You need to add Target before Weapid and amt.
Like such.
pawn Код:
if(sscanf(params,"uid",Target,Weapid,amt)) return SCM(playerid,0xff0000FF,"Usage /givewep [playerid] [weaponid] [ammo]");
Re: /givewep command problem -
MattyG - 05.04.2013
Quote:
Originally Posted by Logitech90
Can you tell me what was the problem?
|
Yeah, I probably should have said that, sorry: you needed the "Target" in the sscanf
Re: /givewep command problem -
Face9000 - 05.04.2013
Oh, thank you very much @ both, repped.