SA-MP Forums Archive
[HELP] Charge command - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] Charge command (/showthread.php?tid=568313)



[HELP] Charge command - GloomY - 21.03.2015

Hello guys, I wondered if you could help me out with this one.
If I have a charge command and there I need to insert "/charge [playerid] [charge money] [reason]"
Is there any way to make a command that will automatically calculate 10% of players money (from bank) instead of charging with the inserted amount of money.

Example: If I insert "/charge [playerid] [percent money] [reason]" and if I insert 10%, can it check players money and if the player has 100.000$ on bank, he gets charged with 10.000$?

This is my /charge command. Please help me create this command.

pawn Код:
if(strcmp(cmd, "/charge", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            tmp = strtok(cmdtext, idx);
            if(!strlen(tmp))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /charge [Playerid/PartOfName] [money] [reason]");
                return 1;
            }
            new playa;
            new money;
            playa = ReturnUser(tmp);
            tmp = strtok(cmdtext, idx);
            money = strvalEx(tmp);
            if(money < 1)
            {
                SendClientMessage(playerid, COLOR_GREY, "The price shouldn't be less than 1$");
                return 1;
            }
            if (PlayerInfo[playerid][pAdmin] >= 2)
            {
                if(IsPlayerConnected(playa))
                {
                    if(playa != INVALID_PLAYER_ID)
                    {
                        GetPlayerName(playa, giveplayer, sizeof(giveplayer));
                        GetPlayerName(playerid, sendername, sizeof(sendername));
                        new length = strlen(cmdtext);
                        while ((idx < length) && (cmdtext[idx] <= ' '))
                        {
                            idx++;
                        }
                        new offset = idx;
                        new result[64];
                        while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
                        {
                            result[idx - offset] = cmdtext[idx];
                            idx++;
                        }
                        result[idx - offset] = EOS;
                        if(!strlen(result))
                        {
                            SendClientMessage(playerid, COLOR_GRAD2, "USAGE: /charge [Playerid/PartOfName] [money] [reason]");
                            return 1;
                        }
                        if (!GetPVarInt(giveplayerid, "gPlayerLogged"))
                        {
                            SendClientMessage(playerid, COLOR_RED, "The player is not connected.");
                            return 1;
                        }
                        new year, month,day;
                        getdate(year, month, day);
                        format(string, sizeof(string), "AdmCmd: %s has punished %s with %d$, reason: %s (%d-%d-%d)", sendername, giveplayer, money, (result) ,month, day, year);
                        ChargeLog(string);
                        format(string, sizeof(string), "AdmCmd: %s has punished %s with %d$, reason: %s", sendername, giveplayer, money, (result));
                        SendClientMessageToAll(COLOR_LIGHTRED, string);
                        SafeGivePlayerMoney(playa, -money);
                        return 1;
                    }
                }
            }
            else
                SendClientMessage(playerid, COLOR_RED, "The player is not connected!");
        }
        return 1;
    }
Thanks in advance.


Re: [HELP] Charge command - rOps - 21.03.2015

Код HTML:
new x, ChargedMoney;
x = money;
ChargedMoney = x - (x/100 * 10);

GivePlayerMoney(playerid, ChargedMoney);



Re: [HELP] Charge command - GloomY - 21.03.2015

Quote:
Originally Posted by rOps
Посмотреть сообщение
Код HTML:
new x, ChargedMoney;
x = money;
ChargedMoney = x - (x/100 * 10);

GivePlayerMoney(playerid, ChargedMoney);
Can you try and put it in this command?
Thanks.