Vice City Multiplayer

VC:MP => mIRC/pawn Scripting => Topic started by: Synx on April 24, 2011, 10:25:05 PM

Title: !givecash fails
Post by: Synx on April 24, 2011, 10: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!!!
Title: Re: !givecash fails
Post by: DeWilX on April 25, 2011, 09:50:05 AM
This is my problem too.  >:(
Title: Re: !givecash fails
Post by: stormeus on April 25, 2011, 09:56:03 AM
Quote from: Synx on April 24, 2011, 10: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.
Title: Re: !givecash fails
Post by: Synx on April 25, 2011, 12:09:34 PM
That work now, but when i type id/nick someone's it sends cash to me no matter what.
Title: Re: !givecash fails
Post by: stormeus on April 25, 2011, 12:33:08 PM
Quote from: Synx on April 25, 2011, 12:09:34 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.