Changing a cmd to ZCMD
#1

Hey, I ended up copying a cmd to gain some knowledge on how its supposed to look and have edited it , but I aint edited it enough, it was not on the zcmd processor and now I am getting a few errors, if you know what i should do, please help me

Код:
(3921) : error 017: undefined symbol "tmp"
(3921) : error 017: undefined symbol "cmdtext"
(3922) : error 017: undefined symbol "tmp"
(3930) : error 017: undefined symbol "tmp"
(3931) : error 017: undefined symbol "tmp"
(3931) : error 017: undefined symbol "cmdtext"
(3932) : error 017: undefined symbol "tmp"
(3933) : error 017: undefined symbol "tmp"
(3935) : error 017: undefined symbol "tmp"
(3935) : error 017: undefined symbol "cmdtext"
(3936) : error 017: undefined symbol "tmp"
pawn Код:
CMD:sellmarijuana(playerid, params[])//Line 3912
{
    if(IsPlayerConnected(playerid))
    {
        /*if(PlayerInfo[playerid][pJob] != 2)
        {
            SendClientMessage(playerid, -1, "ERROR: You are not a Drug Dealer!");
            return 1;
        }*/

        tmp = strtok(cmdtext, idx);//Line 3921
        if(!strlen(tmp))//Line 3922
        {
            SendClientMessage(playerid, -1, "USAGE: /selldrugs [playerid] [amount]");
            return 1;
        }
        new sellpotstring[248];
        new playa;
        new needed;
        playa = strval(tmp);//Line 3930
        tmp = strtok(cmdtext, idx);//Line 3931
        if(!strlen(tmp)) { return 1; }//Line 3932
        needed = strval(tmp);
        if(needed < 1 || needed > 50) { SendClientMessage(playerid, -1, "ERROR: Selling Marijuana can be only in limits of 1 gram to 50 grams."); return 1; }
        tmp = strtok(cmdtext, idx);//Line 3935
        if(!strlen(tmp)) { return 1; }//Line 3936
        if(needed > PlayerInfo[playerid][pMarijuana]) { SendClientMessage(playerid, -1, "ERROR: You don't have that much!"); return 1; }
        if(IsPlayerConnected(playa))
        {
            if(playa != INVALID_PLAYER_ID)
            {
                if (ProxDetectorS(8.0, playerid, playa))
                {
                    if(playa != playerid)
                    {
                        format(sellpotstring, sizeof(sellpotstring), "INFO: You have gave %s %d grams of drugs.", GetPlayerNameEx(playa), needed);
                        SendClientMessage(playerid, -1, sellpotstring);
                        format(sellpotstring, sizeof(sellpotstring), "INFO: %s has just gave you %d grams of drugs.", GetPlayerNameEx(playerid), needed);
                        SendClientMessage(playa, -1, sellpotstring);
                        PlayerInfo[playa][pMarijuana] += needed;
                        PlayerInfo[playerid][pMarijuana] -= needed;
                        PlayerPlayerActionMessage(playerid,playa,15.0,"Has just gave some drugs to");
                    }
                    else
                    {
                        SendClientMessage(playerid, -1, "ERROR: You can't sell yourself drugs!");
                    }
                }
                else
                {
                    SendClientMessage(playerid, -1, "ERROR: You arn't near that player!");
                }
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "ERROR: Invalid ID.");
        }
    }
    return 1;
}//Line 3971
There is a chance this is a simple fix, I have a feeling there is another way to make this cmd with ZCMD without using "tmp" and "cmdtext"
Reply
#2

That should work, the only thing you need to do is changing cmdtext to params, and creating the tmp variable which was not defined.

Код:
CMD:sellmarijuana(playerid, params[])//Line 3912
{
	if(IsPlayerConnected(playerid))
	{
 		/*if(PlayerInfo[playerid][pJob] != 2)
	  	{
			SendClientMessage(playerid, -1, "ERROR: You are not a Drug Dealer!");
			return 1;
	  	}*/
		new tmp;
  		tmp = strtok(params, idx);//Line 3921
		if(!strlen(tmp))//Line 3922
		{
			SendClientMessage(playerid, -1, "USAGE: /selldrugs [playerid] [amount]");
			return 1;
		}
		new sellpotstring[248];
		new playa;
		new needed;
		playa = strval(tmp);//Line 3930
		tmp = strtok(params, idx);//Line 3931
		if(!strlen(tmp)) { return 1; }//Line 3932
		needed = strval(tmp);
		if(needed < 1 || needed > 50) { SendClientMessage(playerid, -1, "ERROR: Selling Marijuana can be only in limits of 1 gram to 50 grams."); return 1; }
		tmp = strtok(params, idx);//Line 3935
		if(!strlen(tmp)) { return 1; }//Line 3936
		if(needed > PlayerInfo[playerid][pMarijuana]) { SendClientMessage(playerid, -1, "ERROR: You don't have that much!"); return 1; }
		if(IsPlayerConnected(playa))
		{
  			if(playa != INVALID_PLAYER_ID)
  			{
				if (ProxDetectorS(8.0, playerid, playa))
				{
					if(playa != playerid)
				 	{
				  		format(sellpotstring, sizeof(sellpotstring), "INFO: You have gave %s %d grams of drugs.", GetPlayerNameEx(playa), needed);
						SendClientMessage(playerid, -1, sellpotstring);
						format(sellpotstring, sizeof(sellpotstring), "INFO: %s has just gave you %d grams of drugs.", GetPlayerNameEx(playerid), needed);
						SendClientMessage(playa, -1, sellpotstring);
						PlayerInfo[playa][pMarijuana] += needed;
						PlayerInfo[playerid][pMarijuana] -= needed;
						PlayerPlayerActionMessage(playerid,playa,15.0,"Has just gave some drugs to");
					}
					else
					{
						SendClientMessage(playerid, -1, "ERROR: You can't sell yourself drugs!");
					}
				}
				else
				{
		  			SendClientMessage(playerid, -1, "ERROR: You arn't near that player!");
				}
			}
		}
		else
		{
  			SendClientMessage(playerid, -1, "ERROR: Invalid ID.");
		}
	}
	return 1;
}//Line 3971
Reply
#3

EDITED: I'll make a new post for this other problem.
Reply
#4

pawn Код:
CMD:sellmarijuana(playerid, params[])
{
    /*if(PlayerInfo[playerid][pJob] != 2)
    {
        SendClientMessage(playerid, -1, "ERROR: You are not a Drug Dealer!");
        return 1;
    }*/


    if(isnull(params)) SendClientMessage(playerid, -1, "USAGE: /selldrugs [playerid] [amount]");
    else{
        new tmp[5],idx; // [5] because max params lenght for id is 4 (max player id 1000) + 1 end of string and max grams is 50 (two chars)
        strcat((tmp[0]=EOS,tmp),strtok(params, idx)); // cmdtext is now params ! storing playerid
        new playa = strval(tmp);

        if(!IsPlayerConnected(playa)) SendClientMessage(playerid, -1, "ERROR: Invalid ID.");
        else if(playa == playerid) SendClientMessage(playerid, -1, "ERROR: You can't sell yourself drugs!");
        else if(!ProxDetectorS(8.0, playerid, playa)) SendClientMessage(playerid, -1, "ERROR: You arn't near that player!");
        else{
            strcat((tmp[0]=EOS,tmp),strtok(params, idx));
            if(isnull(tmp)) SendClientMessage(playerid, -1, "ERROR: Set amount!");
            else{
                new needed = strval(tmp);
                if(!(0 < needed < 51)) SendClientMessage(playerid, -1, "ERROR: Selling Marijuana can be only in limits of 1 gram to 50 grams.");
                else if(needed > PlayerInfo[playerid][pMarijuana]) SendClientMessage(playerid, -1, "ERROR: You don't have that much!");
                else{
                    new sellpotstring[128];
                    format(sellpotstring, sizeof(sellpotstring), "INFO: You have gave %s %d grams of drugs.", GetPlayerNameEx(playa), needed);
                    SendClientMessage(playerid, -1, sellpotstring);
                    format(sellpotstring, sizeof(sellpotstring), "INFO: %s has just gave you %d grams of drugs.", GetPlayerNameEx(playerid), needed);
                    SendClientMessage(playa, -1, sellpotstring);
                    PlayerInfo[playa][pMarijuana] += needed;
                    PlayerInfo[playerid][pMarijuana] -= needed;
                    PlayerPlayerActionMessage(playerid,playa,15.0,"Has just gave some drugs to");
                }
            }
        }
    }
    return 1;
}
You should use sscanf instead of old good strtok, it's better
Reply
#5

Actually if your are lazy just rename params to cmdtext and add somewhere the tmp variable
pawn Код:
CMD:sellmarijuana(playerid, cmdtext[])
No clue why everyone uses 'params' anyway

The best would be if you rewrite your commands with sscanf but that could be a lot of work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)