Need someone to point me in the right direction

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Slav2
Posts: 96
Joined: Tue Jan 11, 2011 7:46 am

Need someone to point me in the right direction

Post by Slav2 »

Ok, i have the whole register and confirmation and login system working like it should. now i have some questions on what or how to do some things, and ill be good :)

(in my game you start with a city and some resources, and you build up and train troops.)

1) ok, first buildings. How should i store that data?

a) the table that i have in mysql are these:

users-(fields) id, username, password, points, mycities(total amount of cities this player has), and email

resources-(fields) id (Auto inc.), userid, city name, wood, stone, iron, food, gold, happiness, loyalty

b) so like i need to know were or how to store these things: (diff building types and the costs to upgrade them, the players building he/she has built and their lvls) like should those things be diff tables, or included in some tables?


2) also ok after the player signs in, he/she is then redirected to the city view. ok its hard to explain wht i need here, but ill try my best. so when the player starts the city will already have a couple buildings they start with (town hall, ware house, ...) the rest of the spots aren't going to have anything there and be blank building areas. so i am wondering how do i code this? like im not looking or asking someone to just type me a whole code or anything, but just explain kinda, and just set me in the right direction.
Thanks,

Slav2
Loopy

Re: Need someone to point me in the right direction

Post by Loopy »

Your troops and your buildings could be handled in a similar fashion. In my game, I tackled troops by creating two tables in my database, one that contains all troops that can be raised, and one that contains all troops that have been raised.

Not all troops are accessible from every race in my game (for instance, race "A" may have a different set of troops than race "B"). When the player goes to the "Army" page, I load from the table of all troops the troops that are particular to that player's race (i.e. someone playing an Elf race (even though I don't use elves...) sees elf troops... someone playing an orc race see orc troops).

Then, when the player "raises" a troop, I either insert, or update (if that troop type is already there), the quantity in the "active" troops table.

Buildings could work in a very similar manner. I would make a table that contained all the buildings, the requirements for building, maintenance, benefits, disadvantages, etc, and another table of "completed" buildings which are assigned to a particular player ID. When a player completes construction of a building, add that building to the 'completed_buildings' table. If a player is only upgrading, then the entry for that building in the "completed" buildings table should already exist, and then you just update the record to reflect the new level.

If a player wanted to upgrade a building, you'd query the table of all buildings for the cost to upgrade (either a flat fee, or perhaps the cost gets incrementally higher for higher levels of buildings... either could be stored in the table). If they have the money, upgrade.. if not, error message.

Regarding how you start a new player with some buildings and not others, when the player registered (or perhaps confirmed their registration), you could run a script that initializes their setup.... so maybe to start with they get 100 gold, 1,000 light spearmen, and the buildings you mentioned. So under this setup I have explained, once they register, you'd run a query to set their gold to whatever number, you'd insert a record for 1,000 light spearmen into the "active" troops table, and you'd insert 3 records into the "active" buildings table (one for each building the player should start with).

This is really speaking in generic terms though, and there a millions ways to do what you're asking, but it really kind of depends on how you want to do it, and other functionality you have in your game. It sounds like you're rather early on in your game design, so I would highly recommend sitting down with a pencil and paper, writing down each "page" on your website you need, and then the functionality that you need to be able to do on each page. I think I could have saved myself about 3 years worth of development time if someone had mentioned that to me when I started... :)
User avatar
Slav2
Posts: 96
Joined: Tue Jan 11, 2011 7:46 am

Re: Need someone to point me in the right direction

Post by Slav2 »

wow that almost completely explained what i was looking for. thank you ^^ and that yes, i have put everything on paper, even some drawings.

Slav2 wrote:2) also ok after the player signs in, he/she is then redirected to the city view. ok its hard to explain wht i need here, but ill try my best. so when the player starts the city will already have a couple buildings they start with (town hall, ware house, ...) the rest of the spots aren't going to have anything there and be blank building areas. so i am wondering how do i code this? like im not looking or asking someone to just type me a whole code or anything, but just explain kinda, and just set me in the right direction.

and one more thing, when inserting into the buildings table (gonna have the requirements to build that building) how exactly do i do it?

a) id|building|wood|stone|......

OR

b) id|building|level\wood|stone

example:

id | building | level | wood| stone | ......
1 | town hall | 1 | ......| .......|.......
1 | town hall | 2 | ......| .......|.......
2 |warehouse| 1 |......|........|.......

SO LIKE WHAT IM TRYING TO FIND OUT IS DO I PUT THE DIFFERENT BUILDING LVLS AND DIFF BUILDINGS ALL IN ONE TABLE, OR DO I HAVE TO MAKE A NEW TABLE FOR EVERY BUILDING?

Thanks,

Slav2
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Need someone to point me in the right direction

Post by PaxBritannia »

One thing that loopy didn't mention though are building/troop levels.

If your the effect of your levels can be derived by a forumla (e.g. hp=level*100, or atk=level*level*5), you could just run them in the script. If they aren't derived by a simple formula though, you might want to store them. To do that you would have another column for the building's level and treat each building separately.

So to summarise for your buildings you need 2 tables: building_settings, and buildings

Code: Select all

building_setting: id (AI), buildingid, building level, hp, and then their building/upgrade cost in the several resources, and any other modifiers you need

Code: Select all

buildings: id (AI), cityid, amount (if they can have more than 1), buildingid, building level
If your buildings need prerequisites to be build (you need to research the academy before the barracks) then you should use a third table called buiding_prereq:

Code: Select all

buiding_prereq: id (AI), buildingid, prereq_buildingid, prereq_buildinglevel. 
If they also have prerequisites to be upgraded, then you also need a column called buildingid_level.

If a building has multiple prerequisites, store them in different entries, and process them in the script with a loop.

pax.
User avatar
Slav2
Posts: 96
Joined: Tue Jan 11, 2011 7:46 am

Re: Need someone to point me in the right direction

Post by Slav2 »

hmmmm ok.....ummn two things, what does prerequisites mean>? and if i wanna add the time it takes to build per lvl, in the table were you can pick: varchart, int, and so on, if i choose time, is there a different way to write the exact amount of time into the mysql?? like does it have to look like this : 01:53:32 (h/m/s) or is there another way it has to be?
Thanks,

Slav2
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Need someone to point me in the right direction

Post by PaxBritannia »

Prerequisites are another word for preexisting-requirements. For example, in your game, you might need to upgrade the barracks to level 5 before you can start building the stables.

And to store time durations, use int and store them using seconds. In fact, to store time, the easiest way is to use bigint(20) and store seconds since the unix epoch (1st January 1970) instead of using timestamp or datetime fields.

pax.
Last edited by PaxBritannia on Thu Jan 20, 2011 2:07 am, edited 1 time in total.
User avatar
Slav2
Posts: 96
Joined: Tue Jan 11, 2011 7:46 am

Re: Need someone to point me in the right direction

Post by Slav2 »

ok thank i understand that word now.....but i still didnt fully understand wat u put about the time......
Thanks,

Slav2
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Need someone to point me in the right direction

Post by PaxBritannia »

Normally to store time you would use mySQL's built in fields: Date, Time, Datetime, and timestamp. php handles time almost in Unixtime exclusively.

In order to use php to manipulate the time in Date, time, and datetime, you must process it first. For most people this gets really annoying.

If you store it in a timestamp, which is meant to store Unixtime, if you process any dates after the year 2038 (google: Y2K38), your data will give you errors. By storing it in an int, those problems will not exist until the year 2038 (when the actual time() function stops working), but by then you should have fixed it.

By storing it in an int, you can access you can times easily and be assured you can use them till at least 2038.

pax.
User avatar
Slav2
Posts: 96
Joined: Tue Jan 11, 2011 7:46 am

Re: Need someone to point me in the right direction

Post by Slav2 »

lol wow i cant understand what u mean....so srry.....like all i need to kno for now is like im adding the troops and buildings into mysql...and for the troops im adding how long it takes to train one . if i use the TIME thing, is there a specific way to enter the time when insterting info into that data base?
Thanks,

Slav2
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: Need someone to point me in the right direction

Post by PaxBritannia »

???? :|

Use an integer field, 5 digits. Store build times in seconds in the troops_setting table.

You want another table called troops_train to store time, troop id, amount and city id. After the time has elapsed, you'll need to write a script to activate them.

If your game needs to train troops one at a time, to find out how to make it active 1 troop at a time, read: http://indie-resource.com/forums/viewto ... =18&t=2673.

pax.
Post Reply

Return to “Advanced Help and Support”