Game Script help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Game Script help

Post by Smackie »

Im making a game and well i came across a few problems all in one :? i want to make it where it will check to see if the user has enough gold or money to buy the armor or if i can make it where the radio button will only show when thet user has the same or more money or gold. then make it where it changes the armor, attack, and defense in database. here is my script

armorshop.php

Code: Select all

<?php

echo'
<center>
<font class="txt">
Armor Shop<br>';
require 'inhandgold.php';
echo'
<br><br>
<font class="txt">
<form name="armor" method="post" action="../index.php?pages=armorshop2">
<table width="317" border="1" cellpadding="0" cellspacing="0" class="txt">
<tr>
<td width="21"></td>
<td width="123">Armor Name</td>
<td width="60">Att/Def</td>
<td width="113">Cost</td>
</tr>
<tr>
<td><input name="armor" type="radio" value="sheild"></td>
<td>Sheild</td>
<td>0/5</td>
<td>5 gold</td>
</tr>
<tr>
<td><input name="armor" type="radio" value="leatherhelmet"></td>
<td>Leather Helmet</td>
<td>0/5</td>
<td>10 gold</td>
</tr>
<tr>
<td><input name="armor" type="radio" value="bodyguard"></td>
<td>Body Guard</td>
<td>0/10</td>
<td>25 gold</td>
</tr>
<tr>
<td><input name="armor" type="radio" value="steelarmor"></td>
<td>Steel Armor</td>
<td>0/25</td>
<td>50 gold</td>
</tr>
</table>
<table width="317" border="1" cellpadding="0" cellspacing="0" class="txt">
<tr>
<td><center><input name="armor" type="submit" value="Buy Armor" class="submit-button"></center></td>
</tr>
</form>
</font>
</center>';
?>
armorshop2.php

Code: Select all

<?php
require 'db.php';
$shield = $_POST['shield'];
$leatherhelmet = $_POST['leatherhelmet'];
$bodyguard = $_POST['bodyguard'];
$steelarmor = $_POST['steelarmor'];
$gold = $_GET['gold'];

if (($shield) > ($gold)) {
 
	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry You dont got the Gold for this Armor.</font></center><br>';
	require 'armorshop.php';
	return;
}

if (($letherhelmet) > ($gold)) {

	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry You dont got the Gold for this Armor.</font></center><br>';
	require 'armorshop.php';
	return;
}

if (($bodyguard) > ($gold)) {     

	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry You dont got the Gold for this Armor.</font></center><br>';
	require 'armorshop.php';
	return;
}

if  ((steelarmor) > ($gold)) {

	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry You dont got the Gold for this Armor.</font></center><br>';
	require 'armorshop.php';
	return;
}

if ((!$shield) || (!$leatherhelmet) || (!$bodyguard) || (!$steelarmor)) {

	
	echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry you dont have enough gold for this armor</font></center><br>';
	require 'armorshop.php';
	return;
}

$sql = mysql_query("INSERT INTO users (armor)
		VALUES('$armor')") or die (mysql_error());


if (!$sql) {
	
	echo '<center><font class="h">There has been an error adding your armor. Please contact the webmaster.</font></center>';

}

?>
Thank you
Smackie
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not seeing where your problem is. :?
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

well it just keeps sending back that i dont got enough gold for the armor and it doesnt update the armor and the defense (not on there still working on that part) or the attack (not on there still working on that part) and well im not sure on them parts and im not sure on how to make it subtrack how much the armor cost either i mean i know how but im not sure on making it more then one thing and changing the price and stuff
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Code: Select all

$shield = $_POST['shield']; 
$leatherhelmet = $_POST['leatherhelmet']; 
$bodyguard = $_POST['bodyguard']; 
$steelarmor = $_POST['steelarmor']; 
$gold = $_GET['gold'];
where do you get these POST and GET values from???
I dont know why you have used GET for gold while others have POST.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

shouldn't have gold passed in through the user anyways. ;)
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

the POST ones are to get the infomation from armorshop.php

and the GET is to get the Gold from the database to check to see how much the user has so it can check to see if they have enough to use to buy the armor and so it can get subtracted...
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Smackie wrote:the POST ones are to get the infomation from armorshop.php

and the GET is to get the Gold from the database to check to see how much the user has so it can check to see if they have enough to use to buy the armor and so it can get subtracted...
its fine about the post ones.
where do you get the gold value from the db???why do you use a GET? I dont see any url variables being used 8O
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

im getting the gold from users database but i just put that script together im looking for someone that can help me to design it better and make everything work like its suppose to and stuff.. I havent really put a game together so thats why im asking for some help right now :?
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post by thomas777neo »

you also spelt shield incorrectly in the armorshop.php

edit: Realised that is your problem if you look @ this piece of code:

Code: Select all

if ((!$shield) || (!$leatherhelmet) || (!$bodyguard) || (!$steelarmor)) { 

     
    echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry you dont have enough gold for this armor</font></center><br>'; 
    require 'armorshop.php'; 
    return; 
}
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

thomas777neo wrote:you also spelt shield incorrectly in the armorshop.php

edit: Realised that is your problem if you look @ this piece of code:

Code: Select all

if ((!$shield) || (!$leatherhelmet) || (!$bodyguard) || (!$steelarmor)) { 

     
    echo '<center><font size="1" face="tahoma" color="red"><b>Error!</b> Sorry you dont have enough gold for this armor</font></center><br>'; 
    require 'armorshop.php'; 
    return; 
}
i already fixed the spelling before you said anything... and also i dont really see a problem there :? unless you mean with the ! (!$shield)
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

Post by Smackie »

Can someone help me and change this scirpt so it will work like i want it to?
Post Reply