Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <dini> //http://www.dracoblue.net/download.php?ID=35&URL=http://www.dracoblue.net/Downloads/Dini_1_5_1.zip
- #include <dudb> //http://www.dracoblue.net/download.php?ID=31&URL=http://www.dracoblue.net/Downloads/DUDB_2_4.zip
- /*--------------------[ Credits ]---------------------------------
- Thanks to Bert for programming the loan system, ty to Paul
- for the spelling mistakes he found
- ----------------------------------------------------------------*/
- new Loaned[MAX_PLAYERS];
- new BankString[128];
- //COLOR defines
- #define COLOR_RED 0xAA3333AA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_GREEN 0x33AA33AA
- public OnFilterScriptInit()
- {
- SetTimer("LoanPayOff", 300000, 1);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- SetTimer("LoanPayOff", 5000, 1);
- new PlayerName[24];
- GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
- if(dini_Exists(udb_encode(PlayerName)))
- {
- Loaned[playerid] = dini_Int(udb_encode(PlayerName), "Loaned");
- GivePlayerMoney(playerid, Loaned[playerid]);
- if(Loaned[playerid] == 0)
- {
- SendClientMessage(playerid, COLOR_GREEN, "You dont have a loan yet, the bank wishes you a good day!");
- }
- else
- {
- format(BankString, sizeof(BankString), "You still have a loan of %d$, the bank requests you to pay!", Loaned[playerid]);
- SendClientMessage(playerid, COLOR_RED, BankString);
- }
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid)
- {
- new PlayerName[24];
- GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
- dini_IntSet(udb_encode(PlayerName), "Loaned", Loaned[playerid]);
- }
- forward LoanPayOff();
- public LoanPayOff()
- {
- for(new i = 0; i < MAX_PLAYERS; i ++)
- {
- if(Loaned[i] > 0)
- {
- new thing = random(5);
- if(thing == 1)
- {
- new amount = Loaned[i]/7;
- format(BankString, sizeof(BankString), "The bank doesn't want to wait anymore, it took %d$ of your loan back", amount);
- SendClientMessage(i, COLOR_RED, BankString);
- format(BankString, sizeof(BankString), "~r~Loan -%d$", amount);
- GameTextForPlayer(i, BankString, 3000, 1);
- GivePlayerMoney(i, -amount);
- Loaned[i] -= amount;
- }
- else
- {
- SendClientMessage(i, 0xFFFFFF, "The bank asks you to pay off your loan!");
- }
- }
- }
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[256], idx;
- cmd = strtok(cmdtext, idx);
- if (strcmp("/loanamount", cmdtext, true, 11) == 0)
- {
- format(BankString, sizeof(BankString), "The amount of your loan currently is: %d$", Loaned[playerid]);
- SendClientMessage(playerid, COLOR_YELLOW, BankString);
- return 1;
- }
- if (strcmp("/loan", cmdtext, true, 5) == 0)
- {
- new tmp[255];
- tmp = strtok(cmdtext, idx);
- new amount = strval(tmp);
- if(!amount)
- {
- SendClientMessage(playerid, COLOR_RED, "Invalid transaction amount");
- return 1;
- }
- else if(Loaned[playerid] > 0)
- {
- format(BankString, sizeof(BankString), "You already have a loan of: %d$", Loaned[playerid]);
- SendClientMessage(playerid, COLOR_RED , BankString);
- }
- else
- {
- SendClientMessage(playerid, COLOR_GREEN , "You succesfully took a loan, use /loanamount to see how much you have borrowed and /payoff to payoff");
- format(BankString, sizeof(BankString), "~y~Loan %d$", amount);
- GameTextForPlayer(playerid, BankString, 3000, 1);
- GivePlayerMoney(playerid, amount);
- Loaned[playerid] = amount;
- }
- return 1;
- }
- if (strcmp("/payoff", cmdtext, true, 5) == 0)
- {
- new tmp[255];
- tmp = strtok(cmdtext, idx);
- new amount = strval(tmp);
- if(!amount)
- {
- SendClientMessage(playerid, COLOR_RED, "Invalid transaction amount");
- return 1;
- }
- else if(amount > Loaned[playerid])
- {
- format(BankString, sizeof(BankString), "You cant payoff more then your max loan, which is %d$", Loaned[playerid]);
- SendClientMessage(playerid, COLOR_RED , BankString);
- }
- else if(amount < GetPlayerMoney(playerid))
- {
- format(BankString, sizeof(BankString), "You succesfully paid off %d$, your new loan is %d$", amount, Loaned[playerid]-amount);
- SendClientMessage(playerid, COLOR_YELLOW , BankString);
- format(BankString, sizeof(BankString), "~r~-Loan %d$", amount);
- GameTextForPlayer(playerid, BankString, 3000, 1);
- GivePlayerMoney(playerid, -amount);
- Loaned[playerid] = Loaned[playerid]-amount;
- if(Loaned[playerid] == 0)
- {
- SendClientMessage(playerid, COLOR_GREEN , "The bank thanks you for paying back all of your loan");
- }
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED , "You cant pay off more then you have in your pocket");
- }
- return 1;
- }
- return 0;
- }
- /*--------------------[ Strtok ]-----------------------------------------
- strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment