-BRAIDZ- Posted June 8, 2015 Author Share Posted June 8, 2015 [MENTION=68406]-BRAIDZ-[/MENTION] You will find programming much more practical if you didn't use a mobile editor. Why would you even attempt to program on your phone?! Like wuttttttt..... Because my laptop kind of had a "malfunction" so until I can fix that or get a new one, I'll be using my phone haha Quote Link to comment Share on other sites More sharing options...
sniko Posted June 8, 2015 Share Posted June 8, 2015 (edited) <?php include_once "globals.php"; print " <h3>Your Home Brewery</h3>"; echo " <br>You are sitting in your shed. </br>What would you like to brew?</br>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'>Brewery Options</th> </tr> <tr> <td>Beer</td> <td> <a href='brewery.php?action=beer'>Brew</a> </td> </tr> <tr> <td>Whiskey</td> <td> <a href='brewery.php?action=whiskey'>Brew</a> </td> </tr> </tr> <tr> <td>Cider</td> <td> <a href='brewery.php?action=cider'>Brew</a> </td> </tr> </tr> <tr> <td>Vodka</td> <td> <a href='brewery.php?action=vodka'>Brew</a> </td> </tr> </table><hr width=85%> "; print "This module is a working progress. Should be up and running in a few weeks."; ?> What does everyone think? You don't need to start print ""; then end it and start echo ""; to output different text blocks. There is really no PHP, so you could just close the PHP tags on line 4 and output HTML without using PHP You haven't ended the headers (displayed the footer) at the end, ie: $h->endpage(); Your current set-up indicated that types of brewery actions will be hardcoded. See http://makewebgames.io/showthread.php/46088-In-Production-Brewery-Mod?p=311918&viewfull=1#post311918 ( [MENTION=68711]KyleMassacre[/MENTION] ) Edited June 8, 2015 by sniko Quote Link to comment Share on other sites More sharing options...
sniko Posted June 8, 2015 Share Posted June 8, 2015 (edited) As you can see the login details appear, right so what we need for your mod is switch(); function switch($_GET['action']){ case 'beer': beer(); break; case 'whiskey': whiskey(); break; case 'cider': cider(); break; case 'vodka': vodka(); break; default: exit("Requires and action"); break; function cider(){ //Code right here } } You might want to redo that code :p It's going to error when a case is true because the function will be not defined (because it's still in the switch() and terminated by the break;) switch( strtolower($_GET['action']) ) { case 'beer': beer(); break; case 'whiskey': whiskey(); break; case 'cider': cider(); break; case 'vodka': vodka(); break; default: exit("Requires and action"); break; } function cider(){ //Code right here } //Define all other functions Edited June 8, 2015 by sniko Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 8, 2015 Author Share Posted June 8, 2015 You might want to redo that code :p It's going to error when a case is true because the function will be not defined (because it's still in the switch() and terminated by the break;) switch( strtolower($_GET['action']) ) { case 'beer': beer(); break; case 'whiskey': whiskey(); break; case 'cider': cider(); break; case 'vodka': vodka(); break; default: exit("Requires and action"); break; } function cider(){ //Code right here } //Define all other functions Will do this soon, but I'm not getting any errors as of yet Quote Link to comment Share on other sites More sharing options...
jcvenom Posted June 8, 2015 Share Posted June 8, 2015 You might want to redo that code :p It's going to error when a case is true because the function will be not defined (because it's still in the switch() and terminated by the break;) switch( strtolower($_GET['action']) ) { case 'beer': beer(); break; case 'whiskey': whiskey(); break; case 'cider': cider(); break; case 'vodka': vodka(); break; default: exit("Requires and action"); break; } function cider(){ //Code right here } //Define all other functions I didnt even see that thanks :P, was a mistake Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 8, 2015 Author Share Posted June 8, 2015 You might want to redo that code :p It's going to error when a case is true because the function will be not defined (because it's still in the switch() and terminated by the break;) switch( strtolower($_GET['action']) ) { case 'beer': beer(); break; case 'whiskey': whiskey(); break; case 'cider': cider(); break; case 'vodka': vodka(); break; default: exit("Requires and action"); break; } function cider(){ //Code right here } //Define all other functions What about this? Can you help me with adding queries please? Give me an example, and tell me where to put it? I only want one sql and that is 'brew' and it will be in the 'users' table. Also, I want it so when you brew you get an item, and set the rand between 1 and 6 or something.. And also, if you have brewed 10 times in one day, how do I get it so it says "You have already brewed 10 times today, come back tomorrow" I do not want to change any part of my code as this is the only way I can read code at the moment aha! <?php require_once("globals.php"); $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : ''; switch($_GET['action']){ case 'beer': brew_beer(); break; case 'brewbeer': brew_beer_sub(); break; case 'whiskey': brew_whiskey(); break; default: brewery(); break; } function brewery() { global $db,$ir,$c,$userid,$h; print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table> <h3>Your Brewery</h3>"; echo " You are sitting in your shed. </br>What would you like to brew?</br>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'>Brewery Options</th> </tr> <tr> <td>Beer</td> <td> <a href='brewery.php?action=beer'>Brew</a> </td> </tr> <tr> <td>Whiskey</td> <td> <a href='brewery.php?action=whiskey'>Brew</a> </td> </tr> </tr> <tr> <td>Cider</td> <td> <a href='brewery.php?action=cider'>Brew</a> </td> </tr> </tr> <tr> <td>Vodka</td> <td> <a href='brewery.php?action=vodka'>Brew</a> </td> </tr> </table> "; print "This module is a working progress. Should be up and running in a few weeks."; } function brew_beer() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Beer</h3>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'> Beer Information</th> </tr> <tr> <td>Time to brew Beer?</td> <td>25 Minutes</td> </tr> <tr> <td>Brave needed to brew Beer?</td> <td>5 Brave</td> </tr> <td>What does beer do?</td> <td>Gives you an energy boost</td> </tr> </table> <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> "; } function brew_whiskey() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Whiskey</h3>"; } function brew_beer_sub() { print "You brewed (number of bottles) Bottles of Beer"; $db->query("UPDATE users SET brew=brew-1 WHERE $userid=userid"); } ?> Quote Link to comment Share on other sites More sharing options...
sniko Posted June 8, 2015 Share Posted June 8, 2015 (edited) What about this? Can you help me with adding queries please? Give me an example, and tell me where to put it? I only want one sql and that is 'brew' and it will be in the 'users' table. Also, I want it so when you brew you get an item, and set the rand between 1 and 6 or something.. And also, if you have brewed 10 times in one day, how do I get it so it says "You have already brewed 10 times today, come back tomorrow" I do not want to change any part of my code as this is the only way I can read code at the moment aha! <?php require_once("globals.php"); $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : ''; switch($_GET['action']){ case 'beer': brew_beer(); break; case 'brewbeer': brew_beer_sub(); break; case 'whiskey': brew_whiskey(); break; default: brewery(); break; } function brewery() { global $db,$ir,$c,$userid,$h; print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table> <h3>Your Brewery</h3>"; echo " You are sitting in your shed. </br>What would you like to brew?</br>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'>Brewery Options</th> </tr> <tr> <td>Beer</td> <td> <a href='brewery.php?action=beer'>Brew</a> </td> </tr> <tr> <td>Whiskey</td> <td> <a href='brewery.php?action=whiskey'>Brew</a> </td> </tr> </tr> <tr> <td>Cider</td> <td> <a href='brewery.php?action=cider'>Brew</a> </td> </tr> </tr> <tr> <td>Vodka</td> <td> <a href='brewery.php?action=vodka'>Brew</a> </td> </tr> </table> "; print "This module is a working progress. Should be up and running in a few weeks."; } function brew_beer() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Beer</h3>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'> Beer Information</th> </tr> <tr> <td>Time to brew Beer?</td> <td>25 Minutes</td> </tr> <tr> <td>Brave needed to brew Beer?</td> <td>5 Brave</td> </tr> <td>What does beer do?</td> <td>Gives you an energy boost</td> </tr> </table> <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> "; } function brew_whiskey() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Whiskey</h3>"; } function brew_beer_sub() { print "You brewed (number of bottles) Bottles of Beer"; $db->query("UPDATE users SET brew=brew-1 WHERE $userid=userid"); } ?> Can you help me with adding queries please? Give me an example, and tell me where to put it? Not sure what query you want... I only want one sql and that is 'brew' and it will be in the 'users' table. What do you want the query to do? (ie: Update `brew` value to what?) Also, I want it so when you brew you get an item, and set the rand between 1 and 6 or something.. rand() / mt_rand() And also, if you have brewed 10 times in one day, how do I get it so it says "You have already brewed 10 times today, come back tomorrow" Create a new table to record how many times a user has brewed When a user brews insert into said table On page load, calculate the amount of times they've brewed If equal to 10, show the message $strDbQuery = "SELECT COUNT(id) AS `times_brewed` FROM `users_brew` WHERE `userid`=". $_SESSION['userid']; $resTimesBrewed = $db->query($strDbQuery); if( is_resource($resTimesBrewed) === FALSE ) { //Something went wrong. //Say something to user die; } $arrResults = $db->fetch_row($resTimesBrewed); if($arrResults['times_brewed'] > 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } Then in your daily cron, truncate `users_brew` table. Edited June 8, 2015 by sniko Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 8, 2015 Author Share Posted June 8, 2015 Can you help me with adding queries please? Give me an example, and tell me where to put it? Not sure what query you want... I only want one sql and that is 'brew' and it will be in the 'users' table. What do you want the query to do? (ie: Update `brew` value to what?) Also, I want it so when you brew you get an item, and set the rand between 1 and 6 or something.. rand() / mt_rand() And also, if you have brewed 10 times in one day, how do I get it so it says "You have already brewed 10 times today, come back tomorrow" Create a new table to record how many times a user has brewed When a user brews insert into said table On page load, calculate the amount of times they've brewed If equal to 10, show the message $strDbQuery = "SELECT COUNT(id) AS `times_brewed` FROM `users_brew` WHERE `userid`=". $_SESSION['userid']; $resTimesBrewed = $db->query($strDbQuery); $arrResults = $db->fetch_row($resTimesBrewed); if($arrResults['times_brewed'] > 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } Then in your daily cron, truncate `users_brew` table. Okay thanks, this is complicated haha. Where do I put this? And what do I write for the give item? The item number is 277.. Sorry to be a pain in the back side haha Quote Link to comment Share on other sites More sharing options...
sniko Posted June 8, 2015 Share Posted June 8, 2015 (edited) Okay thanks, this is complicated haha. Where do I put this? And what do I write for the give item? The item number is 277.. Sorry to be a pain in the back side haha Where do you put what exactly? :confused: Look into item_add() or add_item() function in global_func.php (I can't remember the exact function name, but....) //Maybe this will work //Maybe it won't //I don't know the exact function name or the order of the parameters... item_add($_SESSION['userid'], 277, mt_rand(1,6)); Edited June 8, 2015 by sniko Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 8, 2015 Author Share Posted June 8, 2015 Where do you put what exactly? :confused: Look into item_add() or add_item() function in global_func.php (I can't remember the exact function name, but....) //Maybe this will work //Maybe it won't //I don't know the exact function name or the order of the parameters... item_add($_SESSION['userid'], 277, mt_rand(1,6)); Where do I put this? $strDbQuery = "SELECT COUNT(id) AS `times_brewed` FROM `users_brew` WHERE `userid`=". $_SESSION['userid']; $resTimesBrewed = $db->query($strDbQuery); $arrResults = $db->fetch_row($resTimesBrewed); if($arrResults['times_brewed'] > 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted June 8, 2015 Share Posted June 8, 2015 Where do I put this? $strDbQuery = "SELECT COUNT(id) AS `times_brewed` FROM `users_brew` WHERE `userid`=". $_SESSION['userid']; $resTimesBrewed = $db->query($strDbQuery); $arrResults = $db->fetch_row($resTimesBrewed); if($arrResults['times_brewed'] > 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } You need to place that code in the function that handles brewing Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 9, 2015 Author Share Posted June 9, 2015 You need to place that code in the function that handles brewing Thanks, do I need to do anymore sql strings? Or is this all I need to pit in it? Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 9, 2015 Author Share Posted June 9, 2015 Where do you put what exactly? :confused: Look into item_add() or add_item() function in global_func.php (I can't remember the exact function name, but....) //Maybe this will work //Maybe it won't //I don't know the exact function name or the order of the parameters... item_add($_SESSION['userid'], 277, mt_rand(1,6)); Did I get this correct? <?php require_once("globals.php"); $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : ''; switch($_GET['action']){ case 'beer': brew_beer(); break; case 'brewbeer': brew_beer_sub(); break; case 'whiskey': brew_whiskey(); break; default: brewery(); break; } function brewery() { global $db,$ir,$c,$userid,$h; print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table> <h3>Your Brewery</h3>"; echo " You are sitting in your shed. </br>What would you like to brew?</br>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'>Brewery Options</th> </tr> <tr> <td>Beer</td> <td> <a href='brewery.php?action=beer'>Brew</a> </td> </tr> <tr> <td>Whiskey</td> <td> <a href='brewery.php?action=whiskey'>Brew</a> </td> </tr> </tr> <tr> <td>Cider</td> <td> <a href='brewery.php?action=cider'>Brew</a> </td> </tr> </tr> <tr> <td>Vodka</td> <td> <a href='brewery.php?action=vodka'>Brew</a> </td> </tr> </table> "; print "This module is a working progress. Should be up and running in a few weeks."; } function brew_beer() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Beer</h3>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'> Beer Information</th> </tr> <tr> <td>Time to brew Beer?</td> <td>25 Minutes</td> </tr> <tr> <td>Brave needed to brew Beer?</td> <td>5 Brave</td> </tr> <td>What does beer do?</td> <td>Gives you an energy boost</td> </tr> </table> <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> "; } function brew_whiskey() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Whiskey</h3>"; } function brew_beer_sub() { $strDbQuery = "SELECT COUNT(id) AS `times_brewed` FROM `users_brew` WHERE `userid`=". $_SESSION['userid']; $resTimesBrewed = $db->query($strDbQuery); $arrResults = $db->fetch_row($resTimesBrewed); if($arrResults['times_brewed'] > 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } print "You brewed (number of bottles) Bottles of Beer"; $db->query("UPDATE `users_brew` SET `times_brewed`=`times_brewed`+1 WHERE 'userid' = {$userid}"); item_add($_SESSION['userid'], 277, mt_rand(1,6)); } ?> Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 9, 2015 Author Share Posted June 9, 2015 This is what I have now <?php require_once("globals.php"); if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); } if($ir['brew_time']) { die("You can't brew for another {$ir['brew_time']} minutes, when your current batch finishes."); } if(['brew'] == 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : ''; switch($_GET['action']){ case 'beer': brew_beer(); break; case 'brewbeer': brew_beer_sub(); break; case 'whiskey': brew_whiskey(); break; default: brewery(); break; } function brewery() { global $db,$ir,$c,$userid,$h; print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table> <h3>Your Brewery</h3>"; echo " You are sitting in your shed. </br>What would you like to brew?</br>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'>Brewery Options</th> </tr> <tr> <td>Beer</td> <td> <a href='brewery.php?action=beer'>Brew</a> </td> </tr> <tr> <td>Whiskey</td> <td> <a href='brewery.php?action=whiskey'>Brew</a> </td> </tr> </tr> <tr> <td>Cider</td> <td> <a href='brewery.php?action=cider'>Brew</a> </td> </tr> </tr> <tr> <td>Vodka</td> <td> <a href='brewery.php?action=vodka'>Brew</a> </td> </tr> </table> "; print "This module is a working progress. Should be up and running in a few weeks."; } function brew_beer() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Beer</h3>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'> Beer Information</th> </tr> <tr> <td>Time to brew Beer?</td> <td>25 Minutes</td> </tr> <tr> <td>Brave needed to brew Beer?</td> <td>5 Brave</td> </tr> <td>What does beer do?</td> <td>Gives you an energy boost</td> </tr> </table> <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> "; } function brew_whiskey() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Whiskey</h3>"; } function brew_beer_sub() { if ($_POST['brewbeer']){ global $db,$ir,$c,$userid,$h,$beer; $beer = rand(1, 6); echo "While brewing away, you managed to brew {$beer} Bottles of Beer!"; item_add($userid, 277, $beer); $db->query("UPDATE users SET brew=brew + 1 WHERE userid=$userid"); $db->query("UPDATE users SET brave=brave - 5 WHERE userid=$userid"); $db->query("UPDATE users SET brew_time=brew_time + 25 WHERE userid=$userid"); } } ?> I will be making a new case and function, so you can go into "Inventory" and it will say "Drink" next to "Bottle of Beer" but I will also set it up so you can't drink it while you have time left brewing.. What does everyone think? Quote Link to comment Share on other sites More sharing options...
sniko Posted June 9, 2015 Share Posted June 9, 2015 Where do I put this? $strDbQuery = "SELECT COUNT(id) AS `times_brewed` FROM `users_brew` WHERE `userid`=". $_SESSION['userid']; $resTimesBrewed = $db->query($strDbQuery); $arrResults = $db->fetch_row($resTimesBrewed); if($arrResults['times_brewed'] > 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } Man.... use your logic! :mad: Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 9, 2015 Author Share Posted June 9, 2015 Man.... use your logic! :mad: I did, and now I have this <?php require_once("globals.php"); if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); } if($ir['brew_time']) { die("You can't brew for another {$ir['brew_time']} minutes, when your current batch finishes."); } if($ir['brew'] == 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : ''; switch($_GET['action']){ case 'beer': brew_beer(); break; case 'drinkbeer': drink_beer(); break; case 'brewbeer': brew_beer_sub(); break; case 'whiskey': brew_whiskey(); break; default: brewery(); break; } function brewery() { global $db,$ir,$c,$userid,$h; print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table> <h3>Your Brewery</h3>"; echo " You are sitting in your shed. </br>What would you like to brew?</br>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'>Brewery Options</th> </tr> <tr> <td>Beer</td> <td> <a href='brewery.php?action=beer'>Brew</a> </td> </tr> <tr> <td>Whiskey</td> <td> <a href='brewery.php?action=whiskey'>Brew</a> </td> </tr> </tr> <tr> <td>Cider</td> <td> <a href='brewery.php?action=cider'>Brew</a> </td> </tr> </tr> <tr> <td>Vodka</td> <td> <a href='brewery.php?action=vodka'>Brew</a> </td> </tr> </table> "; print "<h3><font color='red'>This module is a is not complete and still in early production stage.</br> Not all functions will work properly.</font></h3>"; } function brew_beer() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Beer</h3>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'> Beer Information</th> </tr> <tr> <td>Time to brew Beer?</td> <td>25 Minutes</td> </tr> <tr> <td>Brave needed to brew Beer?</td> <td>5 Brave</td> </tr> <td>What does beer do?</td> <td>Gives you an energy boost of 25 Energy</td> </tr> </table> <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> "; } function brew_whiskey() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Whiskey</h3>"; } function brew_beer_sub() { if ($_POST['brewbeer']){ global $db,$ir,$c,$userid,$h,$beer; $beer = rand(1, 6); echo "While brewing away, you managed to brew {$beer} Bottles of Beer!"; item_add($userid, 277, $beer); $db->query("UPDATE users SET brew=brew + 1 WHERE userid=$userid"); $db->query("UPDATE users SET brave=brave - 5 WHERE userid=$userid"); $db->query("UPDATE users SET brew_time=brew_time + 25 WHERE userid=$userid"); } } function drink_beer() { print "still working on this function"; } ?> The way you explained was way too complicated. Now to work out how to make it so you require the item Bottle of Beer to access brewery.php?action=drinkbeer So then it credits the user the energy it provides, and also deletes one if that item from the users inventory, if you get what I mean? Quote Link to comment Share on other sites More sharing options...
NonStopCoding Posted June 9, 2015 Share Posted June 9, 2015 (edited) I did, and now I have this <?php require_once("globals.php"); if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); } if($ir['brew_time']) { die("You can't brew for another {$ir['brew_time']} minutes, when your current batch finishes."); } if($ir['brew'] == 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : ''; switch($_GET['action']){ case 'beer': brew_beer(); break; case 'drinkbeer': drink_beer(); break; case 'brewbeer': brew_beer_sub(); break; case 'whiskey': brew_whiskey(); break; default: brewery(); break; } function brewery() { global $db,$ir,$c,$userid,$h; print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table> <h3>Your Brewery</h3>"; echo " You are sitting in your shed. </br>What would you like to brew?</br>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'>Brewery Options</th> </tr> <tr> <td>Beer</td> <td> <a href='brewery.php?action=beer'>Brew</a> </td> </tr> <tr> <td>Whiskey</td> <td> <a href='brewery.php?action=whiskey'>Brew</a> </td> </tr> </tr> <tr> <td>Cider</td> <td> <a href='brewery.php?action=cider'>Brew</a> </td> </tr> </tr> <tr> <td>Vodka</td> <td> <a href='brewery.php?action=vodka'>Brew</a> </td> </tr> </table> "; print "<h3><font color='red'>This module is a is not complete and still in early production stage.</br> Not all functions will work properly.</font></h3>"; } function brew_beer() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Beer</h3>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'> Beer Information</th> </tr> <tr> <td>Time to brew Beer?</td> <td>25 Minutes</td> </tr> <tr> <td>Brave needed to brew Beer?</td> <td>5 Brave</td> </tr> <td>What does beer do?</td> <td>Gives you an energy boost of 25 Energy</td> </tr> </table> <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> "; } function brew_whiskey() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Whiskey</h3>"; } function brew_beer_sub() { if ($_POST['brewbeer']){ global $db,$ir,$c,$userid,$h,$beer; $beer = rand(1, 6); echo "While brewing away, you managed to brew {$beer} Bottles of Beer!"; item_add($userid, 277, $beer); $db->query("UPDATE users SET brew=brew + 1 WHERE userid=$userid"); $db->query("UPDATE users SET brave=brave - 5 WHERE userid=$userid"); $db->query("UPDATE users SET brew_time=brew_time + 25 WHERE userid=$userid"); } } function drink_beer() { print "still working on this function"; } ?> The way you explained was way too complicated. Now to work out how to make it so you require the item Bottle of Beer to access brewery.php?action=drinkbeer So then it credits the user the energy it provides, and also deletes one if that item from the users inventory, if you get what I mean? I have been noticing you are using <form> tags when not really needed a link is easy enough to add instead <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> could be done easy via a <a> tag <a href='brewery.php?action=brewbeer'>Brew Beer</a> if you are using the form submit because you like the look of the button instead of the text link you could add the <button> tag around the <a> tag <a href='brewery.php?action=brewbeer'><button>Brew Beer</button></a> Now to work out how to make it so you require the item Bottle of Beer the item add function will do this as sniko said but for in order for this to work you need to have the item in the items table in the database. So then it credits the user the energy it provides, and also deletes one if that item from the users inventory as i was saying above use a <a> tag to provide the link you need to go to the file when using a switch statement and functions to be able to call the function you need to call the case for example case 'go': go_brew(); break; so using <a href='filename.php?action <- notice the action we used it earlier in our switch statement switch($_GET['action']) ok back to link <a href='filename.php?action=go'>Go Brew Beer</a> noticed i used the go on the end of ?action= this is to let the a tag know that we want to access the go_brew() function if you wish to remove a item you will need the item_remove(); function Edit: I also see you have made it they need to wait 25 minutes to brew beer but you give item instantly when coding a module you need to think where the queries or code will go. Edited June 9, 2015 by NonStopCoding Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 9, 2015 Author Share Posted June 9, 2015 I have been noticing you are using <form> tags when not really needed a link is easy enough to add instead <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> could be done easy via a <a> tag <a href='brewery.php?action=brewbeer'>Brew Beer</a> if you are using the form submit because you like the look of the button instead of the text link you could add the <button> tag around the <a> tag <a href='brewery.php?action=brewbeer'><button>Brew Beer</button></a> Now to work out how to make it so you require the item Bottle of Beer the item add function will do this as sniko said but for in order for this to work you need to have the item in the items table in the database. So then it credits the user the energy it provides, and also deletes one if that item from the users inventory as i was saying above use a <a> tag to provide the link you need to go to the file when using a switch statement and functions to be able to call the function you need to call the case for example case 'go': go_brew(); break; so using <a href='filename.php?action <- notice the action we used it earlier in our switch statement switch($_GET['action']) ok back to link <a href='filename.php?action=go'>Go Brew Beer</a> noticed i used the go on the end of ?action= this is to let the a tag know that we want to access the go_brew() function if you wish to remove a item you will need the item_remove(); function Edit: I also see you have made it they need to wait 25 minutes to brew beer but you give item instantly when coding a module you need to think where the queries or code will go. Id rather the button option to brew. Looks neater, and yes I have really thought about that, well I have, but have no clue how I'd do it.. Quote Link to comment Share on other sites More sharing options...
sniko Posted June 9, 2015 Share Posted June 9, 2015 Id rather the button option to brew. Looks neater, and yes I have really thought about that, well I have, but have no clue how I'd do it.. Then use a link and style it like a button. As you're not using any form elements within your form, it seems a little wasted. Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 9, 2015 Author Share Posted June 9, 2015 Then use a link and style it like a button. As you're not using any form elements within your form, it seems a little wasted. And how do I do that? Also can you see what's going on with my last function? I only keep getting You don't have enough beer code: <?php require_once("globals.php"); if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); } if($ir['brew_time']) { die("You can't brew for another {$ir['brew_time']} minutes, when your current batch finishes."); } if($ir['brew'] == 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : ''; switch($_GET['action']){ case 'beer': brew_beer(); break; case 'drinkbeer': drink_beer(); break; case 'brewbeer': brew_beer_sub(); break; case 'whiskey': brew_whiskey(); break; default: brewery(); break; } function brewery() { global $db,$ir,$c,$userid,$h; print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table> <h3>Your Brewery</h3>"; echo " You are sitting in your shed. </br>What would you like to brew?</br>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'>Brewery Options</th> </tr> <tr> <td>Beer</td> <td> <a href='brewery.php?action=beer'>Brew</a> </td> </tr> <tr> <td>Whiskey</td> <td> <a href='brewery.php?action=whiskey'>Brew</a> </td> </tr> </tr> <tr> <td>Cider</td> <td> <a href='brewery.php?action=cider'>Brew</a> </td> </tr> </tr> <tr> <td>Vodka</td> <td> <a href='brewery.php?action=vodka'>Brew</a> </td> </tr> </table> "; print "<h3><font color='red'>This module is a is not complete and still in early production stage.</br> Not all functions will work properly.</font></h3>"; } function brew_beer() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Beer</h3>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'> Beer Information</th> </tr> <tr> <td>Time to brew Beer?</td> <td>25 Minutes</td> </tr> <tr> <td>Brave needed to brew Beer?</td> <td>5 Brave</td> </tr> <td>What does beer do?</td> <td>Gives you an energy boost of 25 Energy</td> </tr> </table> <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> "; } function brew_whiskey() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Whiskey</h3>"; } function brew_beer_sub() { if ($_POST['brewbeer']){ global $db,$ir,$c,$userid,$h,$beer; $beer = rand(1, 6); echo "While brewing away, you managed to brew {$beer} Bottles of Beer!"; item_add($userid, 277, $beer); $db->query("UPDATE users SET brew=brew + 1 WHERE userid=$userid"); $db->query("UPDATE users SET brave=brave - 5 WHERE userid=$userid"); $db->query("UPDATE users SET brew_time=brew_time + 25 WHERE userid=$userid"); } } function drink_beer() { if($itmid['277'] < 1){ echo "You don't have enough beer"; die; }else{ if($_GET['ID'] == 277){ echo "You used 1 beer and gained 20 energy"; item_remove($userid, 277, 1); } } } ?> Quote Link to comment Share on other sites More sharing options...
sniko Posted June 9, 2015 Share Posted June 9, 2015 And how do I do that? Also can you see what's going on with my last function? I only keep getting You don't have enough beer code: <?php require_once("globals.php"); if($ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); } if($ir['brew_time']) { die("You can't brew for another {$ir['brew_time']} minutes, when your current batch finishes."); } if($ir['brew'] == 10) { echo 'You have already brewed 10 times today, come back tomorrow'; $h->endpage(); die; } $_GET['action'] = isset($_GET['action']) && ctype_alpha($_GET['action']) ? strtolower(trim($_GET['action'])) : ''; switch($_GET['action']){ case 'beer': brew_beer(); break; case 'drinkbeer': drink_beer(); break; case 'brewbeer': brew_beer_sub(); break; case 'whiskey': brew_whiskey(); break; default: brewery(); break; } function brewery() { global $db,$ir,$c,$userid,$h; print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <table class='tablee'><tr><td><center><img src='/images/brewery.jpg' /></td></tr></table> <h3>Your Brewery</h3>"; echo " You are sitting in your shed. </br>What would you like to brew?</br>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'>Brewery Options</th> </tr> <tr> <td>Beer</td> <td> <a href='brewery.php?action=beer'>Brew</a> </td> </tr> <tr> <td>Whiskey</td> <td> <a href='brewery.php?action=whiskey'>Brew</a> </td> </tr> </tr> <tr> <td>Cider</td> <td> <a href='brewery.php?action=cider'>Brew</a> </td> </tr> </tr> <tr> <td>Vodka</td> <td> <a href='brewery.php?action=vodka'>Brew</a> </td> </tr> </table> "; print "<h3><font color='red'>This module is a is not complete and still in early production stage.</br> Not all functions will work properly.</font></h3>"; } function brew_beer() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Beer</h3>"; echo " <table width='55%' border='0' cellspacing='1' cellpadding='3' class='table' style='text-align:center;'> <tr> <th colspan='3'> Beer Information</th> </tr> <tr> <td>Time to brew Beer?</td> <td>25 Minutes</td> </tr> <tr> <td>Brave needed to brew Beer?</td> <td>5 Brave</td> </tr> <td>What does beer do?</td> <td>Gives you an energy boost of 25 Energy</td> </tr> </table> <form method='post' action='brewery.php?action=brewbeer'> <input type='submit' name='brewbeer' value='Brew Beer' /> </form> "; } function brew_whiskey() { print "<div class='generalinfo_txt'> <div><img src='images/info_left.jpg' alt='' /></div> <div class='info_mid'><h2 style='padding-top:10px;'>Brewery</h2></div> <div><img src='images/info_right.jpg' alt='' /></div> </div> <div class='generalinfo_simple'> <h3>Whiskey</h3>"; } function brew_beer_sub() { if ($_POST['brewbeer']){ global $db,$ir,$c,$userid,$h,$beer; $beer = rand(1, 6); echo "While brewing away, you managed to brew {$beer} Bottles of Beer!"; item_add($userid, 277, $beer); $db->query("UPDATE users SET brew=brew + 1 WHERE userid=$userid"); $db->query("UPDATE users SET brave=brave - 5 WHERE userid=$userid"); $db->query("UPDATE users SET brew_time=brew_time + 25 WHERE userid=$userid"); } } function drink_beer() { if($itmid['277'] < 1){ echo "You don't have enough beer"; die; }else{ if($_GET['ID'] == 277){ echo "You used 1 beer and gained 20 energy"; item_remove($userid, 277, 1); } } } ?> And how do I do that? Really? Really?!. Click the blue links. *sigh Also can you see what's going on with my last function? Yes. $itmid doesn't exist. Query the inventory table for the item and check the quantity. Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 9, 2015 Author Share Posted June 9, 2015 And how do I do that? Really? Really?!. Click the blue links. *sigh Also can you see what's going on with my last function? Yes. $itmid doesn't exist. Query the inventory table for the item and check the quantity. But the itmid does exist Quote Link to comment Share on other sites More sharing options...
sniko Posted June 9, 2015 Share Posted June 9, 2015 But the itmid does exist Sure, but the variable doesn't. I'm done. Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 9, 2015 Author Share Posted June 9, 2015 Sure, but the variable doesn't. I'm done. What do you mean by the variable? Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted June 9, 2015 Author Share Posted June 9, 2015 [ATTACH]2098[/ATTACH] ^this one is the inventory table^ [ATTACH]2099[/ATTACH] ^and this one is items^ [MENTION=67703]adamhull[/MENTION] is this good enough? Quote Link to comment 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.