Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <dini>
- #include <dudb>
- /*--------------------[ Credits ]---------------------------------
- -Credit's Moe Allan First Fs
- ========= ========
- === === = = =
- = = = = = = ========
- = === = = = =
- = = = = =
- = = ========= ========
- ----------------------------------------------------------------*/
- new Credit[MAX_PLAYERS];
- new BankString[128];
- //COLOR defines
- #define COLOR_RED 0xAA3333AA
- #define COLOR_YELLOW 0xFFFF00AA
- #define COLOR_GREEN 0x33AA33AA
- public OnFilterScriptInit()
- {
- SetTimer("CreditPayBack", 300000, 1);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- SetTimer("CreditPayBack", 5000, 1);
- new PlayerName[24];
- GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
- if(dini_Exists(udb_encode(PlayerName)))
- {
- Credit[playerid] = dini_Int(udb_encode(PlayerName), "Credit");
- GivePlayerMoney(playerid, Credit[playerid]);
- if(Credit[playerid] == 0)
- {
- SendClientMessage(playerid, COLOR_GREEN, "You dont have any Loan Credit Due to the Bank Of Trust");
- }
- else
- {
- format(BankString, sizeof(BankString), "You Still Have To Pay Back %d$ Loan Credit", Credit[playerid]);
- SendClientMessage(playerid, COLOR_RED, BankString);
- }
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid)
- {
- new PlayerName[24];
- GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
- dini_IntSet(udb_encode(PlayerName), "Credit", Credit[playerid]);
- }
- forward LoanPayOff();
- public LoanPayOff()
- {
- for(new i = 0; i < MAX_PLAYERS; i ++)
- {
- if(Credit[i] > 0)
- {
- new thing = random(5);
- if(thing == 1)
- {
- new amount = Credit[i]/7;
- format(BankString, sizeof(BankString), "The Bank Is Pissed, it took %d$ of your Credit Loan back", amount);
- SendClientMessage(i, COLOR_RED, BankString);
- format(BankString, sizeof(BankString), "~r~Loan -%d$", amount);
- GameTextForPlayer(i, BankString, 3000, 1);
- GivePlayerMoney(i, -amount);
- Credit[i] -= amount;
- }
- else
- {
- SendClientMessage(i, 0xFFFFFF, "The bank wants its loan back now!");
- }
- }
- }
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[256], idx;
- cmd = strtok(cmdtext, idx);
- if (strcmp("/Creditdue", cmdtext, true, 11) == 0)
- {
- format(BankString, sizeof(BankString), "The amount of your Credit currently is: %d$", Credit[playerid]);
- SendClientMessage(playerid, COLOR_YELLOW, BankString);
- return 1;
- }
- if (strcmp("/Credit", 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(Credit[playerid] > 0)
- {
- format(BankString, sizeof(BankString), "You already have Credit of: %d$", Credit[playerid]);
- SendClientMessage(playerid, COLOR_RED , BankString);
- }
- else
- {
- 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");
- format(BankString, sizeof(BankString), "~y~Loan %d$", amount);
- GameTextForPlayer(playerid, BankString, 3000, 1);
- GivePlayerMoney(playerid, amount);
- Credit[playerid] = amount;
- }
- return 1;
- }
- if (strcmp("/creditpay", 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 > Credit[playerid])
- {
- format(BankString, sizeof(BankString), "You cant payback more then your max Credit , which is %d$", Credit[playerid]);
- SendClientMessage(playerid, COLOR_RED , BankString);
- }
- else if(amount < GetPlayerMoney(playerid))
- {
- format(BankString, sizeof(BankString), "You succesfully paid off Your Credit Of %d$, your new Credit amount is %d$", amount, Credit[playerid]-amount);
- SendClientMessage(playerid, COLOR_YELLOW , BankString);
- format(BankString, sizeof(BankString), "~r~-Loan %d$", amount);
- GameTextForPlayer(playerid, BankString, 3000, 1);
- GivePlayerMoney(playerid, -amount);
- Credit[playerid] = Credit[playerid]-amount;
- if(Credit[playerid] == 0)
- {
- SendClientMessage(playerid, COLOR_GREEN , "The Bank Is Thankfull for your credit payback");
- }
- }
- else
- {
- SendClientMessage(playerid, COLOR_RED , "You cant pay off more then you have in your wallet");
- }
- 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