Need help for a simple command.
#1

Well, I got a little problem with a command for selling guns and here it is -

Код:
if(strcmp(cmdtext,"/sellak",true)==0)
{
  new playerb, bullets;
  if(gTeam[playerid] !=  TEAM_GUNDEALERS) return SendClientMessage(playerid,COLOR_RED,"You are not Emmet's Place Worker!");
if(!IsPlayerNearPlayer(playerid, playerb, 5)) return SendClientMessage(playerid, COLOR_RED, "You are too far away from that player.");
  if(bullets < 1 || > 400) return SendClientMessage(playerid, 0xFF9900AA, "You can only take 1-400 bullets at once!");
  SendClientMessage(playerb, 0xFF9900AA, "Emmet Worker has given you a AK-47 and a box of ammo.");
  GivePlayerWeapon(playerb, 30, bullets);
  GivePlayerMoney(playerid, -500);
  return 1;
}
But when I try to sell to someone, it says "You are too far away from that player" or either "You can only take 1-400 bullets at once!"...

I've also added this function:

Код:
stock IsPlayerNearPlayer(playerid, targetid, Float:radius)
{
	new Float:x, Float:y, Float:z;
	GetPlayerPos(targetid, x, y, z);
	if(IsPlayerInRangeOfPoint(playerid, radius ,x, y, z))
	{
	    return 1;
	}
	return 0;
}
Did I forgot something ? It compiles fine and Im just confused, should I add "playerid" at "new playerb, bullets;" ?
Or If someone can make it working, thanks in advance.
Everyone who atleast try to help me will be +Repped x)
Reply
#2

pawn Код:
if(strcmp(cmdtext,"/sellak",true)==0)
{
    new playerb, bullets, Float:x, Float:y, Float:z;
    GetPlayerPos(playerb, x, y, z);
    if(gTeam[playerid] !=  TEAM_GUNDEALERS) return SendClientMessage(playerid,COLOR_RED,"You are not Emmet's Place Worker!");
    if(IsPlayerInRangeOfPoint(playerid, 5.0, x, y, z))
    {
        if(bullets < 1 || bullets > 400) return SendClientMessage(playerid, 0xFF9900AA, "You can only take 1-400 bullets at once!");
        SendClientMessage(playerb, 0xFF9900AA, "Emmet Worker has given you a AK-47 and a box of ammo.");
        GivePlayerWeapon(playerb, 30, bullets);
        GivePlayerMoney(playerid, -500);
    }
    else SendClientMessage(playerid, COLOR_RED, "You are too far away from that player.");
    return 1;
}
Try it.
Reply
#3

Thanks, I will... anyways, thanks for replying x)

P.S: +Repped
Reply
#4

Im sorry for double-posting, but its the same again, I think its something else.. I mean if I type only /sellak, it shows me "You are too far away from this player", and when I type "/sell ak id ammo - ex: /sellak 1 50" it shows me unknown command ? What should be wrong ?
Reply
#5

Do you have sscanf installed?
Reply
#6

Yeah I was thinking about that.. It may be cause of this - I dont have it.
Reply
#7

Well it's not necessarily because you don't have it, but it's the easiest way to accomplish what you're trying to do here. Install it, and try this out.
pawn Код:
if(strcmp(cmdtext,"/sellak",true)==0)
{
    new playerb, bullets;
    if(sscanf(params,"ii",playerb,bullets)) return SendClientMessage(playerid,-1,"Usage: /sellak [id] [ammo]");
    else {
        if(gTeam[playerid] !=  TEAM_GUNDEALERS) return SendClientMessage(playerid,COLOR_RED,"You are not Emmet's Place Worker!");
        else {
            if(IsPlayerNearPlayer(playerid, playerb, 5)) {
                if(bullets < 1 || > 400) return SendClientMessage(playerid, 0xFF9900AA, "You can only take 1-400 bullets at once!");
                else {
                    SendClientMessage(playerb, 0xFF9900AA, "Emmet Worker has given you a AK-47 and a box of ammo.");
                    GivePlayerWeapon(playerb, 30, bullets);
                    GivePlayerMoney(playerb, -500);
                    GivePlayerMoney(playerid,500);
                }
            }
            else return SendClientMessage(playerid, COLOR_RED, "You are too far away from that player.");
        }
    }
    return 1;
}
Reply
#8

The problem was indeed caused by not specifying any parameters. They magically appear and are not used at all. So playerb is always ID 0 and bullets as well.

The problem with above code from zDevon is, that the variable PARAMS doesn't exist. Even he is making stuff up. Switch to another command processor (damn, I have done that a lot in the past 15 minutes) to fully enjoy sscanf and the easiness of writing commands.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)