Main bit of /givecash?
#1

How to get the command like this

/givecash [id] [amount]

How to get the server to read what the user puts in as amount
Reply
#2

use sscanf, add
pawn Код:
new id, amount;
under dcmd_givecash(playerid,params[]) {

You can do like:
pawn Код:
format(string,sizeof(string),"[SUCCES] You have given %s [ID: %d] $%d",PlayerName(id),id,amount);
pawn Код:
GivePlayerMoney(id,amount);
if that is what you meant
Reply
#3

Top of script
pawn Код:
#define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(givecash, 8, cmdtext);
    return 0;
}
Anywhere in script except inside a callback..
pawn Код:
dcmd_givecash(playerid, params[])
{
    new
        giveplayerid,
        amount;
    if (sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "[USAGE] /givecash <playerid/partname> <amount>.");
    else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "[INFO] Player not found.");
    else if (amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "You Don't Have That Much Money!");
    else
    {
        GivePlayerMoney(giveplayerid, amount);
        GivePlayerMoney(playerid, 0 - amount);
        new tempstring[256];
        format(tempstring, sizeof(tempstring), "[INFO] You've Given $%d To %s.", amount, giveplayerid);
        SendClientMessage(playerid, 0x00FF00AA, tempstring);
        format(tempstring, sizeof(tempstring), "[INFO] You've Recieved $%d From %s.", amount, playerid);
        SendClientMessage(giveplayerid, 0x00FF00AA, tempstring);
    }
    return 1;
}
Reply
#4

Ok, I got the code of wiki, Anyways,
I want the id who got sent the money to recieve a message,
Код:
Admin Torran has set your cash to [amount]
So i used a string,
pawn Код:
format(string, sizeof(string), "Admin %s has set your cash to %s", name, amount);
The name bit works alright ingame but the amount bit just displays this:

[img width=1024 height=768]/imageshack/img80/271/samp001ai.png[/img]

Ive never used a string for anything besides the players name,
So i know ive done something wrong,
Btw the command works fine,

Full code:

pawn Код:
dcmd_givecash(playerid, params[])
{
    new
        giveplayerid,
        amount;
    if (sscanf(params, "ud", giveplayerid, amount)) SendClientMessage(playerid, 0xFF0000AA, "Usage: /givecash [playerid/partname] [amount]");
    else if (giveplayerid == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player not found");
    else
    {
        GivePlayerMoney(giveplayerid, amount);
        new name[MAX_PLAYER_NAME], string[48];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "Admin %s has set your cash to %s", name, amount);
    SendClientMessage(giveplayerid, 0xFFFF00AA, string);
    }
    return 1;
}
Reply
#5

Use %d for numbers, instead of %s.
Reply
#6

You need to use %d for money amount and %s for name etc..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)