Guest User

Untitled

a guest
Dec 15th, 2009
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.38 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini>
  3. #include <dudb>
  4.  
  5. /*--------------------[ Credits ]---------------------------------
  6.  
  7.                   -Credit's Moe Allan  First Fs
  8.                                    =========   ========
  9.                ===        ===      =       =   =
  10.                =  =     =   =      =       =   ========
  11.                =    ===     =      =       =   =
  12.                =            =      =       =   =
  13.                =            =      =========   ========
  14.                
  15.                
  16. ----------------------------------------------------------------*/
  17.  
  18. new Credit[MAX_PLAYERS];
  19. new BankString[128];
  20.  
  21. //COLOR defines
  22. #define COLOR_RED 0xAA3333AA
  23. #define COLOR_YELLOW 0xFFFF00AA
  24. #define COLOR_GREEN 0x33AA33AA
  25.  
  26. public OnFilterScriptInit()
  27. {
  28.     SetTimer("CreditPayBack", 300000, 1);
  29.     return 1;
  30. }
  31.  
  32. public OnPlayerConnect(playerid)
  33. {
  34.     SetTimer("CreditPayBack", 5000, 1);
  35.     new PlayerName[24];
  36.     GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
  37.     if(dini_Exists(udb_encode(PlayerName)))
  38.     {
  39.         Credit[playerid] = dini_Int(udb_encode(PlayerName), "Credit");
  40.         GivePlayerMoney(playerid, Credit[playerid]);
  41.         if(Credit[playerid] == 0)
  42.         {
  43.             SendClientMessage(playerid, COLOR_GREEN, "You dont have any Loan Credit Due to the Bank Of Trust");
  44.         }
  45.         else
  46.         {
  47.             format(BankString, sizeof(BankString), "You Still Have To Pay Back %d$ Loan Credit", Credit[playerid]);
  48.             SendClientMessage(playerid, COLOR_RED, BankString);
  49.         }
  50.     }
  51.     return 1;
  52. }
  53.  
  54. public OnPlayerDisconnect(playerid)
  55. {
  56.     new PlayerName[24];
  57.     GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
  58.     dini_IntSet(udb_encode(PlayerName), "Credit", Credit[playerid]);
  59. }
  60.  
  61. forward LoanPayOff();
  62. public LoanPayOff()
  63. {
  64.     for(new i = 0; i < MAX_PLAYERS; i ++)
  65.     {
  66.         if(Credit[i] > 0)
  67.         {
  68.             new thing = random(5);
  69.             if(thing == 1)
  70.             {
  71.                 new amount = Credit[i]/7;
  72.                 format(BankString, sizeof(BankString), "The Bank Is Pissed, it took %d$ of your Credit Loan back", amount);
  73.                 SendClientMessage(i, COLOR_RED, BankString);
  74.                 format(BankString, sizeof(BankString), "~r~Loan -%d$", amount);
  75.                 GameTextForPlayer(i, BankString, 3000, 1);
  76.                 GivePlayerMoney(i, -amount);
  77.                 Credit[i] -= amount;
  78.             }
  79.             else
  80.             {
  81.                 SendClientMessage(i, 0xFFFFFF, "The bank wants its loan back now!");
  82.             }
  83.         }
  84.     }
  85. }
  86.  
  87. public OnPlayerCommandText(playerid, cmdtext[])
  88. {
  89.     new cmd[256], idx;
  90.     cmd = strtok(cmdtext, idx);
  91.  
  92.     if (strcmp("/Creditdue", cmdtext, true, 11) == 0)
  93.     {
  94.         format(BankString, sizeof(BankString), "The amount of your Credit currently is: %d$", Credit[playerid]);
  95.         SendClientMessage(playerid, COLOR_YELLOW, BankString);
  96.         return 1;
  97.     }
  98.     if (strcmp("/Credit", cmdtext, true, 5) == 0)
  99.     {
  100.         new tmp[255];
  101.         tmp = strtok(cmdtext, idx);
  102.         new amount = strval(tmp);
  103.         if(!amount)
  104.         {
  105.             SendClientMessage(playerid, COLOR_RED, "Invalid transaction amount");
  106.             return 1;
  107.         }
  108.         else if(Credit[playerid] > 0)
  109.         {
  110.             format(BankString, sizeof(BankString), "You already have Credit of: %d$", Credit[playerid]);
  111.             SendClientMessage(playerid, COLOR_RED , BankString);
  112.         }
  113.         else
  114.         {
  115.             SendClientMessage(playerid, COLOR_GREEN , "You succesfully took a credit Loan, use /creditdue To see how much you credited and need to pay back /creditpay to PayBack");
  116.             format(BankString, sizeof(BankString), "~y~Loan %d$", amount);
  117.             GameTextForPlayer(playerid, BankString, 3000, 1);
  118.             GivePlayerMoney(playerid, amount);
  119.             Credit[playerid] = amount;
  120.         }
  121.         return 1;
  122.     }
  123.     if (strcmp("/creditpay", cmdtext, true, 5) == 0)
  124.     {
  125.         new tmp[255];
  126.         tmp = strtok(cmdtext, idx);
  127.         new amount = strval(tmp);
  128.         if(!amount)
  129.         {
  130.             SendClientMessage(playerid, COLOR_RED, "Invalid transaction amount");
  131.             return 1;
  132.         }
  133.         else if(amount > Credit[playerid])
  134.         {
  135.             format(BankString, sizeof(BankString), "You cant payback more then your max Credit , which is %d$", Credit[playerid]);
  136.             SendClientMessage(playerid, COLOR_RED , BankString);
  137.         }
  138.         else if(amount < GetPlayerMoney(playerid))
  139.         {
  140.             format(BankString, sizeof(BankString), "You succesfully paid off Your Credit Of %d$, your new Credit amount is %d$", amount, Credit[playerid]-amount);
  141.             SendClientMessage(playerid, COLOR_YELLOW , BankString);
  142.             format(BankString, sizeof(BankString), "~r~-Loan %d$", amount);
  143.             GameTextForPlayer(playerid, BankString, 3000, 1);
  144.             GivePlayerMoney(playerid, -amount);
  145.             Credit[playerid] = Credit[playerid]-amount;
  146.             if(Credit[playerid] == 0)
  147.             {
  148.                 SendClientMessage(playerid, COLOR_GREEN , "The Bank Is Thankfull for your credit payback");
  149.             }
  150.         }
  151.         else
  152.         {
  153.             SendClientMessage(playerid, COLOR_RED , "You cant pay off more then you have in your wallet");
  154.         }
  155.         return 1;
  156.     }
  157.     return 0;
  158. }
  159.  
  160.  
  161. /*--------------------[ Strtok ]-----------------------------------------
  162. strtok(const string[], &index)
  163. {
  164.     new length = strlen(string);
  165.     while ((index < length) && (string[index] <= ' '))
  166.     {
  167.         index++;
  168.     }
  169.  
  170.     new offset = index;
  171.     new result[20];
  172.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  173.     {
  174.         result[index - offset] = string[index];
  175.         index++;
  176.     }
  177.     result[index - offset] = EOS;
  178.     return result;
  179. }*/
Advertisement
Add Comment
Please, Sign In to add comment