grlayouts Posted October 26, 2007 Share Posted October 26, 2007 OK I have a market game, what I want to try to do is. set it so that depending on how many players are playing a how many factories there are the amount the market can fluctuate. IE. if i have 10 players with 10 steak houses making 100 steaks. the price would start at 50 but go down every time someone sells. but to increase "boost the market" there are drugs factorys which have a static price ie 10. so if someone sold 10000 that would boost the market depending on the ammount of steaks and people making them. the code i have is <?php print "<form method=post action=cmarket.php?view=sell&step=sell>Sell <input name=amount><select name=seller><option value=drugs>Drugs</option><option value=steak>Steaks</option></select>. <input type=submit value=Sell></form>"; if (isset($_POST)){ switch($_POST['seller']) { case "drugs": if ($stat['drugs'] < $amount) { print "Sorry mate, you don't have the drugs."; } else { mysql_query("update players set drugs=(drugs-$amount) where id=".$stat[id]); mysql_query("update players set credits=credits+($amount*".$stat['drugprice'].") where id=".$stat['id']); print "You sold $amount of drugs."; } break; case "steak": if ($stat['steaks'] < $amount) { print "Sorry mate, you don't have the steaks."; } else { mysql_query("update players set steaks=(steaks-$amount) where id=".$stat[id]); mysql_query("update players set credits=credits+($amount*".$stat['steakprice'].") where id=".$stat['id']); print "You sold $amount of steaks."; } } } ?></div></td> </tr> </table> <table width=100% cellpadding=2 cellspacing=0 style="width:100%;height:95%;margin-top:10px;border:1px solid #5B84A4;"> <tr height=25 bgcolor=#0F354C><td width=25%><b>Rank </td> <td width=24%><b>Stock</td> <td width=14%><b>Last Payout</td> <td width=21%><b>Selling Price </td> </tr> <tr height=20 bgcolor=#0F354C> <td>Drugs</td> <td><? print"$stat[drugs]"; ?></td> <td><? print"$stat[dpayout]"; ?></td> <td><? print"$stat[drugprice]"; ?></td> </tr> <tr height=20 bgcolor=#0F354C> <td>Steaks</td> <td><? print"$stat[steaks]"; ?></td> <td><? print"$stat[spayout]"; ?></td> <td><? print"$stat[steakprice]"; ?></td> </tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/74846-fluctuation/ Share on other sites More sharing options...
GingerRobot Posted October 26, 2007 Share Posted October 26, 2007 Why would the price of steak go down as people sell? Surely the principle of suppy and demand would suggest that the less steaks there are, the more they are worth (assuming, of course, demand remains constant?) Anyways, aside from that, this can be as simple or as complex as you like. At a basic level, you could 'count up' the amount of steaks available, and base the price on this, making adjustments if certain criteria are met with regard to drug availablity. P.S. I'd love to know what drugs and steak have got to do with each other! Quote Link to comment https://forums.phpfreaks.com/topic/74846-fluctuation/#findComment-378454 Share on other sites More sharing options...
grlayouts Posted October 26, 2007 Author Share Posted October 26, 2007 any idea how i could do the count as an example. steaks and drugs... no idea all i could think of at the time. Quote Link to comment https://forums.phpfreaks.com/topic/74846-fluctuation/#findComment-378461 Share on other sites More sharing options...
GingerRobot Posted October 26, 2007 Share Posted October 26, 2007 Something like: <?php $sql = "SELECT COUNT(`steaks`) FROM `players`"; $result = mysql_query($sql) or die(mysql_error()); $num_steaks = mysql_result($result,0); echo 'The total number of steaks is: '.$num_steaks; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74846-fluctuation/#findComment-378466 Share on other sites More sharing options...
grlayouts Posted October 26, 2007 Author Share Posted October 26, 2007 yeah thats to display the total steaks, how can i make that fluctutate the steak price between say 10-30 Quote Link to comment https://forums.phpfreaks.com/topic/74846-fluctuation/#findComment-378475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.