Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
trying to figure out how to create a equip system for my game
Old 06-10-2010, 05:36 AM trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
Hi I am new to PHP, I have been teaching myself it for about a month now. it seems I have ran into a road block. I want to create an equip system for this game I am creating bit I don't know how to do it. I am using a DB as well.

I need the system to be able to :

-buy a an item
-appear on a page that the user has bought it

I already have figured out how to actually equip the item those are are just the problems I am having.

If you guys could help me or just tell me what functions to use, that would be great.
Direct is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-10-2010, 05:39 AM Re: trying to figure out how to create a equip system for my game
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
This may not be the best way to do it but by my logic I would go along the lines of:

Database of all items avalible for purchase.
Each player has a database of items that have been purchased.

You can display all items a player owns by pulling the info from thier database, you can add cols like number avalible so that only a certain ammount can be seeded into the game etc and reduce the number by 1 every time a player buys one, then adding that item to thier database.
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-10-2010, 05:46 AM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
Well so far I ahve a table for user data and item data. My only problem is I have is how to set it up so the user purchases the item then it is available to equip
Direct is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 05:51 AM Re: trying to figure out how to create a equip system for my game
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
have two columns in your item data table, can be equiped, is equiped.

If the item can be equiped and is not equiped the show equip button, once pressed changed is equiped to true.
If the item cannot be equiped then is equiped is false.
If the item can be equiped and is equiped, is equiped is true.

Or somthing along those lines. There are so many ways to make a system like this and strong arguments for and against them all.
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-10-2010, 05:57 AM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
The equip part is easy, I am having trouble with the purchasing part

Last edited by Direct; 06-10-2010 at 06:01 AM..
Direct is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 06:01 AM Re: trying to figure out how to create a equip system for my game
Phunk Rabbit's Avatar
Ultra Talker

Posts: 255
Name: John Nerush
Location: Milton Keynes, UK
Trades: 0
Yes it should work fine but once you get a few hundred or thousand items you might wish you had a seperate table for the users items rather than query the whole item table.
__________________

Please login or register to view this content. Registration is FREE

Learn professional skills from professional people, from $6.50 a month.
Phunk Rabbit is offline
Reply With Quote
View Public Profile Visit Phunk Rabbit's homepage!
 
Old 06-10-2010, 06:12 AM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
Upon further review that doesn't seem like it would work since it will not work when there is multiple users. gah this is aggravating
Direct is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 06:27 AM Re: trying to figure out how to create a equip system for my game
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
you could maybe have an items table with an ID attached to the item.

Then on each players data table have a field with ID's comma separated?

So if you have
hammer 1
spoon 2
knife 3
potato 4
chainsaw 5
etc
etc

Then for
user:
name lynxus
password dfsafdsafsafdsafsafsa
email mooo@moo.com
items 1,3,5
accountactive 1
online 1
etc
etc
etc


Then when you read it from the database turn the items into an array split by the comma.

You then know what items they have as you can reference the ID to the item name in the ITEMS table.?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 06-10-2010, 06:32 AM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
Ah that's what my friend was telling me to do but I didn't understand it until now. I would use the explode function right like explode("," , $array)
Direct is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 06:38 AM Re: trying to figure out how to create a equip system for my game
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Yeah just explode the string you get back from the mysql select.

Then you can select ITEMname from ITEMS where id = "whatever";

that will then give you the item name from the database.

adding a new item would be as simple as adding a new item to the items table with a unique ID
I suppose in teh items table you can have how many are left , the cost etc etc
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 06-10-2010, 06:59 AM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
Thanks a lot I am glad I found a forum that is actually active, all the other ones would take days to respond.

I guess one more question I have is how can I update the items column with the id without erasing the other items
Direct is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 07:03 AM Re: trying to figure out how to create a equip system for my game
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Do you mean adding a ID column? to an already existing table?

do you not have an id column for your tables anyway?

One thing i always add is an id column to every table with an auto increment value ( very helpful for such changes to code. )

I would suggest ( if you use mysql ) is to install phpmyadmin.
You should be able to add a column with that , make sure its datatype is "int" and set to auto increment.

Or use the ALTER TABLE command for mysql ( im sure sql etc has similar )


May be an idea to backup the database before making any major changes with mysqldump.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Last edited by lynxus; 06-10-2010 at 07:04 AM..
lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 06-10-2010, 07:10 AM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
lol no

like you said have the item column set up as :1,2,3 etc.

Say the user purchases a new item how can add it to that without erasing the others.

Would it just be

$newitem = $user['item'] . "," . $item['id'] ;

Then just update the user item column with the $newitem
Direct is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 07:15 AM Re: trying to figure out how to create a equip system for my game
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Well, you would have a list of "All items" in your items table.

You can use this to pull what items are available in the purchase screen and how much they cost ( once again the cost can be a column in the items table )

Then in your userdata table.
you would have a colum called items and put them in that colum 1,3,5,2,6,33,231 etc.

So to buy an item i would do this:

Select items and item id from the ITEMS table.
Buy an item and get its ITEM id.
Select items from the usertable ( so the $useritems var woul have 3,2,,34,24, etc )
You then would edit the var you just got back from the users database record to add teh new item ( if they dont already have it )
$useritems = $useritems + ",itemnumber"; ( or as you said, use an array and drop it in that, then update the user items table with that array data )

This would then add it to their own list of items with a matching ID.

If that makes any sense lol?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE



Last edited by lynxus; 06-10-2010 at 07:16 AM..
lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 06-10-2010, 07:17 AM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
Alright that does make sense actually.

I use the + symbol and not the concat?
Direct is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 07:21 AM Re: trying to figure out how to create a equip system for my game
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Quote:
Originally Posted by Direct View Post
Alright that does make sense actually.

I use the + symbol and not the concat?
It doesnt really matter as long as a string of ID's comma separated ( or whatever separated , depending on what you want to use in the explode(); ) ends up in the database.

All your trying to do is get some ID's into a user table so you can reference the ID's against a master "ITEMS" table.

Choose whatever way you fancy to achieve this.
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 06-10-2010, 07:24 AM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
Thanks a lot for the help
Direct is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 09:50 AM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
PHP Code:
<?php
//connect
require("connect.php") ;

//get attack data
$attack_query "SELECT name,id FROM attacks" ;
$attack_results mysql_query($attack_query) ;

if(
$_POST){
     if(
$_POST['attack'] == "{$attacks['id']}"){
         
//get user attacks
         
$user_query "SELECT attacks FROM user_info WHERE user_id=3" ;
         
$user_results mysql_query($user_query) ;
         
$user mysql_fetch_array($user_results) ;
         
         if(
$user['attacks'] == ""){
             
$user['attacks'] = $user['attacks'] . $attacks['id'] . "," ;
            }
         else{
             
$user['attacks'] = $user['attacks'] . "," $attacks['id']  ;
            }
         
mysql_query("UPDATE user_info SET attacks='{$user['attacks']}' WHERE user_id=3") ;
        }
     }


   
if(! 
$_POST){
echo
"<form method='post' action=''>
     <select name='attack'>" 
;
while(
$attacks mysql_fetch_array($attack_results) ){
     echo 
"<option value='{$attacks['id']}'>{$attacks['name']}</option>" ;
}
echo
"</select>
     <input type='submit' value='Submit' />
     </form>" 
;
     }
     
     
?>
Alright I tried making the script, basically nothing gets inserted into the user attacks column when I run it. I was wondering if somebody could help me out a little.
Direct is offline
Reply With Quote
View Public Profile
 
Old 06-10-2010, 09:24 PM Re: trying to figure out how to create a equip system for my game
Experienced Talker

Posts: 35
Trades: 0
I guess the problem I am having is how can I make it so the attack id for the choice gets put in the post variable then without having an if/elseif statement for each attack set it up so the selection id is put in the user table
Direct is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to trying to figure out how to create a equip system for my game
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 3.22059 seconds with 12 queries