help with /pay cmd
#1

PHP код:
CMD:pay(playeridparams[])
{
  new 
otherid,cash,string[128],namez[MAX_PLAYER_NAME],names[MAX_PLAYER_NAME];
  if (
sscanf(params"dd"otheridcash)) SendClientMessage(playeridCOLOR_RED"Usage: /pay [ID] [Cash]");
  if(
otherid == playeridSendClientMessage(playeridCOLOR_RED"It is pointless to pay yourself..");
  else
  {
    if(
GetPlayerMoney(playerid) < cashSendClientMessage(playeridCOLOR_RED"You don't have that much!");
    else if(!
IsPlayerConnected(otherid)) SendClientMessage(playeridCOLOR_RED"That PlayerID is not connected!");
    else
    {
      
GivePlayerMoney(playerid, -cash);
            
GetPlayerName(otherid,names,sizeof(namez));
            
format(string,sizeof(string),"You gave $%d to %s",cash,names);
            
SendClientMessage(otherid,COLOR_BLUE,string);
    }
    {
      
GivePlayerMoney(otheridcash);
      
GetPlayerName(playerid,namez,sizeof(namez));
            
format(string,sizeof(string),"%s gave you $%d",cash,namez);
            
SendClientMessage(otherid,COLOR_BLUE,string);
    }
  }
  return 
1;

Can someone help me ?When i try to pay to myself the error msg shows two times...And i want when you give cash to someone to show you a msg:You gave [] to[] and player who get cash to get msg:[]Gave you[]
Reply
#2

BUMP
Reply
#3

pawn Код:
format(string,sizeof(string),"You gave $%d to %s",cash,names);
SendClientMessage(otherid,COLOR_BLUE,string);
You should send this message to the player that called the function, "playerid".
Reply
#4

Код:
CMD:pay(playerid, params[]) 
{ 
    new otherid, cash, string[128], namez[MAX_PLAYER_NAME], names[MAX_PLAYER_NAME]; 

    if(sscanf(params, "ud", otherid, cash)) return SendClientMessage(playerid, COLOR_RED, "Usage: /pay [ID] [Cash]"); 

    if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, COLOR_RED, "That PlayerID is not connected!");   
    if(otherid == playerid) return SendClientMessage(playerid, COLOR_RED, "It is pointless to pay yourself.."); 
    if(GetPlayerMoney(playerid) < cash) return SendClientMessage(playerid, COLOR_RED, "You don't have that much!"); 

    GivePlayerMoney(playerid, -cash);  
    format(string, sizeof(string), "You gave $%d to %s", cash, GetPlayersName(names)); 
    SendClientMessage(playerid, COLOR_BLUE, string);  

    GivePlayerMoney(otherid, cash); 
    format(string, sizeof(string), "%s gave you $%d", cash, GetPlayersName(namez)); 
    SendClientMessage(otherid, COLOR_BLUE, string); //send the message to the other player 

    return 1; 
}  

GetPlayersName(playerid)  //with this you don't always have to add "GetPlayerName" in every command
{
    new playersName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playersName, MAX_PLAYER_NAME);
    return playersName;
}
I hope this is easier to understand.
You should indent and add a space after commas, it's easier to read.
Reply
#5

I still see some minor mistakes:
pawn Код:
GetPlayerName(otherid, names, sizeof(namez)); // Name is assigned to "names" and sizeof is taken from "namez"...

format(string, sizeof(string), "%s gave you $%d", cash, namez); // "%s" assigned for cash and "$%d" assigned to the name...
Dusk and AaronKillz already gave you a solution, but here is the final code:
pawn Код:
CMD:pay(playerid, params[])
{
    new otherid, cash, string[128], namez[MAX_PLAYER_NAME], names[MAX_PLAYER_NAME];

    if (sscanf(params, "dd", otherid, cash)) SendClientMessage(playerid, COLOR_RED, "Usage: /pay [ID] [Cash]");

    if(!IsPlayerConnected(otherid)) return SendClientMessage(playerid, COLOR_RED, "That PlayerID is not connected!");  
    if(otherid == playerid) return SendClientMessage(playerid, COLOR_RED, "It is pointless to pay yourself..");
    if(GetPlayerMoney(playerid) < cash) return SendClientMessage(playerid, COLOR_RED, "You don't have that much!");

    GivePlayerMoney(playerid, -cash);
    GetPlayerName(otherid, names, sizeof(names));
    format(string, sizeof(string), "You gave $%d to %s", cash, names);
    SendClientMessage(playerid, COLOR_BLUE, string);  

    GivePlayerMoney(otherid, cash);
    GetPlayerName(playerid, namez, sizeof(namez));
    format(string, sizeof(string), "%s gave you $%d", namez, cash);
    SendClientMessage(otherid, COLOR_BLUE, string);
    return 1;
}
Reply
#6

Now i cant pay, if i use /pay it returns:its poitness to pay to yourself..
Reply
#7

EDIT: Oh I found it: You should add a "return" after sscanf(...).
pawn Код:
if(sscanf(params, "ud", otherid, cash)) return SendClientMessage(...).
Important: Always use "u" specifier for player ids in sscanf!
Reply
#8

Nope, when i just use /pay or /pay 8 100(i am not ID it return this value
Reply
#9

Read my edited post above.
Reply
#10

Look at my code again, seems like I've overlooked that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)