command help
#1

I added a /pay command to my server and i got my friend to get on and to help test it out and when i do it says " you gave 90 dollars to" and thats it..


this is my command
pawn Код:
CMD:pay(playerid, params[])
{
    new giveplayerid, amount;
    new string[128];
    if (sscanf(params, "ud", giveplayerid, amount)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /pay [playerid/partname] [amount]");
    else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
    else if (giveplayerid == playerid) SendClientMessage(playerid, 0xFF0000AA, "You cannot send money to yourself");
    GivePlayerMoney(giveplayerid, amount);
    GivePlayerMoney(playerid, -amount);
    format(string, sizeof string, "[SERVER] %d amount of Money has been Sent to %s", amount, giveplayerid);
    SendClientMessage(playerid, COLOR_RED, string);
    format(string, sizeof string, "[SERVER] %d amount of Money has Sent by %s", amount, playerid);
    SendClientMessage(giveplayerid, COLOR_RED, string);
    return 1;
}
Reply
#2

Here is the pay cmd which i am using in my script you can change it in your way i think.

pawn Код:
CMD:pay(playerid, params[])
{
    new string[128], playerb, amount;
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(sscanf(params, "ui", playerb, amount)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /pay [playerid] [amount]");
    if(amount <= 0) return SendClientMessage(playerid, COLOR_GREY, "Invalid money amount.");
    if(playerid == playerb) return SendClientMessage(playerid, COLOR_GREY, "You can't pay money to yourself.");
    if(!IsPlayerLoggedIn(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
    if(!IsPlayerNearPlayer(playerid, playerb, 2)) return SendClientMessage(playerid, COLOR_GREY, "You are too far away from that player.");
    if(PlayerInfo[playerid][pMoney] < amount) return SendClientMessage(playerid, COLOR_GREY, "You don't have that much on you right now.");
    GivePlayerMoney(playerid, -amount);
    GivePlayerMoney(playerb, amount);
    format(string, sizeof(string), " You have given %s $%d.", RPN(playerb), amount);
    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
    format(string, sizeof(string), " %s has given you $%d.", RPN(playerid), amount);
    SendClientMessage(playerb, COLOR_LIGHTBLUE, string);
    return 1;
}
Reply
#3

new pName[30];
GetPlayerName(giveplayerid,pName,30);

format(string, sizeof string, "[SERVER] %d amount of Money has been Sent to %s(%d)", amount,pName,giveplayerid);
SendClientMessage(playerid, COLOR_RED, string);
__________________________________________________ _______________________

Fixed Code:
Код:
CMD:pay(playerid, params[])
{
    new giveplayerid, amount,pName[30];
    new string[128];
    GetPlayerName(giveplayerid,pName,30);
    if (sscanf(params, "ud", giveplayerid, amount)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /pay [playerid/partname] [amount]");
    else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "Insufficient Funds");
    else if (giveplayerid == playerid) SendClientMessage(playerid, 0xFF0000AA, "You cannot send money to yourself");
    GivePlayerMoney(giveplayerid, amount);
    GivePlayerMoney(playerid, -amount);
    format(string, sizeof string, "[SERVER] %d amount of Money has been Sent to %s(%d)", amount,pName,giveplayerid);
    SendClientMessage(playerid, COLOR_RED, string);
    format(string, sizeof string, "[SERVER] %d amount of Money has Sent by %s", amount, playerid);
    SendClientMessage(giveplayerid, COLOR_RED, string);
    return 1;
}
Reply
#4

Atleast guys, explain what the problem was. By pasting the code into his gamemode, he will never learn what it was wrong in case it happens again..

pawn Код:
format(string, sizeof string, "[SERVER] %d amount of Money has been Sent to %s", amount, giveplayerid);
format(string, sizeof string, "[SERVER] %d amount of Money has Sent by %s", amount, playerid);
What are you trying to display is the id of the player which is integer, not string.
pawn Код:
format(string, sizeof string, "[SERVER] %d amount of Money has been Sent to %d", amount, giveplayerid);
format(string, sizeof string, "[SERVER] %d amount of Money has Sent by %d", amount, playerid);
You can use the name/ID too, but you need to GetPlayerName first.
pawn Код:
new
    name[ MAX_PLAYER_NAME ],
    gname[ MAX_PLAYER_NAME ]
;

GetPlayerName(playerid, name, sizeof(name));
GetPlayerName(giveplayerid, gname, sizeof(gname));

format(string, sizeof string, "[SERVER] %d amount of Money has been Sent to %s(%d)", amount, gname, giveplayerid);
format(string, sizeof string, "[SERVER] %d amount of Money has Sent by %s(%d)", amount, name, playerid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)