Jump to content
MakeWebGames

Problem with "homemade" MCCodes!


2Pacalypse
 Share

Recommended Posts

When testing this script I constantly get "You are not high enough level to go here!"

It's written for MCCode V2

As far as I can see all is in perfect order... but obviously, something isn't

Help is appreciated :)

 

<?php

include "globals.php";

switch($_GET['city'])
{
case 'portadown': portadown(); break;
case 'london': london(); break;
case 'washington': washington(); break;
case 'paris': paris(); break;
case 'berlin': berlin(); break;
case 'vegas': vegas(); break;
case 'kathmandu': kathmandu(); break;
}

print "

<table class='table' width='65%' cellpadding='2'>
<tr>
<th>City</th><th>Level</th><th>Cost</th><th>Travel</th>
</tr>
<tr>
<td>Portadown</td><td>1</td><td>/$1,000</td><td>[url='airport.php?city=portadown']Go[/url]</td>
</tr>
<tr>
<td>London</td><td>5</td><td>/$3,000</td><td>[url='airport.php?city=london']Go[/url]</td>
</tr>
<tr>
<td>Washington</td><td>10</td><td>/$5,000</td><td>[url='airport.php?city=washington']Go[/url]</td>
</tr>
<tr>
<td>Paris</td><td>20</td><td>/$7,500</td><td>[url='airport.php?city=paris']Go[/url]</td>
</tr>
<tr>
<td>Berlin</td><td>30</td><td>/$10,000</td><td>[url='airport.php?city=berlin']Go[/url]</td>
</tr>
<tr>
<td>Las Vegas</td><td>40</td><td>/$12,500</td><td>[url='airport.php?city=vegas']Go[/url]</td>
</tr>
<tr>
<td>Kathmandu</td><td>50</td><td>/$15,000</td><td>[url='airport.php?city=vegas']Go[/url]</td>
</tr> ";


function portadown()
{
if ($ir['level'] > 0 and $ir['money'] >999)
{
$db->query("UPDATE users SET money=money-1000,location=1 WHERE userid=$userid");
print "You paid /$1,000 to travel to Portadown";
}
elseif ($ir['level'] < 1)
{
print "You are not high enoguh level to go here!";
}
elseif ($ir['money'] < 1000)
{
print "You don't have enough money to cover the ticket";
}
}

function london()
{
if ($ir['level'] > 4 and $r['money'] >2999)
{
$db->query("UPDATE users SET money=money-3000,location=2 WHERE userid=$userid");
print "You paid /$3,000 to travel to London";
}
elseif (($ir['level']) < 5)
{
print "You are not high enough level to go here!";
}
elseif ($r['money'] < 3000)
{
print "You don't have enough money to cover the ticket";
}
}

function washington()
{
if ($ir['level'] > 9 and $ir['money'] >4999)
{
$db->query("UPDATE users SET money=money-5000,location=3 WHERE userid=$userid");
print "You paid /$5,000 to travel to Washington";
}
elseif ($ir['level'] < 10)
{
print "You are not high enoguh level to go here!";
}
elseif ($ir['money'] < 5000)
{
print "You don't have enough money to cover the ticket";
}
}

function paris()
{
if ($ir['level'] > 19 and $ir['money'] >7499)
{
$db->query("UPDATE users SET money=money-7500,location=4 WHERE userid=$userid");
print "You paid /$7,500 to travel to Paris";
}
elseif ($ir['level'] < 20)
{
print "You are not high enoguh level to go here!";
}
elseif ($ir['money'] < 7500)
{
print "You don't have enough money to cover the ticket";
}
}

function berlin()
{
if ($ir['level'] > 29 and $ir['money'] >9999)
{
$db->query("UPDATE users SET money=money-10000,location=5 WHERE userid=$userid");
print "You paid /$10,000 to travel to Berlin";
}
elseif ($ir['level'] < 30)
{
print "You are not high enough level to go here!";
}
elseif ($ir['money'] < 10000)
{
print "You don't have enough money to cover the ticket";
}
}

function vegas()
{
if ($ir['level'] > 39 and $ir['money'] >12499)
{
$db->query("UPDATE users SET money=money-12500,location=6 WHERE userid=$userid");
print "You paid /$12,500 to travel to Las Vegas";
}
elseif ($ir['level'] < 40)
{
print "You are not high enough level to go here!";
}
elseif ($ir['money'] < 12500)
{
print "You don't have enough money to cover the ticket";
}
}

function kathmandu()
{
if ($ir['level'] > 49 and $ir['money'] >14999)
{
$db->query("UPDATE users SET money=money-15000,location=7 WHERE userid=$userid");
print "You paid /$12,500 to travel to Kathmandu 
This is a very cold place!";
}
elseif ($ir['level'] < 50)
{
print "You are not high enough level to go here!";
}
elseif ($ir['money'] < 15000)
{
print "You don't have enough money to cover the ticket";
}
}
$h->endpage();
?>

<?php
include "globals.php";
$_GET['to'] = abs((int) $_GET['to']);
if(!$_GET['to'])
{
print "Welcome to the Monorail Station. It costs \$1000 for a ticket.

Where would you like to travel today?
";
$q=$db->query("SELECT * FROM cities WHERE cityid != {$ir['location']} AND cityminlevel <= ");
print "<table width=75% cellspacing=1 class='table'><tr style='background:gray'><th>Name</th><th>Description</th><th>Min Level</th><th> </th></tr>";
while($r=$db->fetch_row($q))
{
print "<tr><td>{$r['cityname']}</td><td>{$r['citydesc']}</td><td>{$r['cityminlevel']}</td><td>[url='monorail.php?to={$r[']Go[/url]</td></tr>";
}
print "</table>";
}
else
{
if($ir['money'] < 1000)
{
print "You don't have enough money.";
}
else if( ((int) $_GET['to']) != $_GET['to'])
{
print "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
{
$db->query("UPDATE users SET money=money-1000,location={$_GET['to']} WHERE userid=$userid");
$r=$db->fetch_row($q);
print "Congratulations, you paid \$1000 and travelled to {$r['cityname']} on the monorail!";
}
}
}
$h->endpage();
?>

 

Thanks for reading, look forward to your help :wink:

Link to comment
Share on other sites

Re: Problem with "homemade" MCCodes!

I couldn't be bothered to read through all of your code as I got a headache with no indents.

However I can see you have a lot of repetitive code going on there, so I will just make a suggestion you do something like this:

 

<?php
function canTravel($player, $location) {

# We can display this to the player later so they no WHY they are not allowed to travel if that may be the case.
$error = "";

# Does the player meet the correct level?
if ($player['level'] < $location['level_requirement'])
	$error .= "You do not meet the level requirement to travel here. 
";

# Does the player have enough money?
if ($player['money'] < $location['travel_cost'])
	$error .= "You do not have enough money to travel here. 
";

# No errors encountered. Let the player travel.
if ($error == "")
	return true;

return false;
}
?>

 

This is a generic function you can use to test for all locations but it requires you have 2 things.

The first is an array of player information. Personally I would grab this from a database table row.

Secondly is an array of "location" information (or places). I can see you hard coded a lot of prices and level requirements. I would also store this in its own table (probably called places), and have columns representing all the similar information required for each place. Some examples are - name, level_requirement, travel_cost etc...

Doing it that way it would be easy to change the name\cost of a place without having to go through everybit of code that mentions it.

To get a list of places within your game you wouls just grab all the rows from the "places" table etc...

Hope that helps and makes some sort of sense.

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.

 Share

×
×
  • Create New...