Forgot Password / Register
Site Statistics
Total Members: 520
Total Tutorials: 242
Newsest User: 8884244477
Todays Unique Hits: 335
0 Users 4 Guests Online

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?

Code


ALTER TABLE `members` ADD `pet_id` VARCHAR( 225 ) NOT NULL default '0';

-- --------------------------------------------------------

CREATE TABLE `pet_enemy` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(225) NOT NULL,
`hp` varchar(225) NOT NULL,
`level` varchar(225) NOT NULL,
`hp_level` varchar(225) NOT NULL,
`image` varchar(225) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

-- --------------------------------------------------------

CREATE TABLE `pet_item` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(225) NOT NULL,
`hp` varchar(225) NOT NULL,
`price` varchar(225) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

-- --------------------------------------------------------

CREATE TABLE `pet_shop` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(225) NOT NULL,
`hp` varchar(225) NOT NULL default '10',
`xp` varchar(225) NOT NULL default '0',
`level` varchar(225) NOT NULL default '1',
`pet_name` varchar(225) NOT NULL,
`price` varchar(225) NOT NULL,
`birthdate` varchar(225) NOT NULL,
`last_fed` varchar(225) NOT NULL,
`image` varchar(225) NOT NULL,
`max_hp` varchar(225) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

-- --------------------------------------------------------

CREATE TABLE `user_item` (
`id` int(11) NOT NULL auto_increment,
`owner` varchar(225) NOT NULL,
`name` varchar(225) NOT NULL,
`hp` varchar(225) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

-- --------------------------------------------------------

CREATE TABLE `user_pet` (
`id` int(11) NOT NULL auto_increment,
`owner` varchar(225) NOT NULL,
`pet_name` varchar(225) NOT NULL,
`name` varchar(225) NOT NULL,
`xp` varchar(225) NOT NULL,
`level` varchar(225) NOT NULL,
`birthdate` varchar(225) NOT NULL,
`hp` varchar(225) NOT NULL,
`last_fed` varchar(225) NOT NULL,
`image` varchar(225) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM;

-- --------------------------------------------------------

INSERT INTO `pet_enemy` VALUES (1, 'Evil Teacher', '15', '2', '15', 'http://www.cartooncottage.com/images/teacherboard.gif');

-- --------------------------------------------------------

INSERT INTO `pet_item` VALUES (1, 'Dog Biscuit', '4', '20');
INSERT INTO `pet_item` VALUES (3, 'Humans (Dragon food)', '4', '20');
INSERT INTO `pet_item` VALUES (4, 'Cat mush', '4', '20');
INSERT INTO `pet_item` VALUES (5, 'Small Humans (Bear food)', '4', '20');

-- --------------------------------------------------------

INSERT INTO `pet_shop` VALUES (1, 'German Shepard Dog', '10', '0', '1', 'German Shepard Dog', '50', '', '', 'http://www.cartooncottage.com/images/puppybone2.gif', '');
INSERT INTO `pet_shop` VALUES (4, 'Chestnut Grizzly Bear', '10', '0', '1', 'Chestnut Grizzly Bear', '50', '', '', 'http://www.cartooncottage.com/graphics/teddybearitch.gif', '');
INSERT INTO `pet_shop` VALUES (5, 'Red Fire Dragon', '15', '5', '1', 'Red Fire Dragon', '65', '', '', 'http://www.cartooncottage.com/images/reddragon.gif', '');



Now the all important pet_admin.php
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?PHP
session_start
();
include 
"config.php";

if(
$logged[username] && $logged[userlevel] == 6)

{

switch(
$_GET[page])

{

default:
echo(
"
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.
<Br><br>
<a href='?page=addpet'>-Add pet to shop</a><br>
<a href='?page=delpet'>-Delete pet from shop</a><br>
<a href='?page=additem'>-Add item to shop</a><br>
<a href='?page=delitem'>-Delete item from shop</a><br>
<a href='?page=addenemy'>-Add enemy</a><br>
<a href='?page=delenemy'>-Delete enemy</a><br>
"
);
break;

case
'addpet':

echo(
"
<form method='post'>
Pet name:</br>
<input type='text' name='pet_name'><br>
Pet Image (http://www.cartooncottage.com/):</br>
<input type='text' name='image'><br>
Price:</br>
<input type='text' name='price'><br>
<input type='submit' name='submit' value='Add a pet'>
</form>
"
);//Form for adding iteam

if ($_POST[submit]){
$insert mysql_query("INSERT INTO `pet_shop` (`name`, `pet_name`, `price`, `image`) VALUES ('$_POST[pet_name]', '$_POST[pet_name]', '$_POST[price]', '$_POST[image]')");
echo(
"Pet added to shop");//Inserts new item
}
break;

case
'delpet':
$fetch mysql_query("SELECT * FROM `pet_shop`");
while (
$items mysql_fetch_array($fetch))
{
echo (
"$items[name] - $items[price] credits <a href='?page=delpet2&id=$items[id]'>DELETE</a><br>");
}
//Gets all the item so you can pick one to delete
break;

case
'delpet2':
$update mysql_query("DELETE FROM `pet_shop` WHERE `id` = '$_GET[id]'");
echo (
"Pet deleted. <a href='pet_admin.php'>Back</a>");
break;
//Delets iteam (same code all the way down just for diff things)


case'additem':

echo(
"
<form method='post'>
Item name:</br>
<input type='text' name='pet_name'><br>
HP it adds to pet:</br>
<input type='text' name='hp'><br>
Price:</br>
<input type='text' name='price'><br>
<input type='submit' name='submit' value='Add an item'>
</form>
"
);

if (
$_POST[submit]){
$insert mysql_query("INSERT INTO `pet_item` (`name`, `hp`, `price`) VALUES ('$_POST[pet_name]', '$_POST[hp]', '$_POST[price]')");
echo(
"Item added to shop");
}
break;

case
'delitem':
$fetch mysql_query("SELECT * FROM `pet_item`");
while (
$items mysql_fetch_array($fetch))
{
echo (
"$items[name] - $items[price] credits <a href='?page=delitem2&id=$items[id]'>DELETE</a><br>");
}
break;

case
'delitem2':
$update mysql_query("DELETE FROM `pet_item` WHERE `id` = '$_GET[id]'");
echo (
"Item deleted. <a href='pet_admin.php'>Back</a>");
break;




case
'addenemy':

echo(
"
<form method='post'>
Enemy name:</br>
<input type='text' name='name'><br>
HP:</br>
<input type='text' name='hp'><br>
Level:</br>
<input type='text' name='level'><br>
Image:</br>
<input type='text' name='image'><br>
<input type='submit' name='submit' value='Add an Enemy'>
</form>
"
);

if (
$_POST[submit]){
$insert mysql_query("INSERT INTO `pet_enemy` (`name`, `hp`, `hp_level`, `level`, `image`) VALUES ('$_POST[name]', '$_POST[hp]', '$_POST[hp]','$_POST[level]','$_POST[image]')");
echo(
"Enemy added");
}
break;

case
'delenemy':
$fetch mysql_query("SELECT * FROM `pet_enemy`");
while (
$items mysql_fetch_array($fetch))
{
echo (
"$items[name]<a href='?page=delenemy2&id=$items[id]'>DELETE</a><br>");
}
break;

case
'delenemy2':
$update mysql_query("DELETE FROM `pet_enemy` WHERE `id` = '$_GET[id]'");
echo (
"Enemy deleted. <a href='pet_admin.php'>Back</a>");
break;
}
}
?>


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

Next up is pet_shop.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
session_start
();
include 
"pet_config.php";
$date date("d/m/y");//all config details
if($logged[username])
{
switch(
$_GET[page])
{
default:
echo (
"<a href='?page=pets'>Pets</a> - <a href='?page=petitems'>Pet Items</a>");
break;

case 
'petitems':
$fetch mysql_query("SELECT * FROM `pet_item`");
while (
$items mysql_fetch_array($fetch))//Gets all the food from the databse
{
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
}
break;

case 
'pets':
$fetch mysql_query("SELECT * FROM `pet_shop`");
while (
$pet mysql_fetch_array($fetch))//Gets all the pets from the database
{
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
}
break;

case 
'purchasepet':
$fetch mysql_query("SELECT * FROM `pet_shop` WHERE `id` = '$_GET[id]'");
$pet mysql_fetch_array($fetch);
if(
$logged[points] < $pet[price])//Purchases pet
{
echo (
"Sorry you dont have enough points to purchase a pet.");
}
else
{
$userpoints $logged[points]-$pet[price];
$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]')");
$update mysql_query("UPDATE `members` SET `points` = '$userpoints' WHERE `username` = '$logged[username]'");//Adds pet to owners account
echo ("Enjoy your new pet. $pet[pet_name]");
}
break;

case 
'purchaseitem':
$fetch mysql_query("SELECT * FROM `pet_item` WHERE `id` = '$_GET[id]'");
$items mysql_fetch_array($fetch);
if(
$logged[points] < $items[price])//Minuses points for item
{
echo (
"Sorry you dont have enough points to purchase a pet.");
}
else
{
$userpoints $logged[points]-$items[price];
$insert mysql_query("INSERT INTO `user_item` (`owner`, `name`, `hp`) VALUES ('$logged[username]', '$items[name]', '$items[hp]')");
$update mysql_query("UPDATE `members` SET `points` = '$userpoints' WHERE `username` = '$logged[username]'");//adds item to user account
echo ("Enjoy your new pet item. $items[name]");
}
break;
}
}
?>


Now pet_config.php

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

This code is our control.

Code

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

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.

Code

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

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

Code

if ($pets[hp] < 0)
{
$update = mysql_query("UPDATE `user_pet` SET `hp` = '0' WHERE `hp` < '0'");
}

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

Next up is my_pets.php
PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
session_start
();
include 
"pet_config.php";
$date date("d/m/y");
if(
$logged[username])
{
switch(
$_GET[page])
{
default:
$fetch mysql_query("SELECT * FROM `user_pet` WHERE `owner` = '$logged[username]'");
while (
$pets mysql_fetch_array($fetch))
{
echo (
"<a href='?page=viewpet&id=$pets[id]'>$pets[pet_name]</a><br>");
}
break;

case 
'viewpet':
$items mysql_query("SELECT * FROM `user_item` WHERE `owner` = '$logged[username]'");
$fetch mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
$pets mysql_fetch_array($fetch);
echo (
"
<img src='
$pets[image]' align='right'>
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>
Type of pet: 
$pets[name]<br>
Experience points: 
$pets[xp]<br>
Hitpoints remaining: 
$pets[hp]");
$rows mysql_num_rows($items);
if (
$rows <= 0)
{
echo (
"<br>");
}
else
{
echo (
" - <a href='?page=feedpet&id=$pets[id]'>Feed Pet</a><br>");
}
echo (
"
Pet level: 
$pets[level]<br>
Birthdate: 
$pets[birthdate]<br>
Last time you fed your pet: 
$pets[last_fed]<br>
"
);
break;

case 
'changepetname':
$fetch mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
$pets mysql_fetch_array($fetch);
if(
$logged[username] !== $pets[owner])
{
die(
"You can only re-name your own pets");
}
else
{
echo (
"<form method='post'>
<input type='text' name='pet_name' value='
$pets[pet_name]'><br>
<input type='submit' name='submit' value='Change your pet name'>
</form>
"
);
if (
$_POST[submit])
{
$update mysql_query("UPDATE `user_pet` SET `pet_name` = '$_POST[pet_name]' WHERE `id` = '$_GET[id]'");
echo (
"Pet name changed.<a href='my_pets.php'>Back</a>");
}
}
break;

case 
'changemain':
$fetch mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
$pets mysql_fetch_array($fetch);
if(
$logged[username] !== $pets[owner])
{
die(
"This is not your pet.");
}
else
{
$update mysql_query("UPDATE `members` SET `pet_id` = '$_GET[id]' WHERE `username` = '$logged[username]'");
echo (
"Main pet changed changed.<a href='my_pets.php'>Back</a>");
}
break;

case 
'deletepet':
$fetch mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
$pets mysql_fetch_array($fetch);
if(
$logged[username] !== $pets[owner])
{
die(
"This is not your pet.");
}
else
{
$update mysql_query("DELETE FROM `user_pet` WHERE `id` = '$_GET[id]'");
echo (
"You release $pets[pet_name] into the wild. <a href='my_pets.php'>Back</a>");
}
break;

case 
'feedpet':
$fetch mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
$pets mysql_fetch_array($fetch);
if(
$logged[username] !== $pets[owner])
{
die(
"This is not your pet.");
}
else
{
echo (
"What do you want to feed your pet with?<br>");
$fetch mysql_query("SELECT * FROM `user_item` WHERE `owner` = '$logged[username]'");
while (
$item mysql_fetch_array($fetch))
{
echo (
"<a href='?page=feedpet2&iid=$item[id]&pid=$pets[id]'>$item[name]</a><br>");
}
}
break;

case 
'feedpet2':
$fetch1 mysql_query("SELECT * FROM `user_item` WHERE `id` = '$_GET[iid]'");
$item mysql_fetch_array($fetch1);

$fetch2 mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[pid]'");
$pets mysql_fetch_array($fetch2);
if(
$logged[username] !== $pets[owner])
{
die(
"This is not your pet.");
}
else
{
$hp $pets[hp]+$item[hp];
$update mysql_query("UPDATE `user_pet` SET `hp` = '$hp', `last_fed` = '$date' WHERE `id` = '$_GET[pid]'");
$delete mysql_query("DELETE FROM `user_item` WHERE `id` = '$_GET[iid]'");

echo (
"Your pet $pets[pet_name] now has $hp health. <a href='my_pets.php'>Back</a>");
}
break;
}
}
?>


Now we have duel.php

PHP Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
session_start
();
include 
"pet_config.php";
if(
$logged[username])
{
switch(
$_GET[page])
{
default:
$fetch mysql_query("SELECT * FROM `pet_enemy`");
while (
$enemy mysql_fetch_array($fetch))
{
echo (
"
Enemy name: <a href='?page=duel&id=
$enemy[id]'>$enemy[name]</a><br>
Hitpoints remaining: 
$enemy[hp]<br>
Pet level: 
$enemy[level]<br>
<center><hr width='70%'></center>
"
);
}
break;

case 
'duel':
$fetch1 mysql_query("SELECT * FROM `pet_enemy` WHERE `id` = '$_GET[id]'");
$enemy mysql_fetch_array($fetch1);

$fetch2 mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$logged[pet_id]'");
$pets mysql_fetch_array($fetch2);

if (
$enemy[hp] <= && $pets[hp] <= 0)
{
echo (
"Sorry you have both killed each other simeltaneously, therefore you receive 0 xp. <a href='my_pets.php'>Home</a>");
$update2 mysql_query("UPDATE `pet_enemy` SET `hp` = '$enemy[hp_level]' WHERE `id` = '$enemy[id]'");
}
elseif (
$enemy[hp] <= && $pets[hp] >= 1)
{
echo (
"Congratulations you won. you recieve $enemy[hp_level] xp for winning. <a href='my_pets.php'>Home</a>");
$userxp $pets[xp]+$enemy[hp_level];
$update1 mysql_query("UPDATE `user_pet` SET `xp` = '$userxp' WHERE `id` = '$logged[pet_id]'");
$update2 mysql_query("UPDATE `pet_enemy` SET `hp` = '$enemy[hp_level]' WHERE `id` = '$enemy[id]'");
}
elseif (
$enemy[hp] >= && $pets[hp] <= 0)
{
echo (
"Sorry you have no HP left. <a href='my_pets.php'>Home</a>");
$update2 mysql_query("UPDATE `pet_enemy` SET `hp` = '$enemy[hp_level]' WHERE `id` = '$enemy[id]'");
}
else
{
echo (
"
<table width='100%'>
<tr>
<td><b>Enemy Stats:</b><br>
Enemy name: 
$enemy[name]<br>
Hitpoints remaining: 
$enemy[hp]<br>
Pet level: 
$enemy[level]<br>
<a href='?page=attack&id=
$enemy[id]'>Attack!</a><br>
<img src='
$enemy[image]' align='center'></td>
<td><b>My Stats:</b><br>
Name: 
$pets[pet_name]<br>
Hitpoints remaining: 
$pets[hp]<br>
Pet level: 
$pets[level]<br>
<a href='?page=healpet&id=
$pets[id]&did=$enemy[id]'>Heal pet</a><br>
<img src='
$pets[image]' align='center'></td>
</tr>
</table>
"
);
}
break;

case 
'attack':
$fetch1 mysql_query("SELECT * FROM `pet_enemy` WHERE `id` = '$_GET[id]'");
$enemy mysql_fetch_array($fetch1);

$fetch2 mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$logged[pet_id]'");
$pets mysql_fetch_array($fetch2);

$random "012345";
$userattack substr(str_shuffle($random), 01);
$enemyattack substr(str_shuffle($random), 01);
echo (
"
You hit 
$enemy[name] with a $userattack<br>
$enemy[name] hits you with a $enemyattack<br>
<a href='?page=duel&id=
$enemy[id]'>Back</a>");

$userhp $pets[hp]-$enemyattack;
$enemyhp $enemy[hp]-$userattack;

$update1 mysql_query("UPDATE `user_pet` SET `hp` = '$userhp' WHERE `id` = '$logged[pet_id]'");
$update2 mysql_query("UPDATE `pet_enemy` SET `hp` = '$enemyhp' WHERE `id` = '$enemy[id]'");
break;


case 
'healpet':
$fetch mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[id]'");
$pets mysql_fetch_array($fetch);
if(
$logged[username] !== $pets[owner])
{
die(
"This is not your pet.");
}
else
{
echo (
"What do you want to feed your pet with?<br>");
$fetch mysql_query("SELECT * FROM `user_item` WHERE `owner` = '$logged[username]'");
while (
$item mysql_fetch_array($fetch))
{
echo (
"<a href='?page=feed&iid=$item[id]&pid=$pets[id]&did=$_GET[did]'>$item[name]</a><br>");
}
}
break;

case 
'feed':
$fetch1 mysql_query("SELECT * FROM `user_item` WHERE `id` = '$_GET[iid]'");
$item mysql_fetch_array($fetch1);

$fetch2 mysql_query("SELECT * FROM `user_pet` WHERE `id` = '$_GET[pid]'");
$pets mysql_fetch_array($fetch2);
if(
$logged[username] !== $pets[owner])
{
die(
"This is not your pet.");
}
else
{
$random "012345";
$enemyattack substr(str_shuffle($random), 01);
$hp $pets[hp]+$item[hp]-$enemyattack;

$update mysql_query("UPDATE `user_pet` SET `hp` = '$hp', `last_fed` = '$date' WHERE `id` = '$_GET[pid]'");
$delete mysql_query("DELETE FROM `user_item` WHERE `id` = '$_GET[iid]'");
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>");
}
break;
}
}
?>



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
Author:
Views:
3186
Rating:
Posted on Saturday 1st November 2008 at 01:05 AM
jambomb
jambomb
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
Yeah thats because its hit points not health :P
Posted on Monday 18th August 2008 at 07:17 PM
UrbanTwitch
UrbanTwitch
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
Fail...
Posted on Thursday 24th July 2008 at 01:47 AM
UrbanTwitch
UrbanTwitch
Whoops, nvm. I wasn't logged in. xD
Posted on Thursday 24th July 2008 at 01:45 AM
UrbanTwitch
UrbanTwitch
I am GETTING BLANK PAGES WHEN IM LOGGED IN AS ADMIN!!! :(
Posted on Wednesday 23rd July 2008 at 04:11 AM
UrbanTwitch
UrbanTwitch
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
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
Thats what the duel.php is for Dalez?
Posted on Monday 7th April 2008 at 05:49 PM
Dalez
Dalez
Nice, but i would like it so that you could battle other people who are registered :P

So PvP pet fighting :) If possible..