ZCMD + SSCANF PROBLEM
#1

I'm trying to create /give [ID/PartOfName] [item] [amount] but im not succeding.

Here's my code:

pawn Код:
cmd(give, playerid, params[])
{
  if(IsPlayerConnected(playerid) && PlayerLoggedIn[playerid])
  {
    new player[32];
    new item[128];
    new amount[32];
    sscanf(params, "uss", player, item, amount);
    if(isnull(player))
    {
      SendClientMessage(playerid, COLOR_HELP, "USAGE: /give [ID/PartOfName] [item] [amount]");
      SendClientMessage(playerid, COLOR_HELP, "ITEMS: money, gun");
      return 1;
    }
    if(isnull(item))
    {
      SendClientMessage(playerid, COLOR_HELP, "USAGE: /give [ID/PartOfName] [item] [amount]");
      SendClientMessage(playerid, COLOR_HELP, "ITEMS: money, gun");
      return 1;
    }
    if(!strcmp(item, "money"))
    {
      if(isnull(amount))
      {
         SendClientMessage(playerid, COLOR_HELP, "USAGE: /give [ID/PartOfName] [item] [amount]");
         SendClientMessage(playerid, COLOR_HELP, "ITEM: money, gun");
         return 1;
      }
      GivePlayerCash(playerid,-amount); // Line: 3285
      GivePlayerCash(player,amount); // Line: 3286
    }
  }    
  return 1;
}
I didn't even finish the command and i get this errors:

Код:
C:\Documents and Settings\Ivan\Desktop\SERVER\gamemodes\cgrpg.pwn(3285) : error 035: argument type mismatch (argument 2)
C:\Documents and Settings\Ivan\Desktop\SERVER\gamemodes\cgrpg.pwn(3286) : error 035: argument type mismatch (argument 1)
Please help me fix it. Thank you.
Reply
#2

This has nothing to do with zcmd or sscanf it's you trying to check the index of a none array (player).

pawn Код:
if ( isnull(player //player isn't a string, a string is an array of characters
Edit:

Learn from my reply, you are doing the same thing but the other way around now.
Reply
#3

Quote:
Originally Posted by Donny
This has nothing to do with zcmd or sscanf it's you trying to check the index of a none array (player).

pawn Код:
if ( isnull(player //player isn't a string, a string is an array of characters
I've replaced

pawn Код:
new player;
with

pawn Код:
new player[32];
and that error has been fixed, but new ones appeared and i can't fix them.

I updated my first post. Please help, thanks...
Reply
#4

Quote:
Originally Posted by Donny
This has nothing to do with zcmd or sscanf it's you trying to check the index of a none array (player).

pawn Код:
if ( isnull(player //player isn't a string, a string is an array of characters
Edit:

Learn from my reply, you are doing the same thing but the other way around now.
Reply
#5

Try this:
Код:
cmd(give, playerid, params[])
{
  if(PlayerLoggedIn[playerid] != 1) return 1;
	new player;
	new item[12];
	new amount;
	if(sscanf(params, "usd", player, item, amount))
	{
	  SendClientMessage(playerid, COLOR_HELP, "USAGE: /give [ID/PartOfName] [item] [amount]");
	  SendClientMessage(playerid, COLOR_HELP, "ITEMS: money, gun");
	  return 1;
	}
	else if(player == INVALID_PLAYER_ID)
	{
	  SendClientMessage(playerid, COLOR_HELP, "Player not found.");
	  return 1;
	}
	if(!strcmp(item, "money", true))
	{
		GivePlayerCash(playerid, -amount);
		GivePlayerCash(player, amount);
	}
 	return 1;
}
Reply
#6

Thanks dre$tA. It works great.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)