Jump to content
MakeWebGames

Loan System for Bank (ideas bounced around too)


Recommended Posts

So for my second mod, I am thinking about making a little loan system, the things it will include (hopefully :P):

1. Simple Loan/Repay system

2. If user hasn't paid money back he will be attacked by a "hitman" reason being not paying loan on time. Not sure how exactly this will work as in how many times he will be attacked or something until debt has been settled, so ideas will be helpful and welcome :)

3. This addition has not been thought through completely yet, so the current loan limit will be set to $100,000, but if the user gets a loan lets say greater than 50000 or 75000 and pays it back and does that 4-5 times maximum loan will increase to $150,000 - 200,000 but if user fails to pay back loan the limit will decrease.

So these are my ideas so far, I have started it already, tell me what you think of the idea and any possible changes or things you want to see added in to it. :)

Link to comment
Share on other sites

I currently have a moneylender mod that I created. If it something that you would like me to share I can post it here and see if there is anything you would like to add then feel free???

Sounds like a plan, can I use it as a guide maybe? If it's okay with you?

Link to comment
Share on other sites

Sounds like a nice little nifty mod, I'd suggest limiting the amount you can borrow to a combination of how old your account is, your level and you activity on the site.

Also need a way to stop multi's just borrowing as much as possible and sending all to one account. Maybe limit sending of "loaned" money entirely or for a certain amount of time.

Link to comment
Share on other sites

Sounds like a nice little nifty mod, I'd suggest limiting the amount you can borrow to a combination of how old your account is, your level and you activity on the site.

Also need a way to stop multi's just borrowing as much as possible and sending all to one account. Maybe limit sending of "loaned" money entirely or for a certain amount of time.

Thanks for the feedback, and yeah, the multi's thing will be quite important to stomp down on cheaters. Currently the amount of money being borrowed has been set to 100,000 and your idea is quite a good on about the day's old of an account.

Link to comment
Share on other sites

Thanks for the feedback, and yeah, the multi's thing will be quite important to stomp down on cheaters. Currently the amount of money being borrowed has been set to 100,000 and your idea is quite a good on about the day's old of an account.

Is that 100,000 per player, or 100,000 in total? As that is what Dave was saying

Link to comment
Share on other sites

I would suggest having to put up some kind of collateral as well. Maybe an expensive item (assuming you set the sell value at less) that they don't want to part with. The problem I've found with loan shark systems is it's hard to prevent people exploiting it through multiple accounts, as has been said, or simply spending the money and have no way to pay back the system.

Link to comment
Share on other sites

Is that 100,000 per player, or 100,000 in total? As that is what Dave was saying

100,000 per player, and you can only have one loan at anyone time, until that's paid back you can't get another ones, I did it like this to try and stop the abusing of this system (I know it's not the best idea) but hopefully I will work on it and think of other ideas to stop cheating.

 

I would suggest having to put up some kind of collateral as well. Maybe an expensive item (assuming you set the sell value at less) that they don't want to part with. The problem I've found with loan shark systems is it's hard to prevent people exploiting it through multiple accounts, as has been said, or simply spending the money and have no way to pay back the system.

I have thought of this and have been thinking of ideas to try and stop it, so I came up with this, if the loan is not paid back this will happen if you guys think it's a good idea or not to try and stop the cheating:

1. The user will be attacked and some money will be stolen the attack will be like said at the top by a hitman and they will be told it's because of overdue loan - though not sure how many times they will be attacked before the next measure is taken so some ideas to how many times they get attacked will be helpful.

2. There house will be attacked/burnt down/bombed so slowly it takes away there things which they may have spent the money on (the main things)

3. I don't no any other ways of trying to stop the cheating other than staff checking cash logs or something like that but that is the only other alternative I know.

Thanks for the ideas and hope to see more :-)

Edited by Script47
Link to comment
Share on other sites

100,000 per player, and you can only have one loan at anyone time, until that's paid back you can't get another ones, I did it like this to try and stop the abusing of this system (I know it's not the best idea) but hopefully I will work on it and think of other ideas to stop cheating.

I have thought of this and have been thinking of ideas to try and stop it, so I came up with this, if the loan is not paid back this will happen if you guys think it's a good idea or not to try and stop the cheating:

1. The user will be attacked and some money will be stolen the attack will be like said at the top by a hitman and they will be told it's because of overdue loan - though not sure how many times they will be attacked before the next measure is taken so some ideas to how many times they get attacked will be helpful.

2. There house will be attacked/burnt down/bombed so slowly it takes away there things which they may have spent the money on (the main things)

3. I don't no any other ways of trying to stop the cheating other than staff checking cash logs or something like that but that is the only other alternative I know.

Thanks for the ideas and hope to see more :-)

Good ideas but could really drive away players if they have no will to pay of the loan and would just end up with an unplayable account.

Link to comment
Share on other sites

Good ideas but could really drive away players if they have no will to pay of the loan and would just end up with an unplayable account.

Hmm, true, well I think I will finish the main script of then start working on ways to stop cheating, all ideas for this issues welcome :-)

Link to comment
Share on other sites

Okay. Here is what I have for the money lender system that I have. Obviously there are things in the code that are in place for my game but if you weed through it you will find what you need.

 

<?php 
include "globals.php";
If ($ir['daysold']<30)
{
   echo"<center>You are not old enough to borrow money.<br />
   Try again when you reach 30 days old.<br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
   $h->endpage();
   exit; 
}
$q=$db->query("SELECT lendermoney FROM moneylender WHERE userid=$userid");
$r=$db->fetch_row($q);
if($r['lendermoney']==1)
{
   echo"<center>You are no longer allowed to borrow money.<br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
   $h->endpage();
   exit;
}
switch ($_GET['action'])
{
   case 'borrowmoney':borrow_money();break;
   case 'moneyborrowed':money_borrowed();break;
   case 'payback':pay_back();break;
   case 'paidback':paid_back();break;
   default:moneylender_home();break;
}
function moneylender_home()
{
   global $db,$ir,$c,$userid,$h;
echo "<center><img src='/images/moneylender.png' width='500' height='150' alt='Money Lender' title='Money Lender' /><br /><br />
   <h3>You can either borrow money or pay back what you have already borrowed.<br />
   Which would you like to do?</h3>
   <a href='moneylender.php?action=borrowmoney'>Borrow some money</a><br />
   <a href='moneylender.php?action=payback'>Pay back on your loan</a><br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
}

function borrow_money()
{
   global $db,$ir,$c,$userid,$h;
   $csrf_token = create_csrf(__FILE__, session_id());

   $lend=($ir['level']*50000);
   echo"<center><h2><u>Borrowing Money</u></h2><br /><br />
   The terms of borrowing money from the Money Lender are simple.<br />
   You have 15 days to pay back the loan, including interest. <br /><span style='color:red'><strong>If you default on the loan,<br />
   you will be put in the pen <u>for 3 days</u> and added to his black list.</span></strong><br />
   If you have defaulted, The Money Lender will continue to add interest to your loan daily,<br />
   and he will continue to take the money from you until it is paid in full.<br />
   He will take the money from any or all of your bank accounts.<br />
   If you do not have money in your accounts, he will take it from your inventory.<br />
   If he does have to take it from your inventory, it will be based on the 'sell' price.<br />
   The items removed will <strong>NOT</strong> be donator items.<br /><br />
   You are allowed to borrow up to $".number_format($lend).".<br />
   Enter in the amount you would like to borrow.<br />
   By clicking on the Borrow button, you are agreeing to the terms<br />
   of the Money Lender.<br /><br />
   <table id='table-1' cellspacing='1'><tr> <td>
   <form action='moneylender.php?action=moneyborrowed' method='post'>
   <input type='hidden' name='csrf_token' value='" . $csrf_token . "'>
   <strong>Amount to borrow</strong>: <input type='text' name='moneyborrowed' value='' />
   <input type='submit' value='Borrow' /></form></td></tr></table>";
   echo"<br /><br />Changed your mind about borrowing some money?<br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
}
function money_borrowed()
{
   global $db, $ir, $c, $userid, $h;
   $csrf_token = create_csrf(__FILE__, session_id());
   if (array_key_exists('csrf_token', $_POST) && ($_POST['csrf_token'] == $csrf_token))
   {
       $lend=($ir['level']*50000);
       $_POST['moneyborrowed']=abs((int)$_POST['moneyborrowed']);
       if($_POST['moneyborrowed'] > $lend)
       {
           echo "<center>You have entered more than you are allowed to borrow.<br /><br />
           <a href='moneylender.php?action=borrowmoney'>Try again</a><br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
           $h->endpage();
           exit; 
       }
       $q2=$db->query("SELECT moneylent FROM moneylender WHERE userid=$userid");
       $r2=$db->fetch_row($q2);
       if($r2['moneylent']>0)
       {
           echo"<center>You have to pay off your current loan in full before you can borrow more money.<br />
           You still have \$".$r2['moneylent']." left owing.<br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
       }
       else
       {
           $gain=$_POST['moneyborrowed'];
           $ir['money']+=$gain;
           $q3=$db->query("SELECT * FROM moneylender WHERE userid=$userid");
           if(!$db->num_rows($q3))
           {
               $db->query("INSERT INTO moneylender VALUES ({$ir['userid']},'{$ir['username']}',0,{$gain},15)");
               $db->query("UPDATE users SET money=money+$gain WHERE userid=$userid");
           }
           else
           {
               $db->query("UPDATE moneylender SET `dayslent`=`dayslent`+ 15,`moneylent`=`moneylent`+'$gain' WHERE userid=$userid");
               $db->query("UPDATE `users` SET `money`=`money`+'$gain' where `userid`='$userid'", $C);
           }
           echo "<center>You were given \${$_POST['moneyborrowed']} from the money lender. <br />
           <strong>You now have 15 days to pay back the money you have borrowed.</strong><br />
           It is recommended that you go and deposit that money now,<br />
           unless you have mercs to protect you.<br /><br />
           <a href='banking.php'>Go to the bank</a><br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
           event_add($ir['userid'],"This is your copy of the agreement that you made with the Money Lender. You have borrowed \$".$_POST['moneyborrowed'].".
           You have 15 days to pay back the loan, including interest. If you default on the loan, you will be put in the pen for 3 days and added 
           to his black list. If you have defaulted, The Money Lender will continue to add interest to your loan daily, and he will continue to 
           take the money from you until it is paid in full. He will take that money from your accounts or your inventory. If he has to take it 
           from you inventory, it is based on the 'sell' price. The items removed to settle the debt will NOT be donator items.",$c);
       }
   }
   else
   {
       borrow_money();
   }
}
function pay_back()
{
   global $db,$ir,$c,$userid,$h;
   $csrf_token = create_csrf(__FILE__, session_id());

   $owing=$db->query("SELECT moneylent FROM moneylender WHERE userid=$userid");
   $owed=$db->fetch_row($owing);
   $owed1=($owed['moneylent']);
   echo"<center>You currently have \$".number_format($owed1)." outstanding.<br />
   How much would you like to repay on your loan?<br /><br />
   <table id='table-1' cellspacing='1'><tr><td>
   <form action='moneylender.php?action=paidback' method='post'>
   <input type='hidden' name='csrf_token' value='" . $csrf_token . "'>
   <strong>Amount to apply to your loan</strong>: <input type='text' name='paidback' value='' />
   <input type='submit' value='Pay Back' /></form></td></tr></table></center>";
   echo"<br /><br /><center>Changed your mind about paying some money on your loan?<br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
}
function paid_back()
{
   global $db,$ir,$c,$userid,$h;
   $csrf_token = create_csrf(__FILE__, session_id());

   if (array_key_exists('csrf_token', $_POST) && ($_POST['csrf_token'] == $csrf_token))
   {
       $_POST['paidback']=abs((int)$_POST['paidback']);
       $amount=$db->query ("SELECT moneylent,dayslent FROM moneylender WHERE userid=$userid LIMIT 1");
       $r4=$db->fetch_row($amount);
       if($r4['moneylent']<=0)
       {
           echo"<center>You currently do not have any outstanding loans.<br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
           $h->endpage();
           exit; 
       }
       if(($_POST['paidback'])>($r4['moneylent']))
       {
           echo "<center>You are trying to pay back more than you borrowed.<br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='moneylender.php?action=payback' method='get'>
           <input type='image' src='/images/tryagain.png' alt='submit' /></form></td><td>
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
           $h->endpage();
           exit; 
       }
       else
       {
           $gain=$_POST['paidback'];
           $ir['money']-=$gain;
           $princ=(($r4['moneylent'])-($gain));
           $db->query("UPDATE `users` SET `money`=`money`-'$gain' WHERE userid =$userid");
           $db->query("UPDATE moneylender SET `moneylent`=`moneylent`-'$gain' where `userid`='$userid'", $C);
           echo "<center>You have given \${$_POST['paidback']} to the money lender. <br />
           You now have <strong>\$".number_format($princ)."</strong> left owing to the money lender.<br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
       }
       $check=$db->query("SELECT moneylent, dayslent FROM moneylender WHERE userid=$userid");
       $checked=$db->fetch_row($check);
       if(($checked['moneylent']<=0) AND ($checked['dayslent']==0))
       {
           $db->query("UPDATE moneylender SET dayslent=0 WHERE userid=$userid");
           echo"<center><strong>You can now borrow more money if needs be.</strong><br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
       }
   }
   else
   {
       pay_back();
   }
}
$h->endpage();

 

Put this in the cron_day file.

 

$users = '';
$select = $db->query("SELECT userid, username, moneylent, dayslent FROM moneylender WHERE moneylent > 0 AND dayslent <= 0");
if($db->num_rows($select)) 
{
while($user = $db->fetch_row($select))
{
$users.= $user['username'].' ['.$user['userid'].']<br />'; 
}
$db->query("INSERT INTO events VALUES ('',1,unix_timestamp(),0,'Moneylender defaults<br /><br />".$users."')");
}

 

Hope this helps.

Link to comment
Share on other sites

Okay. Here is what I have for the money lender system that I have. Obviously there are things in the code that are in place for my game but if you weed through it you will find what you need.

 

<?php 
include "globals.php";
If ($ir['daysold']<30)
{
   echo"<center>You are not old enough to borrow money.<br />
   Try again when you reach 30 days old.<br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
   $h->endpage();
   exit; 
}
$q=$db->query("SELECT lendermoney FROM moneylender WHERE userid=$userid");
$r=$db->fetch_row($q);
if($r['lendermoney']==1)
{
   echo"<center>You are no longer allowed to borrow money.<br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
   $h->endpage();
   exit;
}
switch ($_GET['action'])
{
   case 'borrowmoney':borrow_money();break;
   case 'moneyborrowed':money_borrowed();break;
   case 'payback':pay_back();break;
   case 'paidback':paid_back();break;
   default:moneylender_home();break;
}
function moneylender_home()
{
   global $db,$ir,$c,$userid,$h;
echo "<center><img src='/images/moneylender.png' width='500' height='150' alt='Money Lender' title='Money Lender' /><br /><br />
   <h3>You can either borrow money or pay back what you have already borrowed.<br />
   Which would you like to do?</h3>
   <a href='moneylender.php?action=borrowmoney'>Borrow some money</a><br />
   <a href='moneylender.php?action=payback'>Pay back on your loan</a><br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
}

function borrow_money()
{
   global $db,$ir,$c,$userid,$h;
   $csrf_token = create_csrf(__FILE__, session_id());

   $lend=($ir['level']*50000);
   echo"<center><h2><u>Borrowing Money</u></h2><br /><br />
   The terms of borrowing money from the Money Lender are simple.<br />
   You have 15 days to pay back the loan, including interest. <br /><span style='color:red'><strong>If you default on the loan,<br />
   you will be put in the pen <u>for 3 days</u> and added to his black list.</span></strong><br />
   If you have defaulted, The Money Lender will continue to add interest to your loan daily,<br />
   and he will continue to take the money from you until it is paid in full.<br />
   He will take the money from any or all of your bank accounts.<br />
   If you do not have money in your accounts, he will take it from your inventory.<br />
   If he does have to take it from your inventory, it will be based on the 'sell' price.<br />
   The items removed will <strong>NOT</strong> be donator items.<br /><br />
   You are allowed to borrow up to $".number_format($lend).".<br />
   Enter in the amount you would like to borrow.<br />
   By clicking on the Borrow button, you are agreeing to the terms<br />
   of the Money Lender.<br /><br />
   <table id='table-1' cellspacing='1'><tr> <td>
   <form action='moneylender.php?action=moneyborrowed' method='post'>
   <input type='hidden' name='csrf_token' value='" . $csrf_token . "'>
   <strong>Amount to borrow</strong>: <input type='text' name='moneyborrowed' value='' />
   <input type='submit' value='Borrow' /></form></td></tr></table>";
   echo"<br /><br />Changed your mind about borrowing some money?<br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
}
function money_borrowed()
{
   global $db, $ir, $c, $userid, $h;
   $csrf_token = create_csrf(__FILE__, session_id());
   if (array_key_exists('csrf_token', $_POST) && ($_POST['csrf_token'] == $csrf_token))
   {
       $lend=($ir['level']*50000);
       $_POST['moneyborrowed']=abs((int)$_POST['moneyborrowed']);
       if($_POST['moneyborrowed'] > $lend)
       {
           echo "<center>You have entered more than you are allowed to borrow.<br /><br />
           <a href='moneylender.php?action=borrowmoney'>Try again</a><br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
           $h->endpage();
           exit; 
       }
       $q2=$db->query("SELECT moneylent FROM moneylender WHERE userid=$userid");
       $r2=$db->fetch_row($q2);
       if($r2['moneylent']>0)
       {
           echo"<center>You have to pay off your current loan in full before you can borrow more money.<br />
           You still have \$".$r2['moneylent']." left owing.<br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
       }
       else
       {
           $gain=$_POST['moneyborrowed'];
           $ir['money']+=$gain;
           $q3=$db->query("SELECT * FROM moneylender WHERE userid=$userid");
           if(!$db->num_rows($q3))
           {
               $db->query("INSERT INTO moneylender VALUES ({$ir['userid']},'{$ir['username']}',0,{$gain},15)");
               $db->query("UPDATE users SET money=money+$gain WHERE userid=$userid");
           }
           else
           {
               $db->query("UPDATE moneylender SET `dayslent`=`dayslent`+ 15,`moneylent`=`moneylent`+'$gain' WHERE userid=$userid");
               $db->query("UPDATE `users` SET `money`=`money`+'$gain' where `userid`='$userid'", $C);
           }
           echo "<center>You were given \${$_POST['moneyborrowed']} from the money lender. <br />
           <strong>You now have 15 days to pay back the money you have borrowed.</strong><br />
           It is recommended that you go and deposit that money now,<br />
           unless you have mercs to protect you.<br /><br />
           <a href='banking.php'>Go to the bank</a><br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
           event_add($ir['userid'],"This is your copy of the agreement that you made with the Money Lender. You have borrowed \$".$_POST['moneyborrowed'].".
           You have 15 days to pay back the loan, including interest. If you default on the loan, you will be put in the pen for 3 days and added 
           to his black list. If you have defaulted, The Money Lender will continue to add interest to your loan daily, and he will continue to 
           take the money from you until it is paid in full. He will take that money from your accounts or your inventory. If he has to take it 
           from you inventory, it is based on the 'sell' price. The items removed to settle the debt will NOT be donator items.",$c);
       }
   }
   else
   {
       borrow_money();
   }
}
function pay_back()
{
   global $db,$ir,$c,$userid,$h;
   $csrf_token = create_csrf(__FILE__, session_id());

   $owing=$db->query("SELECT moneylent FROM moneylender WHERE userid=$userid");
   $owed=$db->fetch_row($owing);
   $owed1=($owed['moneylent']);
   echo"<center>You currently have \$".number_format($owed1)." outstanding.<br />
   How much would you like to repay on your loan?<br /><br />
   <table id='table-1' cellspacing='1'><tr><td>
   <form action='moneylender.php?action=paidback' method='post'>
   <input type='hidden' name='csrf_token' value='" . $csrf_token . "'>
   <strong>Amount to apply to your loan</strong>: <input type='text' name='paidback' value='' />
   <input type='submit' value='Pay Back' /></form></td></tr></table></center>";
   echo"<br /><br /><center>Changed your mind about paying some money on your loan?<br /><br />
   <table id='table-2' cellspacing=\"0\" ><tr>   
   <td><form action='explore.php' method='get'>
   <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
}
function paid_back()
{
   global $db,$ir,$c,$userid,$h;
   $csrf_token = create_csrf(__FILE__, session_id());

   if (array_key_exists('csrf_token', $_POST) && ($_POST['csrf_token'] == $csrf_token))
   {
       $_POST['paidback']=abs((int)$_POST['paidback']);
       $amount=$db->query ("SELECT moneylent,dayslent FROM moneylender WHERE userid=$userid LIMIT 1");
       $r4=$db->fetch_row($amount);
       if($r4['moneylent']<=0)
       {
           echo"<center>You currently do not have any outstanding loans.<br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
           $h->endpage();
           exit; 
       }
       if(($_POST['paidback'])>($r4['moneylent']))
       {
           echo "<center>You are trying to pay back more than you borrowed.<br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='moneylender.php?action=payback' method='get'>
           <input type='image' src='/images/tryagain.png' alt='submit' /></form></td><td>
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
           $h->endpage();
           exit; 
       }
       else
       {
           $gain=$_POST['paidback'];
           $ir['money']-=$gain;
           $princ=(($r4['moneylent'])-($gain));
           $db->query("UPDATE `users` SET `money`=`money`-'$gain' WHERE userid =$userid");
           $db->query("UPDATE moneylender SET `moneylent`=`moneylent`-'$gain' where `userid`='$userid'", $C);
           echo "<center>You have given \${$_POST['paidback']} to the money lender. <br />
           You now have <strong>\$".number_format($princ)."</strong> left owing to the money lender.<br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
       }
       $check=$db->query("SELECT moneylent, dayslent FROM moneylender WHERE userid=$userid");
       $checked=$db->fetch_row($check);
       if(($checked['moneylent']<=0) AND ($checked['dayslent']==0))
       {
           $db->query("UPDATE moneylender SET dayslent=0 WHERE userid=$userid");
           echo"<center><strong>You can now borrow more money if needs be.</strong><br /><br />
           <table id='table-2' cellspacing=\"0\" ><tr>   
           <td><form action='explore.php' method='get'>
           <input type='image' src='/images/backtotown.png' alt='submit' /></form></td></tr></table></center>";
       }
   }
   else
   {
       pay_back();
   }
}
$h->endpage();

 

Put this in the cron_day file.

 

$users = '';
$select = $db->query("SELECT userid, username, moneylent, dayslent FROM moneylender WHERE moneylent > 0 AND dayslent <= 0");
if($db->num_rows($select)) 
{
while($user = $db->fetch_row($select))
{
$users.= $user['username'].' ['.$user['userid'].']<br />'; 
}
$db->query("INSERT INTO events VALUES ('',1,unix_timestamp(),0,'Moneylender defaults<br /><br />".$users."')");
}

 

Hope this helps.

Thanks for this newttster :-)

Link to comment
Share on other sites

  • 2 weeks later...
SELECT moneylent FROM moneylender WHERE userid=$userid

is fine ?

i dont think so

I don't understand. Are you asking for help or being sarcastic? Either way you could expand on the error or explain why someone else is in error instead of giving no information at all.

Edited by Dominion
Link to comment
Share on other sites

And I was just bored for 15 minutes, so I wrote this:

NOTE -- this hasn't uploaded to a server or tested, but should work (Hell, I don't even have it as a saved file -- closed the editor just now)

Functionality:

-- Allows users to loan a value determined by their level and days old. (New users, won't be worth **** to them)

-- For 3 days after taking out a loan, you can't pay it back.

-- You can not take out another loan until the current one is paid.

Code:

<?php
include_once('globals.php');
echo '<h2>Office of Bank Loans</h2>';


$maximum  = 100000;
$max_loan = MIN( ($ir['level'] * $ir['daysold']) * 500, $maximum );
$current  = 0;
$sql      = mysql_query("SELECT * FROM `bank_loans` WHERE `user` = '{$ir['userid']}'");
if ( mysql_num_rows($sql) == 0 )
{
   mysql_query("INSERT INTO `bank_loans` (`user`) VALUES ('{$ir['userid']}')");    
}
else
{
   $loan    = mysql_fetch_assoc($sql);
   $current = $loan['amount'];
}


if ($current > 0)
{
   if($loan['time'] > time())
   {
       echo '<p>Your loan is not repayable until ' . date("D jS M, g:i A", $loan['time']) . '. Come back then.</p>';
   }
   else
   {
       $repay = (array_key_exists('repay', $_POST) && (is_int($_POST['repay']) || ctype_digit($_POST['repay']))) ? substr($_POST['repay'], 0, 9) : FALSE ;
       if ($repay)
       {
           if ($repay > $ir['money'])
           {
               echo '<p>You do not have enough money to pay $' . number_format($repay) . '.</p>';
           }
           else
           {
               if ($repay > $loan['amount'])
               {
                   $repay = $loan['amount'];
               }
               echo '<p>You paid $' . number_format($repay) . ' from your loan balance.</p>
               <p>Thank You.</p>';
           }
       }
       else
       {
           echo '<p>Welcome back, ' . htmlentities($ir['username'], ENT_QUOTES, "UTF-8") . '.</p>
           <p>It would appear that you have an outstanding loan balance of $' . number_format($run['amount']) . '.</p>
           <p>Would you like to pay some off the balance today?</p>
           <h4>Pay towards loan debt</h4>
           <form action="" method="post">
           <p>How much would you like to pay?</p>
           <p>
               <input type="text" name="repay" value="">
           </p>
           <button>Pay Loan</button>
           </form>';
       }
   }
}
else
{
   if ($_SERVER['REQUEST_METHOD'] == "POST")
   {
       $amount = (array_key_exists('amount', $_POST) && (is_int($_POST['amount']) || ctype_digit($_POST['amount']))) ? substr($_POST['amount'], 0, 9) : FALSE ;
       if ($amount)
       {
           if ($amount > $max_loan)
           {
               echo '<p>You can only have a loan of $' . number_format($max_loan) . ' at most.';
           }
           else
           {
               $total = ($amount * 1.05);
               mysql_query("UPDATE `bank_loans` SET `amount` = '{$total}', `time` = (UNIX_TIMESTAMP() + (86400 * 3)) WHERE `user` = '{$ir['userid']}'");
               mysql_query("UPDATE `users` SET `money` = `money` + '{$amount}' WHERE `userid` = '{$ir['userid']}'");
               echo '<p>You have taken out a loan for $' . number_format($amount) . ' and with the 5% interest, you will need to pay back $' . number_format($total) . '.</p>
               <p>Thanks for using us for your business and hope you become a valued customer.</p>';
           }
       }
       else
       {
           echo '<p>You did not enter a valid amount to loan from us.</p>';
       }
   }
   else
   {
       echo '<p>Welcome to the loan department, ' . htmlentities($ir['username'], ENT_QUOTES, "UTF-8") . '.</p>
       <p>You can take a loan out today, for a maximum of $' . number_format($max_loan) . ', which will be yours for 3 days minimum.</p>
       <p>Minimum amount you can loan is $100</p>
       <p>The interest you pay on top of the loan will be 5%.</p>
       <h4>Would you like to take a loan out, ' . (strtolower($ir['gender']) == "male" ? 'Sir' : 'Madam') . '?</p>
       <form action="" method="post">
       <p>How much would you like to take out?</p>
       <p>
           <input type="text" name="amount" value="">
       </p>
       <button>Take Loan</button>
       </form>';
   }
}
$h->endpage();

 

Table definitions:

CREATE TABLE `bank_loans` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `user` int(11) unsigned NOT NULL DEFAULT '0',
 `amount` int(11) unsigned NOT NULL DEFAULT '0',
 `time` int(11) unsigned NOT NULL DEFAULT '0',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

 

Any problems or errors, post in the thread here

Edited by Guest
Link to comment
Share on other sites

SELECT moneylent FROM moneylender WHERE userid=$userid

is fine ?

i dont think so

As this was just a base model that I put up for Script47 to use as a reference, it's obvious that it further needs to be secured, etc to suit ones purpose ... how about shutting your pie whole and actually contributing something worthwhile to the thread, instead of being an asswipe.

@ Guest. Thank you for taking the time to run with the idea. I'm sure it works fine as most of your stuff usually does.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...