SA-MP Forums Archive
Help me /pay - 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 me /pay (/showthread.php?tid=513422)



Help me /pay - Raefal - 16.05.2014

Now if i want to pay someone i must do it /pay 10 20 25
How to make it /pay 10 20.25

Because i want to make dollar system

Код:
CMD:pay(playerid, params[])
{
   new
      iTargetID, iCashAmount, iCentAmount;

   if(sscanf(params, "idd", iTargetID, iCashAmount, iCentAmount)) return SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /pay [playerid] [dollar] [cent]");

   if(iTargetID == playerid)
   {
      SendClientMessageEx(playerid, COLOR_GRAD1, "You can not use this command on yourself!");
      return 1;
   }
   if(iCashAmount < 1)
   {
      SendClientMessageEx(playerid, COLOR_GRAD1, "Don't go below $1");
      return 1;
   }
   if (IsPlayerConnected(iTargetID))
   {
      if (ProxDetectorS(5.0, playerid, iTargetID))
      {
         new
            szMessage[128], giveplayer[MAX_PLAYER_NAME], sendername[MAX_PLAYER_NAME], playermoney = GetPlayerCash(playerid);
         giveplayer = GetPlayerNameEx(iTargetID);
         sendername = GetPlayerNameEx(playerid);
         if (iCashAmount > 0 && playermoney >= iCashAmount)
         {
            GivePlayerCash(playerid, (0 - iCashAmount, iCentAmount ));
            GivePlayerCash(iTargetID, iCashAmount,iCentAmount );
            format(szMessage, sizeof(szMessage), "   You have sent %s(player: %d), $%d.", GetPlayerNameEx(iTargetID),iTargetID, iCashAmount);
            PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
            SendClientMessageEx(playerid, COLOR_GRAD1, szMessage);
            format(szMessage, sizeof(szMessage), "   You have recieved $%d from %s(player: %d).", iCashAmount, GetPlayerNameEx(playerid), playerid);
            SendClientMessageEx(iTargetID, COLOR_GRAD1, szMessage);
            new ip[32], ipex[32];
            GetPlayerIp(playerid, ip, sizeof(ip));
            GetPlayerIp(iTargetID, ipex, sizeof(ipex));
            format(szMessage, sizeof(szMessage), "%s (IP:%s) has paid $%d to %s (IP:%s)", GetPlayerNameEx(playerid), ip, iCashAmount, GetPlayerNameEx(iTargetID), ipex);
            Log("logs/pay.log", szMessage);

            if(PlayerInfo[playerid][pAdmin] >= 2)
            {
               format(szMessage, sizeof(szMessage), "[Admin] %s (IP:%s) has paid $%d to %s (IP:%s)", GetPlayerNameEx(playerid), ip, iCashAmount, GetPlayerNameEx(iTargetID), ipex);
               Log("logs/adminpay.log", szMessage);
               format(szMessage, sizeof(szMessage), "{AA3333}AdmWarning{FFFF00}: %s (IP:%s) has paid $%d to %s (IP:%s)", GetPlayerNameEx(playerid), ip, iCashAmount, GetPlayerNameEx(iTargetID), ipex);
               ABroadCast(COLOR_YELLOW, szMessage, 2);
            }

            PayWarn[playerid][iTargetID] += iCashAmount;
            if(PayWarn[playerid][iTargetID] >= 100000 && PlayerInfo[playerid][pLevel] <= 3)
            {
               format(szMessage, sizeof(szMessage), "%s (IP:%s) has paid %s (IP:%s) $%d in this session.", GetPlayerNameEx(playerid), ip, GetPlayerNameEx(iTargetID), ipex, PayWarn[playerid][iTargetID]);
               Log("logs/pay.log", szMessage);
               ABroadCast(COLOR_YELLOW, szMessage, 2);
            }

            if(iCashAmount >= 1000000)
            {
               ABroadCast(COLOR_YELLOW,szMessage,2);
            }

            PlayerPlaySound(iTargetID, 1052, 0.0, 0.0, 0.0);
            format(szMessage, sizeof(szMessage), "* %s takes out some cash, and hands it to %s.", GetPlayerNameEx(playerid) ,GetPlayerNameEx(iTargetID));
            ProxDetector(30.0, playerid, szMessage, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
         }
         else
         {
            SendClientMessageEx(playerid, COLOR_GRAD1, "   Invalid transaction amount.");
         }
      }
      else
      {
         SendClientMessageEx(playerid, COLOR_GREY, "That player isn't near you.");
      }
   }
   else SendClientMessageEx(playerid, COLOR_GRAD1, "Invalid player specified.");
   return 1;
}



Re: Help me /pay - Campbell- - 16.05.2014

By using a float instead of an integer when seperating the parameters via sscanf. You will then later still be able to extract the amount of cents into a seperate integer.


Re: Help me /pay - Raefal - 16.05.2014

How to extract it


Re: Help me /pay - Raefal - 16.05.2014

bump* Someone ?


Re: Help me /pay - Campbell- - 16.05.2014

Assuming that the variable 'val' includes the entered amount of money to be transfered:

pawn Код:
new val = 12.56,
    data[2]; // data[0]: dollars, data[1]: cents

data[0] = floatround(val, floatround_floor); // 12
data[1] = (val - data[0]) * 100; // 56



Re: Help me /pay - Raefal - 16.05.2014

Thanks !