Feky Posted June 24, 2009 Share Posted June 24, 2009 ive been try to sort this for a long time but cant seem to th hang of it.The problem is when a user rents a house and moves in then moves out again ,he become the owner and the original owner dosent get the house when the rent is over. properties.php <?php include "globals.php"; print "<center><font size='4' face='Arial, Helvetica, sans-serif'>Your Properties</font><hr width=75%>"; switch($_GET['action']) { case 'sell': sell_house(); break; case 'market': market_house(); break; case 'rent': rent_house(); break; case 'give': send_house(); break; case 'move': move_house(); break; case 'return': return_house(); break; default: your_houses(); break; } function your_houses() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prOWNER={$userid} ORDER BY h.hPRICE ASC",$c); if ($db->num_rows($q) == 0) { print "You have no houses."; } else { print "<table width=60% cellspacing=1>"; while($r=$db->fetch_row($q)) { print "<tr>"; $dfi=$db->query("SELECT * FROM users WHERE userid={$r['prOWNER']}",$c); $tb=$db->fetch_row($dfi); print "<td valign='center'> [b]Property: [/b]{$r['hNAME']} [b]Owner: [/b][url='viewuser.php?u={$tb[']{$tb['username']}[/url] [b]Upkeep: [/b]\${$r['hTAX']} [b]Will: [/b]{$r['hWILL']}</td> <td align='center'> [[url='properties.php?action=move&ID={$r[']Move In[/url]] "; $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$r['prID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($r['hWILL'] != '100' && $tr == '0') { print " [[url='properties.php?action=sell&ID={$r[']Sell[/url]] [[url='properties.php?action=market&ID={$r[']Market[/url]] [[url='properties.php?action=rent&ID={$r[']Rent[/url]] [[url='properties.php?action=give&ID={$r[']Give[/url]] "; } $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$r['prID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { print "[[url='properties.php?action=return&ID={$r[']Return[/url]] "; } $hprice=money_formatter($r['hPRICE']); print "</tr><tr><td height='10'></td></tr>"; } print "</table> "; } } function sell_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { die (" This house has been rented! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%> "); } $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); $r=$db->fetch_row($q); if ($r['prOWNER'] != $ir['userid']) { print " This house does not belong to you. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $db->query("UPDATE users SET money=money+{$r['hPRICE']} WHERE userid=$userid",$c); print " You sold your {$r['hNAME']} for \${$r['hPRICE']}! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); } } function send_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { die (" This house has been rented! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%> "); } if($_POST['user']) { $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); if($db->num_rows($q)==0) { print " Invalid house ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); $m=$db->query("SELECT * FROM users WHERE userid={$_POST['user']} LIMIT 1",$c); if($db->num_rows($m) == 0) { print " You are trying to send to an invalid user! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else if (!$_GET['ID']) { print " This user does not exist. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $rm=$db->fetch_row($m); $db->query("UPDATE properties SET prOWNER={$_POST['user']} WHERE prID={$_GET['ID']}",$c); } print " You sent the {$r['hNAME']} to {$rm['username']}. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; event_add($_POST['user'],"You received the {$r['hNAME']} from [url='viewuser.php?u=$userid']{$ir['username']}[/url]",$c,'transfer'); } } else if($_GET['ID']) { $id=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); if($db->num_rows($id)==0) { print " Invalid house ID. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else if ($_GET['ID']==0) { print " This user does not exist. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($id); print " [b]Enter the ID of the user you want to give the {$r['hNAME']} to.[/b] <form action='properties.php?action=give&ID={$_GET['ID']}' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' />User ID: <input type='text' name='user' value='' /> <input type='submit' value='Give House' /></form> <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } else { print " Invalid use of file. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } function market_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { die (" This house has been rented! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%> "); } $_POST['price'] = abs((int) $_POST['price']); if($_POST['price']) { $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE prID={$_GET['ID']} and prOWNER=$userid",$c); if($db->num_rows($q)==0) { print " Invalid House ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); $db->query("INSERT INTO propertymarket VALUES ('','$userid',{$_POST['price']},'{$r['hID']}')", $c); $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); print " House added to market. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } else { $q=$db->query("SELECT * FROM properties WHERE prID={$_GET['ID']} and prOWNER=$userid",$c); if($db->num_rows($q)==0) { print " Invalid House ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); print " Adding a house to the property market... <form action='properties.php?action=market&ID={$_GET['ID']}' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> Price: <input type='text' name='price' value='0' /> <input type='submit' value='Add' /></form> <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } } function return_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); $r=$db->fetch_row($q); if ($r['prOWNER'] != $ir['userid']) { print " This house does not belong to you. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); event_add($zf['reOWNER'],"You received the {$r['hNAME']} back from [url='viewuser.php?u=$userid']{$ir['username']}[/url]",$c,'transfer'); print " You returned the {$r['hNAME']}! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); $db->query("INSERT INTO `properties` (`prID`, `prOWNER`, `prHOUSE`) VALUES ('{$zf['rePID']}', '{$zf['reOWNER']}', '{$r['hID']}');",$c); $db->query("DELETE FROM rentals WHERE rePID={$_GET['ID']}",$c); } } function rent_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $yd=$db->query("SELECT * FROM rentals WHERE reRENTER=$userid AND rePID={$_GET['ID']}",$c); $zf=$db->fetch_row($yd); $tr=$db->num_rows($yd); if ($tr) { die (" This house has been rented! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%> "); } $_POST['price'] = abs((int) $_POST['price']); $_POST['days'] = abs((int) $_POST['days']); if($_POST['price'] || $_POST['days']) { $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE prID={$_GET['ID']} and prOWNER=$userid",$c); if($db->num_rows($q)==0) { print " Invalid House ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); $db->query("INSERT INTO rentalmarket VALUES ('','{$_GET['ID']}',{$_POST['price']},'{$_POST['days']}','$userid','{$r['hID']}')", $c); $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); print " House added to market. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } else { $q=$db->query("SELECT * FROM properties WHERE prID={$_GET['ID']} and prOWNER=$userid",$c); if($db->num_rows($q)==0) { print " Invalid House ID <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $r=$db->fetch_row($q); print " Adding a house to the rental market... <form action='properties.php?action=rent&ID={$_GET['ID']}' method='post'> <input type='hidden' name='ID' value='{$_GET['ID']}' /> Price (Daily): <input type='text' name='price' value='0' /> Days: <input type='text' name='days' value='0' /> <input type='submit' value='Add' /></form> <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } } } function move_house() { global $db,$ir,$c,$userid,$h; $_GET['ID'] = abs((int) $_GET['ID']); $q=$db->query("SELECT pr.*,h.* FROM properties pr LEFT JOIN houses h ON pr.prHOUSE=h.hID WHERE pr.prID={$_GET['ID']} AND pr.prOWNER=$userid LIMIT 1",$c); $r=$db->fetch_row($q); if ($r['prOWNER'] != $ir['userid']) { print " This house does not belong to you. <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; } else { $mpq=$db->query("SELECT * FROM houses WHERE hWILL={$ir['maxwill']}",$c); $mp=$db->fetch_row($mpq); print " You moved into your {$r['hNAME']}! <hr width=75%>> [url='properties.php']Back[/url]<hr width=75%>"; $db->query("INSERT INTO `properties` (`prID`, `prOWNER`, `prHOUSE`) VALUES ('', '$userid', '{$mp['hID']}');",$c); $db->query("UPDATE users SET maxwill={$r['hWILL']},will=0 WHERE userid=$userid",$c); $db->query("DELETE FROM properties WHERE prID={$_GET['ID']}",$c); } } $h->endpage(); ?> renatal.php <?php include "globals.php"; print "<center><font size='4' face='Arial, Helvetica, sans-serif'>Rental Market</font> "; switch($_GET['action']) { case "buy": buy_house(); break; case "remove": remove_house(); break; default: market_index(); break; } function market_index() { global $db,$ir,$c,$userid; print "<table width=90% cellspacing=1 class='table'> <tr> <th>Owner</th> <th>House</th> <th>Days</th> <th>Daily Price</th> <th>Links</th> </tr>"; $q=$db->query("SELECT rent.*, h.*, u.* FROM rentalmarket rent LEFT JOIN houses h ON rentHOUSE=h.hID LEFT JOIN users u ON u.userid=rent.rentOWNER ORDER BY rent.rentCOST, rent.rentDAYS ASC",$c); $lt=""; while($r=$db->fetch_row($q)) { if($r['rentOWNER'] == $userid) { $link = "[[url='rentals.php?action=remove&ID={$r[']Remove[/url]]"; } else { $link = "[[url='rentals.php?action=buy&ID={$r[']Rent[/url]]"; } $cost=money_formatter($r['rentCOST']); print "<tr> <td>[url='viewuser.php?u={$r[']{$r['username']}[/url] [{$r['userid']}]</td> <td>{$r['hNAME']}</td> <td>{$r['rentDAYS']}</td> <td>$cost</td> <td>$link</td> </tr>"; } print "</table>"; } function remove_house() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT rent.*, h.*, u.* FROM rentalmarket rent LEFT JOIN houses h ON rentHOUSE=h.hID LEFT JOIN users u ON u.userid=rent.rentOWNER ORDER BY rent.rentCOST, rent.rentDAYS ASC",$c); if(!$db->num_rows($q)) { print "Error, either this house does not exist, or you are not the owner. [url='rentals.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); $f=$db->query("SELECT FROM rentalmarket WHERE rentID={$_GET['ID']}"); $dg=$db->fetch_row($f); $db->query("INSERT INTO `properties` (`prID`, `prOWNER`, `prHOUSE`) VALUES ('NULL', '$userid', '{$dg['rentHOUSE']}');",$c); $db->query("DELETE FROM rentalmarket WHERE rentID={$_GET['ID']}",$c); print "House removed from market! [url='rentals.php']> Back[/url]"; } function buy_house() { global $db,$ir,$c,$userid,$h; $q=$db->query("SELECT rent.*, h.*, u.* FROM rentalmarket rent LEFT JOIN houses h ON rentHOUSE=h.hID LEFT JOIN users u ON u.userid=rent.rentOWNER ORDER BY rent.rentCOST, rent.rentDAYS ASC",$c); if(!$db->num_rows($q)) { print "This house is already occupied. [url='rentals.php']> Back[/url]"; $h->endpage(); exit; } $r=$db->fetch_row($q); if($r['reCOST'] > $ir['money']) { print "Error, you do not have the funds to start renting this house. [url='rentals.php']> Back[/url]"; $h->endpage(); exit; } event_add($r['rentOWNER'],"[url='viewuser.php?u=$userid']{$ir['username']}[/url] is now renting your {$r['hNAME']} for {$r['rentCOST']} per day.",$c); $db->query("INSERT INTO `properties` (`prID`, `prOWNER`, `prHOUSE`) VALUES ('{$r['rentPROP']}', '{$r['rentOWNER']}', '{$r['hID']}');",$c); $db->query("INSERT INTO `rentals` (`reID`, `reOWNER`, `rePID`, `reRENTER`, `reDAYS`, `reCOST`) VALUES ('NULL', '$userid', '{$r['rentPROP']}', '$userid', '{$r['rentDAYS']}', '{$r['rentCOST']}');",$c); $db->query("DELETE FROM rentalmarket WHERE rentID={$_GET['ID']}",$c); $db->query("UPDATE users SET rent={$r['rentCOST']} WHERE userid=$userid",$c); print "You are now renting the {$r['hNAME']} for \$".number_format($r['rentCOST'])." per day."; } $h->endpage(); ?> Quote Link to comment Share on other sites More sharing options...
Feky Posted June 24, 2009 Author Share Posted June 24, 2009 Re: +10 for who ever can fix this this is the cron $db->query("UPDATE rentals set reDAYS=reDAYS-1"); $io=$db->query("SELECT * FROM users where rent>0"); $hu=$db->fetch_row($io); $gd=$db->query("SELECT * FROM rentals WHERE reRENTER={$hu['userid']}"); $hd=$db->fetch_row($gd); $db->query("UPDATE users set money=money-{$hd['reCOST']} WHERE userid={$hd['reRENTER']}"); $q=$db->query("SELECT * FROM rentals WHERE reDAYS=0"); $ids=array(); while($r=$db->fetch_row($q)) { if (!$r['reDAYS']) { $rf=$db->query("SELECT * FROM properties WHERE prID={$r['rePID']}"); $gf=$db->fetch_row($rf); $db->query("DELETE FROM properties WHERE prID={$r['rePID']}"); $db->query("UPDATE users SET rent=0 WHERE userid={$r['reRENTER']}"); $db->query("INSERT INTO `properties` (`prID`, `prOWNER`, `prHOUSE`) VALUES ('{$r['rePID']}', '{$r['reOWNER']}', '{$gf['prHOUSE']}');",$c); $db->query("DELETE FROM rentals WHERE reDAYS=0"); } } Quote Link to comment Share on other sites More sharing options...
fbiss Posted June 26, 2009 Share Posted June 26, 2009 Re: +10 for who ever can fix this This is not a Game modification. Please be more careful when posting next time. ****Moving topic**** Quote Link to comment Share on other sites More sharing options...
Josh23 Posted June 27, 2009 Share Posted June 27, 2009 Re: +10 for who ever can fix this Just prevent them from renting houses, problem solved. Quote Link to comment Share on other sites More sharing options...
MrGi Posted June 27, 2009 Share Posted June 27, 2009 Re: +10 for who ever can fix this Care to post me the database inserts please? Gives me a better look at things Quote Link to comment Share on other sites More sharing options...
Feky Posted June 27, 2009 Author Share Posted June 27, 2009 Re: +10 for who ever can fix this CREATE TABLE `rentalmarket` ( `rentID` int(11) NOT NULL auto_increment, `rentPROP` int(11) NOT NULL, `rentCOST` int(11) NOT NULL, `rentDAYS` int(11) NOT NULL, `rentOWNER` int(11) NOT NULL, `rentHOUSE` int(11) NOT NULL, PRIMARY KEY (`rentID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; CREATE TABLE `rentals` ( `reID` int(11) NOT NULL auto_increment, `reOWNER` int(11) NOT NULL, `rePID` int(11) NOT NULL, `reRENTER` int(11) NOT NULL, `reDAYS` int(11) NOT NULL, `reCOST` int(11) NOT NULL, PRIMARY KEY (`reID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; Alter table users add rent int (11) not null default 0; Quote Link to comment Share on other sites More sharing options...
CraigF Posted June 27, 2009 Share Posted June 27, 2009 Re: +10 for who ever can fix this Care to post me the database inserts please? Gives me a better look at things You just wanted them so you can add this mod to your game, obviously! haha Quote Link to comment Share on other sites More sharing options...
MrGi Posted June 27, 2009 Share Posted June 27, 2009 Re: +10 for who ever can fix this Care to post me the database inserts please? Gives me a better look at things You just wanted them so you can add this mod to your game, obviously! haha Dude, Get a life. I am here to help people. I dont even own a damn game at that. And honestly, I dont give a rats hindend about this mod. Keep your thoughts to yourself. Quote Link to comment Share on other sites More sharing options...
Faz` Posted June 27, 2009 Share Posted June 27, 2009 Re: +10 for who ever can fix this MrGi ain't like that. Keep your comments to yourself dumbass. Quote Link to comment Share on other sites More sharing options...
CraigF Posted June 27, 2009 Share Posted June 27, 2009 Re: +10 for who ever can fix this Woah woah, was just my opinion. MrGi ain't like that. Keep your comments to yourself dumbass. Shut up little boy, noone likes a kissass. and MrGi, I was messing about so don't get so defensive. Lighten up a bit. Quote Link to comment Share on other sites More sharing options...
Feky Posted June 27, 2009 Author Share Posted June 27, 2009 Re: +10 for who ever can fix this does anyone know how to fix it its richard free mod anyone can add it once its fixed Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.