Lilith Posted August 12, 2010 Share Posted August 12, 2010 How would you code an item that appears in your inventory, but instead of a "use" link, you get a "throw bomb" (in this case) link that initiates the bomb.php file? Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted August 12, 2010 Share Posted August 12, 2010 Create a new item type. Get the number for the item type. Then in the inventory you can make the link if($i['itmtype'] == xxx) { echo 'Throw Bomb'; } Quote Link to comment Share on other sites More sharing options...
Paul Evans Posted August 12, 2010 Share Posted August 12, 2010 If you wanted to advance it a little more maybe add something like [mysql]ALTER TABLE `items` ADD `itm_addon` varchar(75) NOT NULL DEFAULT '';[/mysql] item simply have something like // due to already fetching all the fields from the table no need for a fetch query if ( !empty($item['itm_addon']) ) { $itm_addon = explode(':', $item['itm_addon']); // this is a optional method you could use the other method below and remove this line // echo $item['itm_addon']; // This relies on itm_addon being formatted into the html when inputting into the db (quite easy to do) echo '[url="'.$itm_addon['0'].'"]'.$itm_addon['1'].'[/url]'; // remove this line if using method on above line } Obviously you'd format it either with html on input or output.. HTML on output (inputting method) // note i can't recall the exact method of MCC item dropdown so i apologise in advance but this is only a example $_POST['name'] = ( isset($_POST['name']) && ctype_alnum($_POST['name']) ) ? $_POST['name'] : 0 ; $_POST['file'] = ( isset($_POST['file']) && is_string($_POST['file']) ) ? $_POST['file'] : 0 ; // this isn't perfect security it's just for the example $_POST['item'] = ( isset($_POST['item']) && ctype_digit($_POST['item']) ) ? $_POST['item'] : 0 ; if ( !empty($_POST['file']) && !empty($_POST['name']) && !empty($_POST['item'] ) { $db->query('UPDATE `item` SET `item_addon` = "'.$_POST['file'].':'.$_POST['name'].'" WHERE `itmid` = '.$_POST['item']); echo 'Updated!'; } else { echo ' <form action="" method="post"> Item: '.item_dropdown('item',$c).' File: <input type="text" name="file" value="" /> Name: <input type="text" name="name" value="" /> <input type="submit" value="Submit" /> </form> '; } HTML on input (inputting method) // note i can't recall the exact method of MCC item dropdown so i apologise in advance but this is only a example $_POST['name'] = ( isset($_POST['name']) && ctype_alnum($_POST['name']) ) ? $_POST['name'] : 0 ; $_POST['file'] = ( isset($_POST['file']) && is_string($_POST['file']) ) ? $_POST['file'] : 0 ; // this isn't perfect security it's just for the example $_POST['item'] = ( isset($_POST['item']) && ctype_digit($_POST['item']) ) ? $_POST['item'] : 0 ; if ( !empty($_POST['file']) && !empty($_POST['name']) && !empty($_POST['item'] ) { $db->query('UPDATE `item` SET `item_addon` = "[url='.$_POST[']'.$_POST['name'].'[/url]" WHERE `itmid` = '.$_POST['item']); echo 'Updated!'; } else { echo ' <form action="" method="post"> Item: '.item_dropdown('item',$c).' File: <input type="text" name="file" value="" /> Name: <input type="text" name="name" value="" /> <input type="submit" value="Submit" /> </form> '; } Hope this helps Quote Link to comment Share on other sites More sharing options...
Lilith Posted August 17, 2010 Author Share Posted August 17, 2010 wow! Both methods are extremely helpful! I really appreciate the effort put into your answers. Ill probably use Zu's method just because I can modify it to fit several needs with my coding abilities at this time, but Paul has defiantly given me something to play with to improve those abilities. Quote Link to comment Share on other sites More sharing options...
LordDan Posted August 17, 2010 Share Posted August 17, 2010 Last time i did this i used an include rather than going to the page itself. if( isset( $_POST['use_item'] ) ){ if( !empty( $item['itm_addon'] ) ){ include( './modules/item_functions/'.$item['item_addon'].'.php' ); } else { // Stuff to run normal item functions.. } } Quote Link to comment Share on other sites More sharing options...
Paul Evans Posted August 17, 2010 Share Posted August 17, 2010 My method is basically a more complex version of Zu's simple method (no offence intended it's a good answer mate) i just thought i'd spend a little time on something which i will have on my game, it would work on the same premiss as zu's method just a little bit more complex and less actual coding into the inventory file (considering you'd have multiple files which want their own use method). Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted August 17, 2010 Share Posted August 17, 2010 No offence taken tbh my solution was for the novice. I do like you suggestion and Lord Dan's On Zu its decided what the item does after its been selected by the player and how they intend to use it. Means the item is not always restricted to one single pre-defined use. For example if you use item A it does this. However if you use item A but have in stock item B then it can do this if you have learnt the way to do so and so on. 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.