/pay command help
#1

So I got this at the minute.
pawn Код:
CMD:pay(playerid, params[])
{
  new otherid,cash,string[128],namez[MAX_PLAYER_NAME];
  if (sscanf(params, "dd", otherid, cash)) SendClientMessage(playerid, -1, "{5CFF6F}USAGE: {FFFFFF}/pay [ID] [Amount]");
  else
  {
    if(GetPlayerMoney(playerid) < cash) SendClientMessage(playerid, -1, "{FF6347}ERROR: {FFFFFF}You don't have that much!");
    else if(!IsPlayerConnected(otherid)) SendClientMessage(playerid, -1, "{FF6347}ERROR: {FFFFFF}That desired ID is not connected.");
    else if(otherid == playerid) SendClientMessage(playerid, -1, "{FF6347}ERROR: {FFFFFF}You can't pay yourself.");
    else
    {
        GivePlayerMoney(playerid, -cash);
        GetPlayerName(playerid,namez,sizeof(namez));
        format(string,sizeof(string),"{5CFF6F}NOTICE: {FFFFFF}You have sent {5CFF6F}$%d {FFFFFF}to {5CFF6F}%s{FFFFFF}.",cash,namez);
        SendClientMessage(otherid,-1,string);
    }
    {
        GivePlayerMoney(otherid, cash);
        GetPlayerName(playerid,namez,sizeof(namez));
        format(string,sizeof(string),"{5CFF6F}NOTICE: {FFFFFF}You have recieved {5CFF6F}$%d {FFFFFF}from {5CFF6F}%s{FFFFFF}.",cash,namez);
        SendClientMessage(otherid,-1,string);
    }
  }
  return 1;
}
This code does work but when I pay people any amount, it doesn't tell me I payed them but if they pay me, it tells me I was payed and I sent this amount of cash which shouldn't happen. Any help?
Reply
#2

Код:
CMD:pay(playerid, params[])
{
  new otherid,cash,string[128],namez[MAX_PLAYER_NAME], namez1[MAX_PLAYER_NAME];
  if (sscanf(params, "ui", otherid, cash)) SendClientMessage(playerid, -1, "{5CFF6F}USAGE: {FFFFFF}/pay [ID] [Amount]");
  else
  {
    if(GetPlayerMoney(playerid) < cash) return SendClientMessage(playerid, -1, "{FF6347}ERROR: {FFFFFF}You don't have that much!");
    else if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, -1, "{FF6347}ERROR: {FFFFFF}That desired ID is not connected.");
    else if(otherid == playerid) return SendClientMessage(playerid, -1, "{FF6347}ERROR: {FFFFFF}You can't pay yourself.");
    else
    {
	    GivePlayerMoney(playerid, -cash);
		GetPlayerName(otherid,namez1,sizeof(namez1));
		format(string,sizeof(string),"{5CFF6F}NOTICE: {FFFFFF}You have sent {5CFF6F}$%d {FFFFFF}to {5CFF6F}%s{FFFFFF}.",cash,namez1);
		SendClientMessage(playerid,-1,string);
		
      	GivePlayerMoney(otherid, cash);
      	GetPlayerName(playerid,namez,sizeof(namez));
		format(string,sizeof(string),"{5CFF6F}NOTICE: {FFFFFF}You have recieved {5CFF6F}$%d {FFFFFF}from {5CFF6F}%s{FFFFFF}.",cash,namez);
		SendClientMessage(otherid,-1,string);
    }
  }
  return 1;
}
This should work
Reply
#3

So the user above me gave you a code that should work but I thought I would mention a few specific things I noticed that are slightly problematic...

When you are using ZCMD, "u" refers to the ID of the player you're using it on.

In your code you put this:
PHP код:
if (sscanf(params"dd"otheridcash)) 
When it should instead be "ui" - i standing for integer instead of a decimal that you were using. Money in samp doesn't have decimals so it's unnecessary.

Another problem lies with this code:
PHP код:
GetPlayerName(playerid,namez,sizeof(namez)); 
You got the playerid's name and stored it in 'namez' instead of getting the 'otherid' and storing it in namez.
Reply
#4

Quote:
Originally Posted by K9IsGodly
Посмотреть сообщение
So the user above me gave you a code that should work but I thought I would mention a few specific things I noticed that are slightly problematic...

When you are using ZCMD, "u" refers to the ID of the player you're using it on.

In your code you put this:
PHP код:
if (sscanf(params"dd"otheridcash)) 
When it should instead be "ui" - i standing for integer instead of a decimal that you were using. Money in samp doesn't have decimals so it's unnecessary.

Another problem lies with this code:
PHP код:
GetPlayerName(playerid,namez,sizeof(namez)); 
You got the playerid's name and stored it in 'namez' instead of getting the 'otherid' and storing it in namez.
You have pointed right here, good job mate and thank you for explaining him! Here's a +Rep!
Reply
#5

Quote:
Originally Posted by K9IsGodly
Посмотреть сообщение
So the user above me gave you a code that should work but I thought I would mention a few specific things I noticed that are slightly problematic...

When you are using ZCMD, "u" refers to the ID of the player you're using it on.

In your code you put this:
PHP код:
if (sscanf(params"dd"otheridcash)) 
When it should instead be "ui" - i standing for integer instead of a decimal that you were using. Money in samp doesn't have decimals so it's unnecessary.

Another problem lies with this code:
PHP код:
GetPlayerName(playerid,namez,sizeof(namez)); 
You got the playerid's name and stored it in 'namez' instead of getting the 'otherid' and storing it in namez.
Did you know that first thing you mentioned is NOT RIGHT and doesn't help him?
d is also for integer and money in sa-mp is decimal (base 10) so is the ID (The thing you are mistaking it for is float, here read this and you'll understand that you can even use o and x for integer too http://stackoverflow.com/questions/1...nd-for-integer )
Oh and using u instead of d .. I don't really know what would be the benefit of u instead of i/d, I believe it does filter out the not connected players right? Or you just use it cuz others use?
Whole his problem was on SendClientMessage(otherid,-1,string); < sending both messages to otherid instead of one to player one to other and the second problem you mentioned
Reply
#6

Changed "dd" to "ui" and now /pay doesn't work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)