Jump to content
MakeWebGames

Recommended Posts

Posted

Hello all.

While working on upgrading the fishing mod I found on here, I ran into a slight problem. It's showing all data I'm trying to draw from the table as 0, which is not the case. For example on the Shop page to buy bait, it is showing up that I can buy 0 more bait, where on the table it says I have 30 more. It also is not showing the upgrade link on the index page despite the boat's level being under 5.

If someone could assist me in locating the problem I would very much appreciate.

 

<?php
include "globals.php";
global $c,$ir,$h,$userid,$db;
$fishy=$db->query("SELECT * FROM fishing WHERE fsUSERID=$userid");
$fish=mysql_fetch_array($fishy);
switch($_GET['action'])
{
case 'upper': fish_1(); break;
case 'lower': fish_2(); break;
case 'buy': fish_3(); break;
case 'upgrade': fish_4(); break;
case 'shop': fish_5(); break;
default: fish_index(); break;
}
if ($ir['jailtime'] > 0){
print "<center>The docks are closed to jail birds come back when thay release you</center>";
exit;
}
if ($ir['hospital'] > 0){
print "<center>You cant go fishing while in hospital</center>";
exit;
}
if($fish['fsDAMAGE'] > 0)
{
print "Your boat has been damaged. It will take {$fish['fsDAMAGE']} more minutes until it is repaired.";
exit;
}

function fish_index()
{
global $c,$ir,$h,$userid,$db;
if($ir['boat'] < 0)
{
print "Would you like to purchase a boat?



[[url='fish.php?action=buy']Purchase for \$50,000[/url]]";
}
else
{
$costy=$fish['fsLEVEL']*$fish['fsLEVEL']*100000;
print "<table><tr><th>

Welcome to the fishing docks.
</th></tr>
<tr><td>[img=images/river.jpg]

</td></tr>
<tr><td><center><u>Upper Fishing Docks</u>

[[url='fish.php?action=upper']Go Fishing[/url]]</center>
</td></tr>
<tr><td><center><u>Lower Fishing Docks</u>

[[url='fish.php?action=lower']Go Fishing[/url]]</center>
</td></tr>
<tr><td><center>[[url='fish.php?action=shop']Purchase Fish Bait[/url]]</center>
</td></tr>";
if($fish['fsLEVEL'] > 5)
{
print "<tr><td><center>[[url='fish.php?action=upgrade']Upgrade your Boat[/url]]
Costs \$costy</center>
</td></tr>";
}
print "</table>";
}
}

function fish_1()
{
global $c,$ir,$h,$userid,$db;
if($fish['fsFEED'] <= 0){
print "You have run out of bait. Please purchase more soon.";
$h->endpage();
}
$rand = rand(1,6);
if($rand=='1')
{
$rand_fish = rand(1,32);
$rand_money = $rand_fish*125;
print "<center>You begin fishing and found $rand_fish small fish. Taking them to the docks you find a merchant willing to buy them for \$rand_money.</center>

You Currently can fish {$fish['fsFEED']} more times";
$db->query("UPDATE fishing SET fsMONEY=fsMONEY+'$rand_money',fsFEED=fsFEED-1 WHERE fsUSERID=$userid",$c);
} else if($rand=='2') {
$rand_fish = rand(1,22);
$rand_money = $rand_fish*300;
print "<center>You begin fishing and found $rand_fish medium fish. Taking them to the docks you find a merchant willing to buy them for $$rand_money.</center>

You have {$fish['fsFEED']} bait left.";
$db->query("UPDATE fishing SET fsMONEY=fsMONEY+'$rand_money',fsFEED=fsFEED-1 WHERE fsUSERID=$userid",$c);
} else if($rand=='3') {
print "Taking your craft out to the middle of the Yellow River, you try to catch some fish. However you do not seem to have much luck today as you end up falling out of your boat! A friendly fisherman comes along to assist you in time, before you lose today's catch!";
} else if($rand=='4') {
$time = rand(12,31);
print "You are just about to cast your line when you feel a sudden surge of water around your ankles. Water is entering your boat from somewhere and you know enough about boats to know you do not have long to get to shore. Using everything you can you quickly get your boat back to the docks to get repaired.

It will take $time minutes.";
$db->query("UPDATE fishing SET fsDAMAGE=$time WHERE fsUSERID=$userid",$c);
} else {
print "You cast your line and wait for a while. Soon though you begin to realize that there may not be any fish! When you bring up your hook, however, you find out that the bait you used is no longer there...

You have {$fish['fsFEED']} bait left.";
$db->query("UPDATE fishing SET fsFEED=fsFEED-1 WHERE fsUSERID=$userid",$c);
}

print "<center>
[[url='fish.php?action=fish']Fish in this spot again[/url]]</center>
";

print "<center>[[url='fish.php']Back[/url]]</center>
";
}
function fish_2()
{
global $c,$ir,$h,$userid,$db;
if($fish['fsFEED'] <= 0){
print "You have run out of bait. Please purchase more soon.";
$h->endpage();
}
$rand = rand(1,7);


if($rand=='3') {
$rand_fish = rand(1,12);
$rand_money = $rand_fish*700;
print "<center>You begin fishing and found $rand_fish large fish. Taking them to the docks you find a merchant willing to buy them for $$rand_money.</center>

You have {$fish['fsFEED']} bait left.";
$db->query("UPDATE fishing SET fsMONEY=fsMONEY+'$rand_money',fsFEED=fsFEED-1 WHERE fsUSERID=$userid",$c);
}
else if($rand=='4')
{
$rand_fish = rand(1,5);
$rand_money = $rand_fish*1500;
print "<center>You begin fishing and found $rand_fish rare fish. Taking them to the docks you find a merchant willing to buy them for $$rand_money.</center>

You have {$fish['fsFEED']} bait left.";
$db->query("UPDATE fishing SET fsMONEY=fsMONEY+'$rand_money',fsFEED=fsFEED-1 WHERE fsUSERID=$userid",$c);
} else if($rand=='2') {
print "You cast your line and wait for a while. Soon though you begin to realize that there may not be any fish! When you bring up your hook, however, you find out that the bait you used is no longer there...

You have {$fish['fsFEED']} bait left.";
$db->query("UPDATE fishing SET fsFEED=fsFEED-1 WHERE fsUSERID=$userid",$c);
} else if($rand=='1') {
$time = rand(12,31);
print "You are just about to cast your line when you feel a sudden surge of water around your ankles. Water is entering your boat from somewhere and you know enough about boats to know you do not have long to get to shore. Using everything you can you quickly get your boat back to the docks to get repaired.

It will take $time minutes.";
$db->query("UPDATE fishing SET fsDAMAGE=$time WHERE fsUSERID=$userid",$c);
}
else
{
print "Taking your craft out to the middle of the Yellow River, you try to catch some fish. However you do not seem to have much luck today as you end up falling out of your boat! A friendly fisherman comes along to assist you in time, before you lose today's catch!";
}

print "<center>
[[url='fish.php?action=lower']Fish in this spot again[/url]]</center>
";

print "<center>[[url='fish.php']Back[/url]]</center>
";
}
function fish_3()
{
global $c,$ir,$h,$userid,$db;
if($ir['boat'] < 0)
{
print "Congradulations, you have now purchased a boat for \$50,000! Be sure to keep good care of her and she will earn you lots of cash!


[[url='fish.php']Back[/url]]";
$db->query("INSERT INTO fishing VALUES ('', '$userid', '0', '0', '30', '1', '0')");
$db->query("UPDATE users SET boat=1,money=money-50000 WHERE userid=$userid");
$h->endpage();
}
else
{
print "You already have a boat.


[[url='fish.php']Back[/url]]";
$h->endpage();
}
}
function fish_4()
{
global $c,$ir,$h,$userid,$db;
$costy=$fish['fsLEVEL']*$fish['fsLEVEL']*100000;
$expense=$ir['money']-$costy;
if($ir['boat'] < 0)
{
print "You do not have a boat to upgrade!


[[url='fish.php']Back[/url]]";
$h->endpage();
}
else if($fish['fsLEVEL'] >= 5)
{
print "There is no way to upgrade your boat any further.


[[url='fish.php']Back[/url]]";
$h->endpage();
}
else if($expense < 0)
{
print "You do not have enough money to purchase this upgrade.


[[url='fish.php']Back[/url]]";
$h->endpage();
}
else
{
print "Congradulations, you have now upgraded your boat for \$costy!

";
$db->query("UPDATE fishing SET fsLEVEL=fsLEVEL+1 WHERE fsUSERID=$userid");
$db->query("UPDATE users SET money=money-$costy WHERE userid=$userid");
}
}
function fish_5()
{
global $c,$ir,$h,$userid,$db;
$_POST['feed']=abs($_POST['feed']);
if($ir['boat'] < 0)
{
print "You need a boat to buy bait!


[[url='fish.php']Back[/url]]";
$h->endpage();
}
else if($_POST['feed'] > $fish['fsSHOP'])
{
print "You are trying to purchase too much bait, the shop only has {$fish['fsSHOP']} left. Check again later for more.";
}
else if(!$_POST['feed'])
{
$feed=abs($fish['fsFEED']);
$max=abs($fish['fsSHOP']);
print "<form action='fish.php?action=feed' method='post'>
Every unit of bait costs 500$.

You have $feed out of $max.


<input type='text' name='feed' value='{$_POST['feed']}' maxlength='10' length='10' size='10' width='10' />

<input type='submit' value='Buy Bait' />
</form>";
$h->endpage();
}
else
{
$cost=$_POST['feed']*500;
print "You have bought {$_POST['feed']} for \$cost.



[[url='fish.php?action=shop']Back[/url]]";
$db->query("UPDATE fishing SET fsFEED=fsFEED+{$_POST['feed']},fsSHOP=fsSHOP-{$_POST['feed']} WHERE fsUSERID=$userid");
$db->query("UPDATE users SET money=money-$cost WHERE userid=$userid");
}
}
$h->endpage();

?>
Posted

XD thank you both, Equinox helped me last night and told me that fetch_assoc was what I needed. I was going to update this but my net spazzed soon after v_v

Posted

I created a fishing mod not long ago, its based on my search the streets. While this is part of a much larger crafting mod, it became quite complicated, but is easy to simplify and separate. The file also runs on an image map. This is a nice difference from your run of the mill fishing that only results in cash, it also combines with Danny's crafting mod very nicely (thats what it was built for)

<?php
include(DIRNAME(__FILE__).'/globals.php');

$cityname = mysql_fetch_assoc(mysql_query("SELECT `cityname` FROM `cities` WHERE (`cityid` = ".$ir['location'].")"));

echo '<h2>'.htmlentities($cityname['cityname']).' Lake</h2>
[i]Welcome to the Lake. Fishingin '.htmlentities($cityname['cityname']).' takes energy. 
Every time you fish, you loose diferent ammounts of energy.

Which fish would you like 
to catch?
[/i]';

$mn = mysql_query("SELECT * FROM `fish` WHERE `Level` < ".$ir['level']." ORDER BY Level ASC");
echo '<table border = "1" cellspacing = "3">';
while($info = mysql_fetch_assoc($mn)) {
	echo '
		<tr>
		<a href = "'.htmlentities($info['file']).'">Catch '.htmlentities($info['name']).' </a> 
</tr>';
}
echo '</tr></table>';

$h->endpage();
?>

 

This file pulls the list of different fish and the link to that file from the sql database.

To create the DB:

[mysql]CREATE TABLE `fish` (

`name` varchar(28) NOT NULL,

`file` varchar(28) NOT NULL,

`level` int(11) NOT NULL

) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `fish` VALUES('trout', 'craft/fish/trout.php', 1);[/mysql] feel free to add any other fish types you would like along with level required to access the file, and the name of that file.

then edit the following file to create different kinds of fish, difficulty of catching that fish, and any other type variable you want for each fish. Separate files also allow you to easily separate lake fish from river fish from ocean fish that can only be caught in different locations (just add an if statement for location)

<?php
include('globals.php'); //common stuff
//Fish for trout file

$q=$db->query("SELECT * FROM Skills WHERE user={$ir['userid']}"); 
$row = mysql_fetch_assoc($q);
$expm= ($row['flevel'] * 500); //checks fishing exp level can be changed to combat level 
$db->query("UPDATE Skills SET fexpneed= $expm WHERE user={$ir['userid']}"); //updates fishing exp needed based on fishing level

if($row['fexp'] >= $row['fexpneed'])
{
$db->query("UPDATE Skills SET flevel=flevel+1 WHERE user={$ir['userid']}"); 
}
// updates fishing level
if($row['flevel']  <=0)
{
   echo "You do not have enough Fishing experience. Come back later.";
   $h->endpage();
   exit;}
if($ir['energy'] <= 4)
{
   echo "You do not have enough energy. Come back later.";
   $h->endpage();
   exit;
}
//checks energy level
if($ir['jail'] || $ir['hospital'])
{
   echo "You can't access this page while in the hospital or jail.";
   $h->endpage();
   exit;
}
//checks hospital
$cityname = $db->fetch_single($db->query("SELECT cityname FROM cities WHERE cityid = {$ir['location']}"));

if(isset($_GET['search'])) //search
{
   $hard = mt_rand(1,3); // 1:3 chance of hard outcome, change this for each different fish
   $ore = Trout; //sets what kind of fish is named in the results
   $oreid = 134; //what item gets inserted into inventory when successful

if($hard == 1){
               $amt = mt_rand(1,3);
               item_add($userid,  $oreid, $amt);
               $db->query("UPDATE Skills Set fexp=fexp+1 WHERE user=$userid"); 
               $out = "You collected {$amt} {$ore}.";
           }
else	    {
               $out = "There is nothing here.";
           }

   $db->query("UPDATE users SET energy = energy- 3 WHERE userid = {$userid}"); //decrement energy
   ?>
   <div style="text-align:center">
       <?= $out ?>



       <?= ($ir['energy']-3> 0) ? "<a href=\"?\">Search again?</a>" : "" ?>
   </div>

   <?php
}
else //index
{
?>
<h2 style="text-align:center;"><?= $cityname ?> Lake</center></h2>

<div style="text-align:center;">
    Welcome to the Lake, <?= $ir['username'] ?>. Fishing in '.htmlentities($cityname['cityname']).' takes energy. Every time you fish, you energy loose 3 energy.


    Click on the image to Cast your line, net, or trap!



[img=/images/lake.jpg]</center>
<map name='Map'>
 <area shape='rect' coords='2,2,66,66' href="?search">
 <area shape='rect' coords='69,2,134,66' href="?search">
 <area shape='rect' coords='138,2,202,66' href="?search">
 <area shape='rect' coords='205,2,270,66' href="?search">
 <area shape='rect' coords='274,2,338,66' href="?search">
 <area shape='rect' coords='340,2,407,66' href="?search">

 <area shape='rect' coords='2,70,66,133' href="?search">
 <area shape='rect' coords='69,70,136,133' href="?search">
 <area shape='rect' coords='137,70,202,133' href="?search">
 <area shape='rect' coords='205,70,270,133' href="?search">
 <area shape='rect' coords='274,70,338,133' href="?search">
 <area shape='rect' coords='340,70,407,133' href="?search">

 <area shape='rect' coords='2,138,405,202' href="?search">
 <area shape='rect' coords='69,138,406,202' href="?search">
 <area shape='rect' coords='137,138,338,202' href="?search">
 <area shape='rect' coords='205,138,271,202' href="?search">
 <area shape='rect' coords='274,138,338,202'href="?search">
 <area shape='rect' coords='340,138,407,202' href="?search">

 <area shape='rect' coords='2,206,66,270' href="?search">
 <area shape='rect' coords='69,206,136,270' href="?search">
 <area shape='rect' coords='137,206,202,270' href="?search">
 <area shape='rect' coords='205,206,270,270' href="?search">
 <area shape='rect' coords='274,206,338,270' href="?search">
 <area shape='rect' coords='340,206,407,270' href="?search">

 <area shape='rect' coords='2,273,66,337' href="?search">
 <area shape='rect' coords='69,273,136,337' href="?search">
 <area shape='rect' coords='137,273,202,337' href="?search">
 <area shape='rect' coords='205,273,270,337' href="?search">
 <area shape='rect' coords='274,273,338,337' href="?search">
 <area shape='rect' coords='340,273,407,337' href="?search">

 <area shape='rect' coords='2,341,66,405' href="?search">
 <area shape='rect' coords='69,341,136,405' href="?search">
 <area shape='rect' coords='137,341,202,405' href="?search">
 <area shape='rect' coords='205,341,270,405' href="?search">
 <area shape='rect' coords='274,341,338,405' href="?search">
 <area shape='rect' coords='340,341,407,405' href="?search">

 <area shape='rect' coords='2,410,66,473' href="?search">
 <area shape='rect' coords='69,410,136,473' href="?search">
 <area shape='rect' coords='137,410,202,473' href="?search">
 <area shape='rect' coords='205,410,270,473' href="?search">
 <area shape='rect' coords='274,410,338,473' href="?search">
 <area shape='rect' coords='340,410,407,473' href="?search">
</map>
</div>
<?php
}

$h->endpage();
?>

Lists fish according to what you can attempt

fishss.jpg

SS of getting ready to cast

lakess.jpg

Success

fishcaughtss.jpg

Fail

fishfailss.jpg

Posted

lol DJK, well, you secured it, so I have to say thanks for that as well as the compliment. You should look at the mining one again .... That was the hard one!

Posted

Nice work Lilith.

I have something similiar on rulerofzu.com but its a jquery imagemap and the coordinates are random displayed.

So you click a hotspot you get nothing find another get something with a different map and items to find per city or no map at all.

If you find something then you auto receive it but clicking again will get nothing. Linked into my own skills training and workshop :D

Posted
lol DJK, well, you secured it, so I have to say thanks for that as well as the compliment. You should look at the mining one again .... That was the hard one!

Wait I don't remember seeing that, then again quick glance indicates there isn't anything really(*maybe query touch ups but I ain't complaining*) within that code that needs it, so that may be why, who knows.

So I still say to you, good job! :P

*Shivers at the sight of image maps*

Posted

:D I appreciate the offer Lilith, however I absolutely loath ending a project I started in midflight. I'll get this mod perfected one way or another XD

Posted

no worries Ade, I couldnt help much on what you were doing, so I offer what I could.

Zu, your method sounds very interesting! But, i dont completely understand what you mean. Could i talk you into a pm with a link and test acount info?

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