Player to Player /sendcash command??
#1

Hi, I'm tyring to make a very simple command "send cash" for players to use. (not admins)

I have tried to copy from the admin script, but wow it was very hard to read from Ladmin (..and I'm a noob, but learning)


I know what's needed, but scripting it is another story.. (I'm a bad translator - english > machine)

I am just looking for a very very simple script that will do this:
Quote:

/sendcash <ID> <AMOUNT>

if user is online
if user has enough money
{
sender cash - x amount
receiver cash + x amount
}

else
msg "player not online or you do not have enough cash"

I did try to have a bash myself

I know you will need to hold/use at least 4 values, both users ID's / cash


Quote:

public OnPlayerCommandText(playerid, rec_playerid, cmdtext[])
{
if(strcmp(cmdtext,"/sendcash",true) == 0)
{
-i cash from sender
+i cash to receiver
}

return 0;
}

I have searched the forum and ****** btw.


Can anyone help a noob out please?
Reply
#2

On top:
pawn Код:
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
Then add this


pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(givecash, 8, cmdtext);
    return 0;
}

dcmd_givecash(playerid, params[])
{
    new id, amount;
    if(sscanf(params, "ui", id, amount)) SendClientMessage(playerid, 0xFF0000AA, "Use /givecash [id] [amount]");
    else if(id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000AA, "Player is not active");
    else if(id == playerid) SendClientMessage(playerid, 0xFF0000AA, "You cannot send yourself cash");
    else if(amount > GetPlayerMoney(playerid)) SendClientMessage(playerid, 0xFF0000AA, "You cannot send more than you have");
    else
    {
        GivePlayerMoney(id, amount);
        GivePlayerMoney(playerid, -amount);
    }
    return 1;
}
Reply
#3

Quote:

C:\Program Files\Rockstar Games\GTA San Andreas\samp03asvr_R8_win32\gamemodes\DM_MP.pwn(22 6) : error 017: undefined symbol "sscanf"

o_O whats sscanf? lol
Reply
#4

OMG, one more dcmder here, just use OnPlayerCommandText

pawn Код:
if(strcmp(cmd, "/sendmoney", true) == 0)
{
    if(IsPlayerConnected(playerid))
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /pay [playerid/PartOfName] [amount]");
            return 1;
        }
        giveplayerid = ReturnUser(tmp);
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /pay [playerid/PartOfName] [amount]");
            return 1;
        }
        moneys = strval(tmp);
        if (IsPlayerConnected(giveplayerid))
        {
            playermoney = PlayerInfo[playerid][pCash];
            if (playermoney >= moneys)
            {
                GivePlayerMoney(playerid,moneys);
                GivePlayerMoney(giveplayerid,-moneys);
            }
        }
        else
        {
            SendClientMessage(playerid,COLOR_WHITE,"That player is not connected.");
        }
    }
    return 1;
}
Copy from GodFather
Reply
#5

Quote:
Originally Posted by ikey07
Посмотреть сообщение
OMG, one more dcmder here, just use OnPlayerCommandText
OMG, this is my first time using it..

sscanf

pawn Код:
stock sscanf(string[], format[], {Float,_}:...)
{
    new
        formatPos = 0,
        stringPos = 0,
        paramPos = 2,
        paramCount = numargs();
    while (paramPos < paramCount && string[stringPos])
    {
        switch (format[formatPos++])
        {
            case '\0':
            {
                return 0;
            }
            case 'i', 'd':
            {
                new
                    neg = 1,
                    num = 0,
                    ch = string[stringPos];
                if (ch == '-')
                {
                    neg = -1;
                    ch = string[++stringPos];
                }
                do
                {
                    stringPos++;
                    if (ch >= '0' && ch <= '9')
                    {
                        num = (num * 10) + (ch - '0');
                    }
                    else
                    {
                        return 1;
                    }
                }
                while ((ch = string[stringPos]) && ch != ' ');
                setarg(paramPos, 0, num * neg);
            }
            case 'h', 'x':
            {
                new
                    ch,
                    num = 0;
                while ((ch = string[stringPos++]))
                {
                    switch (ch)
                    {
                        case 'x', 'X':
                        {
                            num = 0;
                            continue;
                        }
                        case '0' .. '9':
                        {
                            num = (num << 4) | (ch - '0');
                        }
                        case 'a' .. 'f':
                        {
                            num = (num << 4) | (ch - ('a' - 10));
                        }
                        case 'A' .. 'F':
                        {
                            num = (num << 4) | (ch - ('A' - 10));
                        }
                        case ' ':
                        {
                            break;
                        }
                        default:
                        {
                            return 1;
                        }
                    }
                }
                setarg(paramPos, 0, num);
            }
            case 'c':
            {
                setarg(paramPos, 0, string[stringPos++]);
            }
            case 'f':
            {
                new tmp[25];
                strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
                setarg(paramPos, 0, _:floatstr(tmp));
            }
            case 's', 'z':
            {
                new
                    i = 0,
                    ch;
                if (format[formatPos])
                {
                    while ((ch = string[stringPos++]) && ch != ' ')
                    {
                        setarg(paramPos, i++, ch);
                    }
                    if (!i) return 1;
                }
                else
                {
                    while ((ch = string[stringPos++]))
                    {
                        setarg(paramPos, i++, ch);
                    }
                }
                stringPos--;
                setarg(paramPos, i, '\0');
            }
            default:
            {
                continue;
            }
        }
        while (string[stringPos] && string[stringPos] != ' ')
        {
            stringPos++;
        }
        while (string[stringPos] == ' ')
        {
            stringPos++;
        }
        paramPos++;
    }
    while (format[formatPos] == 'z') formatPos++;
    return format[formatPos];
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)