[ADVANCED]Loan System saved in DB with auto deduction ( UPDATED )

Started by Anik, Dec 25, 2015, 11:04 AM

Previous topic - Next topic

Anik

DID you add it there???
class PlayerStats

Cool

Thanks I want to create that system but i am little weak in scripting so i have some probs in making this thanks for it

Anik

Quote from: King on Jan 01, 2016, 08:40 AMThanks I want to create that system but i am little weak in scripting so i have some probs in making this thanks for it
it's OK. Did ufind any bug??

Cool

No Bug but the system is not fully complete its needs to be updated
And its needs changes like islogged isreg its the 0.3 things in now very less people using

W3aPoN^

Hmm BUG When i Reconnect And /loan 5000 They Give Me Loan When i Reconnect 2nd Time And Do This Again They give Me Load 2nd Time instead Of You Already Took Loan LOL Please Solve Thanks


Anik

Snippet UPDATED

This UPDATE uses database to store loan info.
Also, if the player doesn't pay the loan in 1 week. It will be taken from his account automatically.

Kewun


KAKAN

A bit of suggestion: You don't need a class for having just one variable.
Also, don't set the value( loanamount ) to null. As far as I know, I had some strange problems with that, it might be fixed, but why to take risk :D?
oh no

Anik

:P
Quote from: KAKAN on Jan 23, 2017, 04:36 PMA bit of suggestion: You don't need a class for having just one variable.
Also, don't set the value( loanamount ) to null. As far as I know, I had some strange problems with that, it might be fixed, but why to take risk :D?
No, I didn't face any problem by setting it to null. And I used class cuz many people use it to store players data

!

Quote from: Kewun on Jan 23, 2017, 04:36 PMtaken
What if he has 0$ ? bankrupts?

Replace
function onPlayerJoin( player )
 {
                // Set the cash of the player here. I didn't store the amount of cash the player have. Use your own.
  status[ player.ID ] = PStats( );
  local q = QuerySQL( LoanDB, "SELECT Amount, Time FROM Loan WHERE Name = '" + player.Name + "'");
  if( q )
  {
   status[ player.ID ].loanamount = GetSQLColumnData( q, 0);
   local time2 = GetSQLColumnData( q, 1 ).tointeger();
   if( ( time() - time2 ) > 604800 ) //604800 = 7 days
   {
    QuerySQL( LoanDB, "DELETE FROM Loan WHERE Name = '" + player.Name + "'");
    player.Cash -= status[ player.ID ].loanamount.tointeger();
    ClientMessage ( "$"+status[ player.ID ].loanamount+" has been deducted from your account as you didn't pay the loan!", player, 255, 0, 255);
    status[ player.ID ].loanamount = null;   
   }
  }
  FreeSQLQuery( q );
 }
   With(Untested)
function onPlayerJoin( player )
 {
                // Set the cash of the player here. I didn't store the amount of cash the player have. Use your own.
  status[ player.ID ] = PStats( );
  local q = QuerySQL( LoanDB, "SELECT Amount, Time FROM Loan WHERE Name = '" + player.Name + "'");
  if( q )
  {
   status[ player.ID ].loanamount = GetSQLColumnData( q, 0);
   local time2 = GetSQLColumnData( q, 1 ).tointeger();
   if( ( time() - time2 ) > 604800 ) //604800 = 7 days
   {
   if ( player.Cash != 0 && player.Cash < status[ player.ID ].loanamount.tointeger() )
   {
    local loanleft = player.Cash - status[ player.ID ].loanamount.tointeger();
 QuerySQL( LoanDB, "UPDATE Loan SET Amount='" + loanleft.tointeger() + "' WHERE Name='" + player.Name + "'");
    player.Cash = 0;
    ClientMessage ( "$"+loanleft+" has been deducted from your account as you didn't pay the loan!", player, 255, 0, 255);
    status[ player.ID ].loanamount = loanleft.tointeger();   
   }

  else if ( player.Cash >= status[ player.ID ].loanamount.tointeger() )
   {
    QuerySQL( LoanDB, "DELETE FROM Loan WHERE Name = '" + player.Name + "'");
    player.Cash -= status[ player.ID ].loanamount.tointeger();
    ClientMessage ( "$"+status[ player.ID ].loanamount+" has been deducted from your account as you didn't pay the loan!", player, 255, 0, 255);
    status[ player.ID ].loanamount = null;   
   }
  }
  }
  FreeSQLQuery( q );
 }
Well its just an example now some of the players are going to say what if player deposit all of their money.
My answer is create a function which will do the same as given above and add in both on player join and on player request class.
Second option is
 to add in  deposit cmd.
To decrease spaming of msgs use this
if ( player.Cash > 1000 && player.Cash < status[ player.ID ].loanamount.tointeger() )

Discord: zeus#5155