[php] Cooking system (solved)
Posted: Mon Jun 20, 2011 12:36 am
I have been building a cooking system and it is almost finished except I don't know how I would add the cooked item to the inventory.
My problem is that so far I have been adding generic items that are all the same, but when someone cooks something the health bonus can be different based on how it was cooked, what it was cooked with, etc.
I am not sure how to approach this. I made a table called crafted_foods and when a food is made I add all its stats to that table. My plan was to draw from that like I would when someone received an item from mining or harvesting and then insert it into the inventory. My problem is that with the items not having an id number until they are created, I do not know how to put them in the inventory.
I know that probably does not make sense so let me try and describe it with code.
When an item is successfully cooked I first run this:
crafted_food is an empty table that only has items someone has cooked in it. The id for this table is just an auto increment int, which is why the item will not have an id until it is created.
My plan for getting it into the inventory was to have this right after the above query:
The problem is that I don't have an item_id to use to keep track of it with since all ids are created when the item is created.
Does this make sense? How can I make the items distinguishable if I do not have an id? Is there a better way to do this? Is it something simple I am not seeing?
Thanks for any help.
My problem is that so far I have been adding generic items that are all the same, but when someone cooks something the health bonus can be different based on how it was cooked, what it was cooked with, etc.
I am not sure how to approach this. I made a table called crafted_foods and when a food is made I add all its stats to that table. My plan was to draw from that like I would when someone received an item from mining or harvesting and then insert it into the inventory. My problem is that with the items not having an id number until they are created, I do not know how to put them in the inventory.
I know that probably does not make sense so let me try and describe it with code.
When an item is successfully cooked I first run this:
Code: Select all
$SQL1 = "INSERT into crafted_food(owner, name, class, energy, health, value, randid) VALUES ('$player', 'cooked food', 'crafted_food', '$stataddenergy', '$stataddhp', '$value', '$randid1')";
mysql_query($SQL1) or die("could not add to crafted foods"); My plan for getting it into the inventory was to have this right after the above query:
Code: Select all
$SQL2 = "INSERT into inventory(id, name, class, item_id, randid) VALUES ('$player','$name','crafted_food', '$item_id', '$randid2')";
mysql_query($SQL2) or die("could not add to inventory"); Does this make sense? How can I make the items distinguishable if I do not have an id? Is there a better way to do this? Is it something simple I am not seeing?
Thanks for any help.