Pet system


Hey, this was requested by Insane but im sure a lot of you will like it. Sorry it isn't brilliant coded but we were really enthusiastic to get this released we didnt have too much time. So first we are going to start with the SQL ok?

PHP Code
  1.  
  2. ALTER TABLE `members` ADD `pet_id` VARCHAR( 225 ) NOT NULL default '0';
  3.  
  4. -- --------------------------------------------------------
  5.  
  6. CREATE TABLE `pet_enemy` (
  7. `id` int(11) NOT NULL auto_increment,
  8. `name` varchar(225) NOT NULL,
  9. `hp` varchar(225) NOT NULL,
  10. `level` varchar(225) NOT NULL,
  11. `hp_level` varchar(225) NOT NULL,
  12. `image` varchar(225) NOT NULL,
  13. PRIMARY KEY (`id`)
  14. ) ENGINE=MyISAM;
  15.  
  16. -- --------------------------------------------------------
  17.  
  18. CREATE TABLE `pet_item` (
  19. `id` int(11) NOT NULL auto_increment,
  20. `name` varchar(225) NOT NULL,
  21. `hp` varchar(225) NOT NULL,
  22. `price` varchar(225) NOT NULL,
  23. PRIMARY KEY (`id`)
  24. ) ENGINE=MyISAM;
  25.  
  26. -- --------------------------------------------------------
  27.  
  28. CREATE TABLE `pet_shop` (
  29. `id` int(11) NOT NULL auto_increment,
  30. `name` varchar(225) NOT NULL,
  31. `hp` varchar(225) NOT NULL default '10',
  32. `xp` varchar(225) NOT NULL default '0',
  33. `level` varchar(225) NOT NULL default '1',
  34. `pet_name` varchar(225) NOT NULL,
  35. `price` varchar(225) NOT NULL,
  36. `birthdate` varchar(225) NOT NULL,
  37. `last_fed` varchar(225) NOT NULL,
  38. `image` varchar(225) NOT NULL,
  39. `max_hp` varchar(225) NOT NULL,
  40. PRIMARY KEY (`id`)
  41. ) ENGINE=MyISAM;
  42.  
  43. -- --------------------------------------------------------
  44.  
  45. CREATE TABLE `user_item` (
  46. `id` int(11) NOT NULL auto_increment,
  47. `owner` varchar(225) NOT NULL,
  48. `name` varchar(225) NOT NULL,
  49. `hp` varchar(225) NOT NULL,
  50. PRIMARY KEY (`id`)
  51. ) ENGINE=MyISAM;
  52.  
  53. -- --------------------------------------------------------
  54.  
  55. CREATE TABLE `user_pet` (
  56. `id` int(11) NOT NULL auto_increment,
  57. `owner` varchar(225) NOT NULL,
  58. `pet_name` varchar(225) NOT NULL,
  59. `name` varchar(225) NOT NULL,
  60. `xp` varchar(225) NOT NULL,
  61. `level` varchar(225) NOT NULL,
  62. `birthdate` varchar(225) NOT NULL,
  63. `hp` varchar(225) NOT NULL,
  64. `last_fed` varchar(225) NOT NULL,
  65. `image` varchar(225) NOT NULL,
  66. PRIMARY KEY (`id`)
  67. ) ENGINE=MyISAM;
  68.  
  69. -- --------------------------------------------------------
  70.  
  71. INSERT INTO `pet_enemy` VALUES (1, 'Evil Teacher', '15', '2', '15', 'https://www.cartooncottage.com/images/teacherboard.gif');
  72.  
  73. -- --------------------------------------------------------
  74.  
  75. INSERT INTO `pet_item` VALUES (1, 'Dog Biscuit', '4', '20');
  76. INSERT INTO `pet_item` VALUES (3, 'Humans (Dragon food)', '4', '20');
  77. INSERT INTO `pet_item` VALUES (4, 'Cat mush', '4', '20');
  78. INSERT INTO `pet_item` VALUES (5, 'Small Humans (Bear food)', '4', '20');
  79.  
  80. -- --------------------------------------------------------
  81.  
  82. INSERT INTO `pet_shop` VALUES (1, 'German Shepard Dog', '10', '0', '1', 'German Shepard Dog', '50', '', '', 'https://www.cartooncottage.com/images/puppybone2.gif', '');
  83. INSERT INTO `pet_shop` VALUES (4, 'Chestnut Grizzly Bear', '10', '0', '1', 'Chestnut Grizzly Bear', '50', '', '', 'https://www.cartooncottage.com/graphics/teddybearitch.gif', '');
  84. INSERT INTO `pet_shop` VALUES (5, 'Red Fire Dragon', '15', '5', '1', 'Red Fire Dragon', '65', '', '', 'https://www.cartooncottage.com/images/reddragon.gif', '');



Now the all important pet_admin.php
PHP Code
  1. <?PHP
  2. session_start();
  3. include "config.php";
  4.  
  5. if($logged[username] && $logged[userlevel] == 6)
  6.  
  7. {
  8.  
  9. switch($_GET[page])
  10.  
  11. {
  12.  
  13. default:
  14. echo("
  15. Welcome to the pet admin page. From here you can add pets, add iteams, edit pets, edit items, delete pets from shop, delete items from shop.
  16. <Br><br>
  17. <a href='?page=addpet'>-Add pet to shop</a><br>
  18. <a href='?page=delpet'>-Delete pet from shop</a><br>
  19. <a href='?page=additem'>-Add item to shop</a><br>
  20. <a href='?page=delitem'>-Delete item from shop</a><br>
  21. <a href='?page=addenemy'>-Add enemy</a><br>
  22. <a href='?page=delenemy'>-Delete enemy</a><br>
  23. ");
  24. break;
  25.  
  26. case'addpet':
  27.  
  28. echo("
  29. <form method='post'>
  30. Pet name:</br>
  31. <input type='text' name='pet_name'><br>
  32. Pet Image (https://www.cartooncottage.com/):</br>
  33. <input type='text' name='image'><br>
  34. Price:</br>
  35. <input type='text' name='price'><br>
  36. <input type='submit' name='submit' value='Add a pet'>
  37. </form>
  38. ");//Form for adding iteam
  39.  
  40. if ($_POST[submit]){
  41. $insert = mysql_query("INSERT INTO `pet_shop` (`name`, `pet_name`, `price`, `image`) VALUES ('$_POST[pet_name]', '$_POST[pet_name]', '$_POST[price]', '$_POST[image]')");
  42. echo("Pet added to shop");//Inserts new item
  43. }
  44. break;
  45.  
  46. case'delpet':
  47. $fetch = mysql_query("SELECT * FROM `pet_shop`");
  48. while ($items = mysql_fetch_array($fetch))
  49. {
  50. echo ("$items[name] - $items[price] credits <a href='?page=delpet2&id=$items[id]'>DELETE</a><br>");
  51. }//Gets all the item so you can pick one to delete
  52. break;
  53.  
  54. case'delpet2':
  55. $update = mysql_query("DELETE FROM `pet_shop` WHERE `id` = '$_GET[id]'");
  56. echo ("Pet deleted. <a href='pet_admin.php'>Back</a>");
  57. break;//Delets iteam (same code all the way down just for diff things)
  58.  
  59.  
  60. case'additem':
  61.  
  62. echo("
  63. <form method='post'>
  64. Item name:</br>
  65. <input type='text' name='pet_name'><br>
  66. HP it adds to pet:</br>
  67. <input type='text' name='hp'><br>
  68. Price:</br>
  69. <input type='text' name='price'><br>
  70. <input type='submit' name='submit' value='Add an item'>
  71. </form>
  72. ");
  73.  
  74. if ($_POST[submit]){
  75. $insert = mysql_query("INSERT INTO `pet_item` (`name`, `hp`, `price`) VALUES ('$_POST[pet_name]', '$_POST[hp]', '$_POST[price]')");
  76. echo("Item added to shop");
  77. }
  78. break;
  79.  
  80. case'delitem':
  81. $fetch = mysql_query("SELECT * FROM `pet_item`");
  82. while ($items = mysql_fetch_array($fetch))
  83. {
  84. echo ("$items[name] - $items[price] credits <a href='?page=delitem2&id=$items[id]'>DELETE</a><br>");
  85. }
  86. break;
  87.  
  88. case'delitem2':
  89. $update = mysql_query("DELETE FROM `pet_item` WHERE `id` = '$_GET[id]'");
  90. echo ("Item deleted. <a href='pet_admin.php'>Back</a>");
  91. break;
  92.  
  93.  
  94.  
  95.  
  96. case'addenemy':
  97.  
  98. echo("
  99. <form method='post'>
  100. Enemy name:</br>
  101. <input type='text' name='name'><br>
  102. HP:</br>
  103. <input type='text' name='hp'><br>
  104. Level:</br>
  105. <input type='text' name='level'><br>
  106. Image:</br>
  107. <input type='text' name='image'><br>
  108. <input type='submit' name='submit' value='Add an Enemy'>
  109. </form>
  110. ");
  111.  
  112. if ($_POST[submit]){
  113. $insert = mysql_query("INSERT INTO `pet_enemy` (`name`, `hp`, `hp_level`, `level`, `image`) VALUES ('$_POST[name]', '$_POST[hp]', '$_POST[hp]','$_POST[level]','$_POST[image]')");
  114. echo("Enemy added");
  115. }
  116. break;
  117.  
  118. case'delenemy':
  119. $fetch = mysql_query("SELECT * FROM `pet_enemy`");
  120. while ($items = mysql_fetch_array($fetch))
  121. {
  122. echo ("$items[name]<a href='?page=delenemy2&id=$items[id]'>DELETE</a><br>");
  123. }
  124. break;
  125.  
  126. case'delenemy2':
  127. $update = mysql_query("DELETE FROM `pet_enemy` WHERE `id` = '$_GET[id]'");
  128. echo ("Enemy deleted. <a href='pet_admin.php'>Back</a>");
  129. break;
  130. }
  131. }
  132. ?>


There you can add/delete pet add/delete foot add/delete enemies

Next up is pet_shop.php

PHP Code
  1. <?php
  2. session_start();
  3. include "pet_config.php";
  4. $date = date("d/m/y");//all config details
  5. if($logged[username])
  6. {
  7. switch($_GET[page])
  8. {
  9. default:
  10. echo ("<a href='?page=pets'>Pets</a> - <a href='?page=petitems'>Pet Items</a>");
  11. break;
  12.  
  13. case 'petitems':
  14. $fetch = mysql_query("SELECT * FROM `pet_item`");
  15. while ($items = mysql_fetch_array($fetch))//Gets all the food from the databse
  16. {
  17. echo ("$items[name] - $items[price] credits - Heals $items[hp] HP - <a href='?page=purchaseitem&id=$items[id]'>Purchase pet item</a><br>");//Food for pets
  18. }
  19. break;
  20.  
  21. case 'pets':
  22. $fetch = mysql_query("SELECT * FROM `pet_shop`");
  23. while ($pet = mysql_fetch_array($fetch))//Gets all the pets from the database
  24. {
  25. echo ("$pet[name] - $pet[price] credits - <a href='?page=purchasepet&id=$pet[id]'>Purchase pet</a><br><img src='$pet[image]'><br>");//Displays pets in database
  26. }
  27. break;
  28.  
  29. case 'purchasepet':
  30. $fetch = mysql_query("SELECT * FROM `pet_shop` WHERE `id` = '$_GET[id]'");
  31. $pet = mysql_fetch_array($fetch);
  32. if($logged[points] < $pet[price])//Purchases pet
  33. {
  34. echo ("Sorry you dont have enough points to purchase a pet.");
  35. }
  36. else
  37. {
  38. $userpoints = $logged[points]-$pet[price];
  39. $insert = mysql_query("INSERT INTO `user_pet` (`owner`, `pet_name`, `name`, `xp`, `level`, `birthdate`, `hp`, `last_fed`, `image`) VALUES ('$logged[username]', '$pet[name]', '$pet[name]', '$pet[xp]', '1', '$date', '$pet[hp]', '$date', '$pet[image]')");
  40. $update = mysql_query("UPDATE `members` SET `points` = '$userpoints' WHERE `username` = '$logged[username]'");//Adds pet to owners account
  41. echo ("Enjoy your new pet. $pet[pet_name]");
  42. }
  43. break;
  44.  
  45. case 'purchaseitem':
  46. $fetch = mysql_query("SELECT * FROM `pet_item` WHERE `id` = '$_GET[id]'");
  47. $items = mysql_fetch_array($fetch);
  48. if($logged[points] < $items[price])//Minuses points for item
  49. {
  50. echo ("Sorry you dont have enough points to purchase a pet.");
  51. }
  52. else
  53. {
  54. $userpoints = $logged[points]-$items[price];
  55. $insert = mysql_query("INSERT INTO `user_item` (`owner`, `name`, `hp`) VALUES ('$logged[username]', '$items[name]', '$items[hp]')");
  56. $update = mysql_query("UPDATE `members` SET `points` = '$userpoints' WHERE `username` = '$logged[username]'");//adds item to user account
  57. echo ("Enjoy your new pet item. $items[name]");
  58. }
  59. break;
  60. }
  61. }
  62. ?>


Now pet_config.php

PHP Code
  1. <?
  2. session_start();
  3. include "config.php";
  4. $fetch = mysql_query("SELECT * FROM `user_pet`");
  5. while ($pets = mysql_fetch_array($fetch))
  6. {
  7. if ($pets[level] = 1 && $pets[hp] >= 11)
  8. {
  9. $update = mysql_query("UPDATE `user_pet` SET `hp` = '10' WHERE `level` = '1'");
  10. }
  11. if ($pets[level] = 2 && $pets[hp] > 12)
  12. {
  13. $update = mysql_query("UPDATE `user_pet` SET `hp` = '12' WHERE `level` = '2'");
  14. }
  15. if ($pets[level] = 3 && $pets[hp] > 15)
  16. {
  17. $update = mysql_query("UPDATE `user_pet` SET `hp` = '15' WHERE `level` = '3'");
  18. }
  19. if ($pets[level] = 4 && $pets[hp] >= 18)
  20. {
  21. $update = mysql_query("UPDATE `user_pet` SET `hp` = '18' WHERE `level` = '4'");
  22. }
  23. if ($pets[level] = 5 && $pets[hp] >= 22)
  24. {
  25. $update = mysql_query("UPDATE `user_pet` SET `hp` = '22' WHERE `level` = '5'");
  26. }
  27. if ($pets[level] = 6 && $pets[hp] >= 26)
  28. {
  29. $update = mysql_query("UPDATE `user_pet` SET `hp` = '26' WHERE `level` = '6'");
  30. }
  31. if ($pets[xp] >= 30)
  32. {
  33. $update = mysql_query("UPDATE `user_pet` SET `level` = '2' WHERE `xp` >= '30'");
  34. }
  35. if ($pets[xp] >= 70)
  36. {
  37. $update = mysql_query("UPDATE `user_pet` SET `level` = '3' WHERE `xp` >= '70'");
  38. }
  39. if ($pets[xp] >= 120)
  40. {
  41. $update = mysql_query("UPDATE `user_pet` SET `level` = '4' WHERE `xp` >= '110'");
  42. }
  43. if ($pets[xp] >= 150)
  44. {
  45. $update = mysql_query("UPDATE `user_pet` SET `level` = '5' WHERE `xp` >= '150'");
  46. }
  47. if ($pets[xp] >= 200)
  48. {
  49. $update = mysql_query("UPDATE `user_pet` SET `level` = '6' WHERE `xp` >= '200'");
  50. }
  51. if ($pets[hp] <= 0)
  52. {
  53. $update = mysql_query("UPDATE `user_pet` SET `hp` = '0' WHERE `hp` < '0'");
  54. }
  55. }
  56. ?>

This code is our control.

PHP Code
  1. if ($pets[level] = 1 && $pets[hp] >= 11)
  2. {
  3. $update = mysql_query("UPDATE `user_pet` SET `hp` = '10' WHERE `level` = '1'");
  4. }

This codes grabs the pets that are level 1 and have hp that is over 10 and change it back to 10 so there is no cheating.

PHP Code
  1. if ($pets[xp] >= 30)
  2. {
  3. $update = mysql_query("UPDATE `user_pet` SET `level` = '2' WHERE `xp` >= '30'");
  4. }

This codes grabs all the pets with xp 30 or over and changes their level to 2.

PHP Code
  1. if ($pets[hp] < 0)
  2. {
  3. $update = mysql_query("UPDATE `user_pet` SET `hp` = '0' WHERE `hp` < '0'");
  4. }

This code grabs the pets with hp less than 0 and puts them at 0.

Next up is my_pets.php
PHP Code
  1. <?php
  2. session_start();
  3. include "pet_config.php";
  4. $date = date("d/m/y");
  5. if($logged[username])
  6. {
  7. switch($_GET[page])
  8. {
  9. default:
  10. $fetch = mysql_query("SELECT * FROM `user_pet` WHERE `owner` = '$logged[username]'");
  11. while ($pets = mysql_fetch_array($fetch))
  12. {
  13. echo ("<a href='?page=viewpet&id=$pets[id]'>$pets[pet_name]</a><br>");
  14. }
  15. break;
  16.  
  17. case 'viewpet':
  18. $items = mysql_query("SELECT * FROM `user_item` WHERE `owner` = '$logged[username]'");
  19. $fetch = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
  20. $pets = mysql_fetch_array($fetch);
  21. echo ("
  22. <img src='$pets[image]' align='right'>
  23. Pets name: $pets[pet_name] - <a href='?page=changepetname&id=$pets[id]'>Change pet name</a> - <a href='?page=changemain&id=$pets[id]'>Set as profile/main pet</a> - <a href='?page=deletepet&id=$pets[id]'>Release Pet</a><br>
  24. Type of pet: $pets[name]<br>
  25. Experience points: $pets[xp]<br>
  26. Hitpoints remaining: $pets[hp]");
  27. $rows = mysql_num_rows($items);
  28. if ($rows <= 0)
  29. {
  30. echo ("<br>");
  31. }
  32. else
  33. {
  34. echo (" - <a href='?page=feedpet&id=$pets[id]'>Feed Pet</a><br>");
  35. }
  36. echo ("
  37. Pet level: $pets[level]<br>
  38. Birthdate: $pets[birthdate]<br>
  39. Last time you fed your pet: $pets[last_fed]<br>
  40. ");
  41. break;
  42.  
  43. case 'changepetname':
  44. $fetch = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
  45. $pets = mysql_fetch_array($fetch);
  46. if($logged[username] !== $pets[owner])
  47. {
  48. die("You can only re-name your own pets");
  49. }
  50. else
  51. {
  52. echo ("<form method='post'>
  53. <input type='text' name='pet_name' value='$pets[pet_name]'><br>
  54. <input type='submit' name='submit' value='Change your pet name'>
  55. </form>
  56. ");
  57. if ($_POST[submit])
  58. {
  59. $update = mysql_query("UPDATE `user_pet` SET `pet_name` = '$_POST[pet_name]' WHERE `id` = '$_GET[id]'");
  60. echo ("Pet name changed.<a href='my_pets.php'>Back</a>");
  61. }
  62. }
  63. break;
  64.  
  65. case 'changemain':
  66. $fetch = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
  67. $pets = mysql_fetch_array($fetch);
  68. if($logged[username] !== $pets[owner])
  69. {
  70. die("This is not your pet.");
  71. }
  72. else
  73. {
  74. $update = mysql_query("UPDATE `members` SET `pet_id` = '$_GET[id]' WHERE `username` = '$logged[username]'");
  75. echo ("Main pet changed changed.<a href='my_pets.php'>Back</a>");
  76. }
  77. break;
  78.  
  79. case 'deletepet':
  80. $fetch = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
  81. $pets = mysql_fetch_array($fetch);
  82. if($logged[username] !== $pets[owner])
  83. {
  84. die("This is not your pet.");
  85. }
  86. else
  87. {
  88. $update = mysql_query("DELETE FROM `user_pet` WHERE `id` = '$_GET[id]'");
  89. echo ("You release $pets[pet_name] into the wild. <a href='my_pets.php'>Back</a>");
  90. }
  91. break;
  92.  
  93. case 'feedpet':
  94. $fetch = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
  95. $pets = mysql_fetch_array($fetch);
  96. if($logged[username] !== $pets[owner])
  97. {
  98. die("This is not your pet.");
  99. }
  100. else
  101. {
  102. echo ("What do you want to feed your pet with?<br>");
  103. $fetch = mysql_query("SELECT * FROM `user_item` WHERE `owner` = '$logged[username]'");
  104. while ($item = mysql_fetch_array($fetch))
  105. {
  106. echo ("<a href='?page=feedpet2&iid=$item[id]&pid=$pets[id]'>$item[name]</a><br>");
  107. }
  108. }
  109. break;
  110.  
  111. case 'feedpet2':
  112. $fetch1 = mysql_query("SELECT * FROM `user_item` WHERE `id` = '$_GET[iid]'");
  113. $item = mysql_fetch_array($fetch1);
  114.  
  115. $fetch2 = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[pid]'");
  116. $pets = mysql_fetch_array($fetch2);
  117. if($logged[username] !== $pets[owner])
  118. {
  119. die("This is not your pet.");
  120. }
  121. else
  122. {
  123. $hp = $pets[hp]+$item[hp];
  124. $update = mysql_query("UPDATE `user_pet` SET `hp` = '$hp', `last_fed` = '$date' WHERE `id` = '$_GET[pid]'");
  125. $delete = mysql_query("DELETE FROM `user_item` WHERE `id` = '$_GET[iid]'");
  126.  
  127. echo ("Your pet $pets[pet_name] now has $hp health. <a href='my_pets.php'>Back</a>");
  128. }
  129. break;
  130. }
  131. }
  132. ?>


Now we have duel.php

PHP Code
  1. <?php
  2. session_start();
  3. include "pet_config.php";
  4. if($logged[username])
  5. {
  6. switch($_GET[page])
  7. {
  8. default:
  9. $fetch = mysql_query("SELECT * FROM `pet_enemy`");
  10. while ($enemy = mysql_fetch_array($fetch))
  11. {
  12. echo ("
  13. Enemy name: <a href='?page=duel&id=$enemy[id]'>$enemy[name]</a><br>
  14. Hitpoints remaining: $enemy[hp]<br>
  15. Pet level: $enemy[level]<br>
  16. <center><hr width='70%'></center>
  17. ");
  18. }
  19. break;
  20.  
  21. case 'duel':
  22. $fetch1 = mysql_query("SELECT * FROM `pet_enemy` WHERE `id` = '$_GET[id]'");
  23. $enemy = mysql_fetch_array($fetch1);
  24.  
  25. $fetch2 = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$logged[pet_id]'");
  26. $pets = mysql_fetch_array($fetch2);
  27.  
  28. if ($enemy[hp] <= 0 && $pets[hp] <= 0)
  29. {
  30. echo ("Sorry you have both killed each other simeltaneously, therefore you receive 0 xp. <a href='my_pets.php'>Home</a>");
  31. $update2 = mysql_query("UPDATE `pet_enemy` SET `hp` = '$enemy[hp_level]' WHERE `id` = '$enemy[id]'");
  32. }
  33. elseif ($enemy[hp] <= 0 && $pets[hp] >= 1)
  34. {
  35. echo ("Congratulations you won. you recieve $enemy[hp_level] xp for winning. <a href='my_pets.php'>Home</a>");
  36. $userxp = $pets[xp]+$enemy[hp_level];
  37. $update1 = mysql_query("UPDATE `user_pet` SET `xp` = '$userxp' WHERE `id` = '$logged[pet_id]'");
  38. $update2 = mysql_query("UPDATE `pet_enemy` SET `hp` = '$enemy[hp_level]' WHERE `id` = '$enemy[id]'");
  39. }
  40. elseif ($enemy[hp] >= 1 && $pets[hp] <= 0)
  41. {
  42. echo ("Sorry you have no HP left. <a href='my_pets.php'>Home</a>");
  43. $update2 = mysql_query("UPDATE `pet_enemy` SET `hp` = '$enemy[hp_level]' WHERE `id` = '$enemy[id]'");
  44. }
  45. else
  46. {
  47. echo ("
  48. <table width='100%'>
  49. <tr>
  50. <td><b>Enemy Stats:</b><br>
  51. Enemy name: $enemy[name]<br>
  52. Hitpoints remaining: $enemy[hp]<br>
  53. Pet level: $enemy[level]<br>
  54. <a href='?page=attack&id=$enemy[id]'>Attack!</a><br>
  55. <img src='$enemy[image]' align='center'></td>
  56. <td><b>My Stats:</b><br>
  57. Name: $pets[pet_name]<br>
  58. Hitpoints remaining: $pets[hp]<br>
  59. Pet level: $pets[level]<br>
  60. <a href='?page=healpet&id=$pets[id]&did=$enemy[id]'>Heal pet</a><br>
  61. <img src='$pets[image]' align='center'></td>
  62. </tr>
  63. </table>
  64. ");
  65. }
  66. break;
  67.  
  68. case 'attack':
  69. $fetch1 = mysql_query("SELECT * FROM `pet_enemy` WHERE `id` = '$_GET[id]'");
  70. $enemy = mysql_fetch_array($fetch1);
  71.  
  72. $fetch2 = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$logged[pet_id]'");
  73. $pets = mysql_fetch_array($fetch2);
  74.  
  75. $random = "012345";
  76. $userattack = substr(str_shuffle($random), 0, 1);
  77. $enemyattack = substr(str_shuffle($random), 0, 1);
  78. echo ("
  79. You hit $enemy[name] with a $userattack<br>
  80. $enemy[name] hits you with a $enemyattack<br>
  81. <a href='?page=duel&id=$enemy[id]'>Back</a>");
  82.  
  83. $userhp = $pets[hp]-$enemyattack;
  84. $enemyhp = $enemy[hp]-$userattack;
  85.  
  86. $update1 = mysql_query("UPDATE `user_pet` SET `hp` = '$userhp' WHERE `id` = '$logged[pet_id]'");
  87. $update2 = mysql_query("UPDATE `pet_enemy` SET `hp` = '$enemyhp' WHERE `id` = '$enemy[id]'");
  88. break;
  89.  
  90.  
  91. case 'healpet':
  92. $fetch = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
  93. $pets = mysql_fetch_array($fetch);
  94. if($logged[username] !== $pets[owner])
  95. {
  96. die("This is not your pet.");
  97. }
  98. else
  99. {
  100. echo ("What do you want to feed your pet with?<br>");
  101. $fetch = mysql_query("SELECT * FROM `user_item` WHERE `owner` = '$logged[username]'");
  102. while ($item = mysql_fetch_array($fetch))
  103. {
  104. echo ("<a href='?page=feed&iid=$item[id]&pid=$pets[id]&did=$_GET[did]'>$item[name]</a><br>");
  105. }
  106. }
  107. break;
  108.  
  109. case 'feed':
  110. $fetch1 = mysql_query("SELECT * FROM `user_item` WHERE `id` = '$_GET[iid]'");
  111. $item = mysql_fetch_array($fetch1);
  112.  
  113. $fetch2 = mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[pid]'");
  114. $pets = mysql_fetch_array($fetch2);
  115. if($logged[username] !== $pets[owner])
  116. {
  117. die("This is not your pet.");
  118. }
  119. else
  120. {
  121. $random = "012345";
  122. $enemyattack = substr(str_shuffle($random), 0, 1);
  123. $hp = $pets[hp]+$item[hp]-$enemyattack;
  124.  
  125. $update = mysql_query("UPDATE `user_pet` SET `hp` = '$hp', `last_fed` = '$date' WHERE `id` = '$_GET[pid]'");
  126. $delete = mysql_query("DELETE FROM `user_item` WHERE `id` = '$_GET[iid]'");
  127. echo ("Your pet $pets[pet_name] now has $hp health. But you have been hit with a $enemyattack <a href='duel.php?page=duel&id=$_GET[did]'>Back</a>");
  128. }
  129. break;
  130. }
  131. }
  132. ?>



So there it is Hope you like it i know its not brilliant commented but if you dont understand a bit of code copy the bit paste it into comment box say "I dond get this bit" and we will explain.

Credit to SkillMaster as well he did the basics of the code and so on.
Peace out
MOD-Dan's Avatar
Author:
Views:
3,459
Rating:
Posted on Saturday 1st November 2008 at 01:05 AM
jambomb
jambomb's Avatar
also remember to set your pet as main pet in my_pets :)
Posted on Saturday 1st November 2008 at 12:30 AM
MOD-Dan
MOD-Dan's Avatar
Yeah thats because its hit points not health :P
Posted on Monday 18th August 2008 at 07:17 PM
UrbanTwitch
UrbanTwitch's Avatar
I get when I try to duel someone: Sorry you have no HP left. Home

I got to phpMyAdmin and see my health is at 10!
Posted on Thursday 24th July 2008 at 03:08 AM
ShadowMage
ShadowMage's Avatar
Fail...
Posted on Thursday 24th July 2008 at 01:47 AM
UrbanTwitch
UrbanTwitch's Avatar
Whoops, nvm. I wasn't logged in. xD
Posted on Thursday 24th July 2008 at 01:45 AM
UrbanTwitch
UrbanTwitch's Avatar
I am GETTING BLANK PAGES WHEN IM LOGGED IN AS ADMIN!!! :(
Posted on Wednesday 23rd July 2008 at 04:11 AM
UrbanTwitch
UrbanTwitch's Avatar
I'd rather have us: oursleves the users fighting and gain xp for hits and show hiscore!
Posted on Thursday 29th May 2008 at 02:57 PM
jambomb
jambomb's Avatar
My pet_shop.php shows a blank page? can some 1 help me :)
Posted on Monday 7th April 2008 at 07:16 PM
DanielXP
DanielXP's Avatar
Thats what the duel.php is for Dalez?
Posted on Monday 7th April 2008 at 05:49 PM
Dalez
Dalez's Avatar
Nice, but i would like it so that you could battle other people who are registered :P

So PvP pet fighting :) If possible..