Jump to content

Non linear storage question.


cooldude832

Recommended Posts

I'm trying to make a game.  A module for this game will be a quest feature, in which I can define random quest each day for you to fulfill.  Such as defeat X things, or take item A to Location this.  My idea is to assign a limited number of quest to distribute each day (as a promotion to get people on my game as they never know when a quest will appear as it is handled by cron, the creation that is).  My problem is this.  My quest have no logical bearing to the data storage between quest of killing stuff and Taking stuff somewhere.  My idea was to make a few generic tables like a Kill X things table, a Take This to point B table etc that I could handle much easier, trying to store in a single table.

I think this can be easily handled given each opponent and character/location is defined  (well the opponents type are, the individuals are not), so I would just need to define my quest saying Item to take = Item Type 1093245 and Person to =  345890543.  and then I have some sort of trigger where if you initialize talk with them it be like Give person 345890543 Item 1093245? and it would handle this. 

 

Any ideas on if this sounds pheasable, or an easier way?

Link to comment
Share on other sites

Well, here's my take.

 

Define your scenarios:

 

Take item A to Person B

Kill X of Monster A and report back to Person B

 

Then, just do a random number generator that will randomly pick a scenario to define random values for.

 

So if I randomly pick item A to Person B scenario, you would have a database of all items, and a database of all people. Randomly pick a row out of each table (under certain limitations I assume, like item price or type of person), combine them together, place in a new row in a table, then just have a check to see if a quest exists for that person etc... IE: quest type=1 and so on..

 

Quest Table:

Item A|X Amount|Monster A|Person B|Scenario Number (contains all variables for all scenarios, combined, the union of..)

 

Then you just look up scenario number, grab the variables you need, and do w/e...

 

I kinda like the idea of this method, it would allow you to add new quests easily, without any hard or major coding.

Link to comment
Share on other sites

except I will have more than 2 quest types, meaning I don't want to have a bunch of wasted table space when only 1/10th of the fields would be used.  I think I will just have to make each quest type a table + a centralized database that will contain all the repeated data, linking with the centralized key.  I was thinking along the lines of expanding the table as be, but I just don't think it will be a smart idea to have a 100 field table and only be using 5-10 of them.

Link to comment
Share on other sites

How about shifting the quests over to the flat-file first?

 

IE: that's a lot of queries. Stick all the active, on-going quests into a flat-file, and only save them into the database if they have been completed. This COULD reduce the number of queries sent back and forth between the user and the database. It depends though, the idea of applicability. Does it matter, back-end or front-end if you use flat-files or database?

 

I'm sure front-end may see some speed boosts, but back-end would definitely see some efficiency if we used flat-files and moved over to database when needed.

Link to comment
Share on other sites

I have come to this conclusion

 

A) I need to define each quest type as its own table

B) I need a centralized table  of quest with fields like QuestID, NumbertoRelease, TimeOpen, TimeClose, Timelimit Reward, QuestType

C) Individual tables that define the QuestType of table listed in B

D) A third table that defines, User 12345 accepted quest 123 at Time

 

Then I need to define some functions for each of the tables in D, like in a kill X of Y things, I need to draw data of my battle table that says select count(*) from `Battles` Where UserID = '".$userid."' and Time >'".$quest_start."' and $Time < '">$quest_end'"";

My issue with this is in a battle you can battle anywhere from 1-4 opponents, and so 1 row could have 2 "wolves", I think it will be easier to query it each time, than update a count.  My issue is I need to count only the Oppoent1, opponent2, opponet3, oppoent4 files that equal the given opponent type.  Any Ideas?

Link to comment
Share on other sites

Why not, in the quest table, have a column labeled "enemy" and another column labeled "tokill" and then "killcount" such that "tokill" contains the number you have to kill, "killcount" is how many has been killed, and "enemy" is what you have to kill...

 

I'm not quite clear what your vision of the database tables would look like.. Perhaps illustrate some?

Link to comment
Share on other sites

I think i get it. But as above the quest table flat bed with a field of type of quest

 

Each compeditor has his own table with

pointer to A quest

Number to be killed STILL

completed booll

 

The next quest can't be atempted untill the last is completed.

Each task table will be generated with a mixture of tasks and kills.

 

Desmond.

 

Link to comment
Share on other sites

The naming system is transparent, but I will have a generic array of this data stored.  As for my tables I have

 

Users Table:  UseID, Username, Password, Location (for map), Hp, Other stats

Inventory:  This is being stored by a # of a given item type, Not each item individually so it has ItemType, UserId, ItemCount

Battles: BattleID, UserID, Opp1, Opp2, Opp3, Opp4, Opp1Hp, Opp1,str, Opp1 other stats, Timestart, Timeended.

Quest_gen: QuestID, Q_Type, Number Open, Number Total, Tstart, Tclose, Reward

Quest_type1: Quest Type specific info like a battling quest or a gathering quest, etc

Items: Defines each Itemtype

 

That is my basic idea, The Quest_type1 is just 1 of a lot of potential tables,  it will contain each users individual quest actions.

Link to comment
Share on other sites

I think i get it. But as above the quest table flat bed with a field of type of quest

 

Each compeditor has his own table with

 

The next quest can't be atempted untill the last is completed.

Each task table will be generated with a mixture of tasks and kills.

 

No I would have thousands of table, but I didn't think of having hte single open quest idea.  I think I might add that in

Link to comment
Share on other sites

To be quite honest. This is not realy a subject for this group. This is a PHP group for unique PHP orentated problems. You are trying to create a massive internet game with a database and multiple tables. your problem is not a PHP one, it is a database structure one and not even for the mysql group either.

 

you need to sit down with a piece of paper and draw some schema / flow control of the game and draw up a database layout. But it is not a PHP group problem. Sorry

 

Desmond.

 

Link to comment
Share on other sites

To be quite honest. This is not realy a subject for this group. This is a PHP group for unique PHP orentated problems. You are trying to create a massive internet game with a database and multiple tables. your problem is not a PHP one, it is a database structure one and not even for the mysql group either.

 

you need to sit down with a piece of paper and draw some schema / flow control of the game and draw up a database layout. But it is not a PHP group problem. Sorry

 

Desmond.

 

 

Your so quick to accuse something of being something it doesn't because you don't get it.  It is a php issue, because there is a bunch of ways to do it with "php", and i'm triyng to get opinions on how to do it the best.  The backend structure can vary from extremely static, to full db, and I'm wondering if people have ideas on which will be best.

Link to comment
Share on other sites

Users Table:  UseID, Username, Password, Location (for map), Hp, Other stats

Inventory:  This is being stored by a # of a given item type, Not each item individually so it has ItemType, UserId, ItemCount

Battles: BattleID, UserID, Opp1, Opp2, Opp3, Opp4, Opp1Hp, Opp1,str, Opp1 other stats, Timestart, Timeended.

Quest_gen: QuestID, Q_Type, Number Open, Number Total, Tstart, Tclose, Reward

Quest_type1: Quest Type specific info like a battling quest or a gathering quest, etc

Items: Defines each Itemtype

 

That is my basic idea, The Quest_type1 is just 1 of a lot of potential tables,  it will contain each users individual quest actions.

 

To me, I like how this is set-up, and it's set-up beautifully. However, actions that a user takes should not really be defined in the database. As far as I'm concerned, a database only needs to know: the start and the end. The in-between can be appended to a unique flat file (which is preferrable).

Link to comment
Share on other sites

If you are trying to get help on the best way to query a database then that is a database issue.

 

Where is the PHP in "Select * from morons"

 

 

 

Uhhh.... the asterisk, gasp o_o we use it in regexp all the time, as well as php, and other various languages. This is PHP Help, meaning if they know how to do something, and they want to know some ways to go about doing something, they can query the board.

 

Anyhow, just remember with your queries to mysql_free_result after each one, just to help. Every little bit counts. You may want to look into OOP for this a little bit, cause in fact, it may be easier to define the function once, and just call it numerous times... I believe this would be a perfect example for OOP.

Link to comment
Share on other sites

If you use the basics, you can handle it.

 

IE:

class Quests() {

var $questid;
var $time;
//add more variables to define for this class alone

function read_quest(){
mysql_query("SELECT blah blah FROM blah blah WHERE 'questid' = '$this->questid' ");
//other ways to read, etc...
}

//other functions that are general and helps you

}//end class

 

some php file

include 'above_class.php';//the class above

$quests = new Quests();
$quests->questid = "12";
$quests->read_quest();//runs the function, you can even obtain values from this as if it was a regular return value; thing IE:
$returned_value = $quests->read_quest();//as long as you code the return value; into the original function

 

That's the basics, then it goes on about constructors, extends and things I don't mess with atm.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.