Jump to content
MakeWebGames

Items that initiate or link to a php file


Lilith

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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..
   }
}
Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...