PDA

View Full Version : Item & Health Integration


Ashje
07-09-2009, 04:36 AM
http://buildingbrowsergames.com/tutorials/
On the above site is a tutorial for how to use PHP and SQL to make a browser game (including health and items that heal you). Would anybody know how to integrate this with the adoptables script?

Seapyramid
07-09-2009, 10:38 AM
I just finished a mod yesterday for usable items. It includes items for leveling, healing, resurrection, changing a reg pet to it's alt version & "breeding". Doing it required the addition of 2 new tables & adding fields to existing tables. There were 3 new pages created, many pages altered and major additions to the admin panel. It is currently running on the test server. Taking it live will require not only making all the above changes to the current database and uploading all the new or changed pages, but also then making changes to ALL the existing pets in the database.

Since usable items are designed very specific to the needs of the site and every item must be coded separately to work as it is supposed to work. I do not foresee a "general" mod being created because for it to be general enough for all sites to use everyone would want it modified in some way. Plus the changes needed in the database to the current pets would require a system simular to the one Brandon created for upgrading to the newest script as most of the people here would find making the changes manually well beyond their abilities.

I can only recommend a lot of reading and learning or making good friends with a programmer to do it for you, because hiring someone to design the system for your site would be expensive with all the time involved.

Sea

Ashje
07-09-2009, 10:48 PM
Oh, alright then. Could you give me some hints to just getting started on a basic health system, because I haven't upgraded my site anyway and I was planning on making a new site, so I can start from the beginning...

Seapyramid
07-09-2009, 11:47 PM
Add a health field to your owned_adoptables table.. make it not null & give it a start point.. Mystic Grove start is 20

on another page for items this was added

/* ****************
Healing Spell
***************** */
} elseif ($do == "Healing") {
// We are actually placing in or removing from Dorm...


$article_title = "Healing Potion<br /><br />";
$article_content = "<center><img src='" . $itemimage . "'></center><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; With war comes valor, but also injuries and even death! The Healing Potion can not bring the dead back to life but it can help to sooth the pain and heal the injuries of those wounded in the Goodly Battle. The Healing Potion will help you Companion to recover from it's wounds up to 5 days sooner then what would happen naturally with time. It is useable only once and then it will disappear.<br /><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Which companion would you like to use the " . $type . " Potion on?<br /><br />";

$article_content = $article_content . "<div id='petdisplay' align='center'> <ul>";
// Now we choose a Companion or Item to use it on...


$query = "SELECT * FROM " . $prefix . "owned_adoptables WHERE owner='$loggedinname' AND health < '20' AND health != '0' AND currentlevel = '6' AND item != 'yes'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$i = 0;
while ($i < $num) {
//The item's ID
$aid = @mysql_result($result, $i, "aid");
$name = @mysql_result($result, $i, "name");
$health = @mysql_result($result, $i, "health");



// Get the image for the adopt...
$itemimage = getcurrentitemimage($id);
$image = getcurrentimage($aid);

$go = $name . "<a href='useitem.php?act=Healing&id=" . $id . "&aid=" . $aid . "'><img src='" . $image . "' border=0></a><b>Health: " . $health . "/20 ";
//Loop out code



$article_content = $article_content . "<li><h5><center>" . $go . " </center></h5></li>";


$i++;
}
$article_content = $article_content . "</ul></div><br /><div></div>";


which sent info to another page.. this code


/* ****************
Healing Potion
***************** */

if ($isloggedin == "yes") {
if ($act == "Healing") {
if ($id == "" or !is_numeric($id)) {
$article_title = $err_idnoexist;
$article_content = $err_idnoexist_text;
} else {
$query = "DELETE FROM `adopts_owned_items` WHERE `aid`='$id'";
$result = mysql_query($query);
// die(print_r($query));

// We have what appears to be a valid adoptable ID, so we pull the adoptable's information from the database...

$query = "SELECT * FROM " . $prefix . "owned_adoptables WHERE aid='$aid'";
$result = mysql_query($query);
$num = mysql_numrows($result);

//Loop out code
$i = 0;
while ($i < 1) {
$aid = @mysql_result($result, $i, "aid");
$name = @mysql_result($result, $i, "name");
$owner = @mysql_result($result, $i, "owner");
$health = @mysql_result($result, $i, "health");
$i++;
}

if ($health < "20") {
// Now we see if the adoptable is dead. If it is, we do not heal...

if ($health == "0") {
$article_title = "This Companion is DEAD!";
$article_content = "<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This Companion has died and is well beyound the abilities of this Healing Potion!";
} else {
// Add health points to the total health of this adoptable...
$newhealth = $health + 5;

// Actually insert our health information into the database...

$query = "UPDATE " . $prefix . "owned_adoptables SET health='" . $newhealth . "' WHERE aid='" . $aid . "'";
mysql_query($query);


// End the if statement of healing
$image = getcurrentimage($aid);
$itemimage = getcurrentitemimage($id);

$article_title = "Healing Potion";
$article_content = "<br /><br /><center><img src=" . $image . "><br /><br />The Healing Potion has eased " . $name . "'s pain and brought it's health up to " . $newhealth . "/20 !</center>";
}
} else {
// Adoptable is invalid, show an error...

$article_title = $err_idnoexist;
$article_content = $err_idnoexist_text;
}
}
}
}



to make it finally work & that is just the basic healing.

Sea

Ashje
07-10-2009, 04:54 AM
And I add an items table as well? You are amazing, Thanks so much XD

EDIT:

What fields do I put in the items table and what settings do they have?

Seapyramid
07-10-2009, 09:27 AM
It is not just that easy, you also have to edit the my doadopt.php page to account for the health field. You will need some way for your users to make coin if you want them to actually pay for the items. The fields in the items table will depend on how you want the items to work. You will need to edit your admin.php so that you can add items in. All I did was give you a starting point.

Sea

Ashje
07-10-2009, 06:29 PM
I'm working on the shop mod for myself seeing as yours is donator only. I'm trying to convert Kisazeky's script. Thank you for the starting point, I really appreciate it. XD

Bloodrun
07-14-2009, 09:34 AM
Careful Ashje, other scripts, especially those not done by professionals, may look like they incorporate nicely, but just pile up errors, and problems, that you will receive later on down the road.

Just a heads up mate.

Ashje
07-14-2009, 10:46 PM
Thanks for the heads up XD

Seapyramid
10-08-2009, 12:55 PM
That is really great that including a health and items that can heal. so how to trace the error on some part on users to make coin if you want them to actually pay for the items?


_________________
Travel insurance quote (http://www.mnui.com/quotes.asp)


??? What?? This is NOT a working mod, just some ideas for someone who was trying to make their own. What you are asking makes no sense unless you have tried to just use these examples as a working mod & in that case you would have many errors.

Sea

Bloodrun
10-08-2009, 01:09 PM
That is really great that including a health and items that can heal. so how to trace the error on some part on users to make coin if you want them to actually pay for the items?


_________________
Travel insurance quote (http://www.mnui.com/quotes.asp)


??? What?? This is NOT a working mod, just some ideas for someone who was trying to make their own. What you are asking makes no sense unless you have tried to just use these examples as a working mod & in that case you would have many errors.

Sea


Don't reply to them. They've been popping around the forum here and there. I would have taken care of this already but I don't have Moderation Access in this forum.