Author Topic: !givecash fails  (Read 3618 times)

0 Members and 1 Guest are viewing this topic.

Offline Synx

  • Street Thug
  • *
  • Posts: 27
    • View Profile
!givecash fails
« on: April 24, 2011, 11:25:05 pm »
Quote
      else if (strcmp(cmd, "!givecash", true) == 0) {
          new tmp2[256], plr;
      tmp = strtok(cmdtext, idx), tmp2 = strtok(cmdtext, idx), plr = FindPlayerIDFromString(tmp);
      if(PlayerInfo[playerid][Logged] != 1) SendClientMessage(playerid, COLOR_RED, "You need to login first!");
      else if (!strlen(tmp2)) SendClientMessage(playerid,COLOR_GREEN, "USAGE: !givecash [Nick/ID] [Amount]");
      else if (GetPlayerHandCash(gPlayers[playerid]) < StrToInt(tmp2)) SendClientMessage(playerid,COLOR_GREEN, "Error: You havent got the needed money.");
      else if (plr != INACTIVE_PLAYER_ID) SendClientMessage(playerid,COLOR_RED,"Error: Unknown player");
      else if(!IsPlayerRegistered(gPlayers[plr])) SendClientMessage(playerid, COLOR_RED, "Error: That nick is not registered!");
      else if (!IsNumeric(tmp2)) SendClientMessage(playerid,COLOR_GREEN, "Error: Invalid Amount!");
      else {
         format(szMsg,sizeof(szMsg),"You have sent:[ $%d ] to:[ %s ]",tmp,gPlayers[playerid]);
         SendClientMessage(playerid,COLOR_GREEN, szMsg);
         DecPlayerHandCash(playerid,StrToInt(tmp));
         IncPlayerHandCash(plr,StrToInt(tmp));
      }
      return 1;
      }

When I want send some one money it's say all time "invalid id" I type nick "invalid id". HELP!!!

Offline DeWilX

  • Street Thug
  • *
  • Posts: 3
    • View Profile
Re: !givecash fails
« Reply #1 on: April 25, 2011, 10:50:05 am »
This is my problem too.  >:(

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: !givecash fails
« Reply #2 on: April 25, 2011, 10:56:03 am »
Quote
      else if (strcmp(cmd, "!givecash", true) == 0) {
          new tmp2[256], plr;
      tmp = strtok(cmdtext, idx), tmp2 = strtok(cmdtext, idx), plr = FindPlayerIDFromString(tmp);
      if(PlayerInfo[playerid][Logged] != 1) SendClientMessage(playerid, COLOR_RED, "You need to login first!");
      else if (!strlen(tmp2)) SendClientMessage(playerid,COLOR_GREEN, "USAGE: !givecash [Nick/ID] [Amount]");
      else if (GetPlayerHandCash(gPlayers[playerid]) < StrToInt(tmp2)) SendClientMessage(playerid,COLOR_GREEN, "Error: You havent got the needed money.");
      else if (plr != INACTIVE_PLAYER_ID) SendClientMessage(playerid,COLOR_RED,"Error: Unknown player");
      else if(!IsPlayerRegistered(gPlayers[plr])) SendClientMessage(playerid, COLOR_RED, "Error: That nick is not registered!");
      else if (!IsNumeric(tmp2)) SendClientMessage(playerid,COLOR_GREEN, "Error: Invalid Amount!");
      else {
         format(szMsg,sizeof(szMsg),"You have sent:[ $%d ] to:[ %s ]",tmp,gPlayers[playerid]);
         SendClientMessage(playerid,COLOR_GREEN, szMsg);
         DecPlayerHandCash(playerid,StrToInt(tmp));
         IncPlayerHandCash(plr,StrToInt(tmp));
      }
      return 1;
      }

When I want send some one money it's say all time "invalid id" I type nick "invalid id". HELP!!!


else if (plr != INACTIVE_PLAYER_ID)

The != tells Pawn that if the ID is NOT an invalid player, that it should stop and tell them they don't have the required money.

Replace != with == so that it checks if the ID IS an invalid player.
Do not PM me for support.




Offline Synx

  • Street Thug
  • *
  • Posts: 27
    • View Profile
Re: !givecash fails
« Reply #3 on: April 25, 2011, 01:09:34 pm »
That work now, but when i type id/nick someone's it sends cash to me no matter what.

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: !givecash fails
« Reply #4 on: April 25, 2011, 01:33:08 pm »
That work now, but when i type id/nick someone's it sends cash to me no matter what.

In the beginning of your code, tmp is used for the nick/ID, and tmp2 is used for the amount. Then this gets switched in your format statement, and it says it sent $[player id] to you because you use playerid instead of plr.

format(szMsg,sizeof(szMsg),"You have sent:[ $%d ] to: [ %s ]",tmp,gPlayers[playerid]);

Replace tmp with tmp2
Replace gPlayers[playerid] with gPlayers[plr]

By the way, instead of using StrToInt, you can use the native strval() function instead.

Other than that, I can't see much else wrong with your code.
Do not PM me for support.