Jump to content
MakeWebGames

Monorail.php


Maniak

Recommended Posts

I'm having troubles with my Travel System (monorail.php). I have changed it to where each city has a different cost to travel to, and no matter what amount of money the Player has out, it lets them travel. If the Player has less money than the cost to travel to the city then the amount of money goes into negative figures. This is the if code (unfinished atm, but I wanted this solving before I move on):

 

<?phpinclude "globals.php";$_GET['to'] = abs((int) $_GET['to']);if(!$_GET['to']){echo "<div class='maincontent'><h1>Bus Station</h1><div class='main_text'>

Welcome to the Bus Station... Where would you like to travel today?
You can travel anywhere your Level allows you to, for a set price!</p>";$q=$db->query("SELECT * FROM cities WHERE cityid != {$ir['location']} AND cityminlevel <= {$ir['level']}");echo "

<table width=75% cellspacing=1 align=center><tr><td width=50%>[b]City[/b]</td><td width=30%>[b]Minimum Level[/b]</td><td width=20%>[b]Cost[/b]</td></tr>";while($r=$db->fetch_row($q)){echo "<tr><td>[url='monorail.php?to={$r[']{$r['cityname']}[/url]</td><td>{$r['cityminlevel']}</td><td>\${$r['citycost']}</td></tr>";}echo "</table></p></div></div>";}else{if($ir['money'] < $r['citycost']){echo "You don't have enough money.";}else if( ((int) $_GET['to']) != $_GET['to']){echo "Invalid city ID";}else{$q=$db->query("SELECT * FROM cities WHERE cityid = {$_GET['to']} AND cityminlevel <= {$ir['level']}");if(!$db->num_rows($q)){print "Error, this city either does not exist or you cannot go there.";}else{$r=$db->fetch_row($q);$db->query("UPDATE users SET money=money-{$r['citycost']},location={$_GET['to']} WHERE userid=$userid");echo "Congratulations, you paid \${$r['citycost']} and travelled to {$r['cityname']} on the monorail!";}}}$h->endpage();?>
Link to comment
Share on other sites

<?php
require_once("globals.php");

$_GET['to'] = isset($_GET['to']) && is_numeric($_GET['to']) ? abs((int) $_GET['to']) : false;

if(!$_GET['to'])
{
echo "<div class='maincontent'><h1>Bus Station</h1>
     <div class='main_text'>

Welcome to the Bus Station... Where would you like to travel today?

    You can travel anywhere your Level allows you to, for a set price!</p>";

$q=$db->query("SELECT `cityid`,`cityname`,`cityminlevel`,`citycost` FROM `cities` WHERE `cityid` != {$ir['location']} AND `cityminlevel` <= {$ir['level']}");


echo "

<table width=75% cellspacing=1 align=center>
       <tr><td width=50%>[b]City[/b]</td>
           <td width=30%>[b]Minimum Level[/b]</td>
           <td width=20%>[b]Cost[/b]</td></tr>";
while($r=$db->fetch_row($q))
{
echo "<tr><td>[url='monorail.php?to=".abs((int) $r[']".stripslashes($r['cityname'])."[/url]</td>
         <td>".abs((int) $r['cityminlevel'])."</td>
         <td>\$".abs((int) $r['citycost'])."</td></tr>";
}
echo "</table></p></div></div>";
}


else
{


$q=$db->query("SELECT `citycost`,`cityname` FROM cities WHERE cityid = {$_GET['to']} AND cityminlevel <= {$ir['level']}");

if(!$db->num_rows($q))
{
echo "Error, this city either does not exist or you cannot go there.";
$h->endpage();
exit;
}

$r=$db->fetch_row($q);

if($ir['money'] < $r['citycost'])
{
echo "You don't have enough money.";
$h->endpage();
exit;
}


$query1 = sprintf("UPDATE `users` SET `money`=`money`-%u,`location`=%u WHERE (`userid`=%d)", abs((int) $r['citycost']), $_GET['to'], abs((int) $userid)");
$db->query($query1);
echo "Congratulations, you paid \$".number_format($r['citycost'])." and travelled to ".stripslashes(htmlentities($r['cityname']))." on the monorail!";

}
$h->endpage();
?>

 

Hm..that should work ^

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...