• Welcome to Vice City Multiplayer.
 

!givecash fails

Started by Synx, April 24, 2011, 09:25:05 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Synx

Quoteelse 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!!!

DeWilX

This is my problem too.  >:(

stormeus

Quote from: Synx on April 24, 2011, 09:25:05 PM
Quoteelse 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.

Synx

That work now, but when i type id/nick someone's it sends cash to me no matter what.

stormeus

Quote from: Synx on April 25, 2011, 11:09:34 AM
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.