Mys 1.3.4 Item Shop Mod(s): NPC + Item Display + Tooltips

Forum
Last Post
Threads / Messages
@Ittermat In class_itemshop.php, you basically replace the whole public function display section. Clicking the first opening bracket next to 'public function display' should also highlight the closing bracket. So you take everything inside that, erase it, and replace with new code. Make sure to save your original code first.
 
End at the end of the display function. Brackets always line up. You'll have to see where that function ends. In a text editor meant for code, such as Sublime Text 2 or Notepad++, syntax highlighting will help you recognize where code ends and begins, and as Tahbikat said, if you click on a bracket, the closing bracket will highlight itself, showing where it ends.

Anyway, obviously one function must end before the next begins. Just look for the start of the next one?
 
For some reason tool tips will not work (in shop or inventory) even after following all the steps. I'm not sure if it's because I'm using the bookstore theme. I double checked the tootip.css, tooltip.js and the header file.
 
Does that theme have jQuery? If not, include a link to the jQuery library. For the tooltips to work, its .js file must come after jQuery, as it is dependant on it. Keep in mind that this may break your profile pages since they come with their own link to jQuery and having two links to different versions will cause errors on that page!

This should have been covered in section 2, in the third code block.
 
Last edited:
I did follow that part as well but no luck. So I thought i'd ask just in case. I'm going to go over it a third time to see if I missed something.
 
Last edited:
Unrelated to my last post but I'm having a issue with key items being able to be sold in the inventory.

I saw:
if($item->category !== "Key Items") {

So I assumed if the category was "Key Items" that would fix it but I got a error.
Catchable fatal error: Argument 1 passed to GUIContainer::add() must be an instance of GUIComponent, null given, called in /home/monstari/public_html/view/inventoryview.php on line 72 and defined in /home/monstari/public_html/classes/class_guicontainer.php on line 361

I tried to I tried to figure it out but I am stumped. I am not to far along my php studies so maybe the fix is right in front of my face but I can't see it.
 
About the Inventory - you're absolutely right, although... I was going off of existing code in class_itemtablehelper.php, which used if($item->category == "Key Items") return "N/A"; . . . . obviously, yeah, that'd only take effect if the item's category was "Key Items".

It'd probably be better to check for $item->function.

I updated the chunk of code above, but also here -
PHP:
    public function index(){
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $document->setTitle($mysidia->lang->inventory);
        
        $inventory = $this->getField("inventory");
        
        $document->add(new Comment(" <style>
                .sc_item {
                  display: inline-table;
                  padding: 5px;
                  text-align: center;
                  font-family: 'Trebuchet MS', Helvetica, sans-serif;
                  font-size: 14px;
                  margin-bottom: 3px;
                  width: 120px;
                }
                .s_panel {
                  border-radius: 2px;
                  border: 1px solid #CCC;
                  background-color: #FBFDF2;  
                }
            </style> ", FALSE));
        $iids = $inventory->getiids();
        for($i = 0; $i < $iids->length(); $i++){
            $item = $inventory->getitem($iids[$i]);
                 
            # Descriptions of the item functions
            switch ($item->function) {
                case "Click1": $usage = "<br/><b>use:</b> Feed a pet to give them {$item->value} EXP."; break;
                case "Click2": $usage = "<br/><b>use:</b> Feed a pet to set their EXP to {$item->value}."; break;
                case "Click3": $usage = "<br/><b>use:</b> Resets EXP earned today to 0."; break;
                case "Level1": $usage = "<br/><b>use:</b> Raises the Level of your pet by {$item->value}."; break;
                case "Level2": $usage = "<br/><b>use:</b> Sets the Level of your pet to {$item->value}."; break;
                case "Level3": $usage = "<br/><b>use:</b> Makes your pet Level 0 again!"; break;
                case "Gender": $usage = "<br/><b>use:</b> Swaps the gender of your pet to its opposite!"; break;            
                default;
                    $usage = ""; break;
            }  # End item function descriptions        

            
            # Rendering items now
            $document->add(new Comment("
            <div class=\"s_panel sc_item\">
            <img rel=\"tooltip\" title=\"{$item->description} <em>{$usage}</em>\" src=\"{$item->imageurl}\"/><br/>
              <b>{$item->itemname}</b><br> Own ×{$item->quantity}<br/>", FALSE));

            # If item is consumable, add use button
            if($item->consumable == "yes") {
                $useForm = new FormBuilder("useform", "inventory/uses", "post");
                $useForm->setLineBreak(FALSE);
                $useForm->buildPasswordField("hidden", "action", "uses")
                        ->buildPasswordField("hidden", "itemname", $item->itemname)
                        ->buildButton("Use", "use", "use");
                $document->add($useForm);
            }

            # Add sellback button so long as the item is not a key item
            $sellback = $item->price / 2;
            $document->add(new Comment("<hr>{$sellback} {$mysidia->settings->cost} Each ", FALSE));
            if($item->function !== "Key") {
                $sellForm = new FormBuilder("sellform", "inventory/sell", "post");
                $sellForm->setLineBreak(FALSE);
                $sellForm->buildPasswordField("hidden", "action", "sell")
                         ->buildPasswordField("hidden", "itemname", $item->itemname);
                
                $quantity = new TextField("quantity");
                $quantity->setSize(3);
                $quantity->setMaxLength(3);
                $quantity->setLineBreak(FALSE);

                $sell = new Button("Sell", "sell", "sell");
                $sell->setLineBreak(FALSE);

                $sellForm->add($quantity);
                $sellForm->add($sell);
            }    
            $document->add($sellForm);
            $document->add(new Comment("</div>", FALSE));   

        } # END item for loop

    } # END index function

If the problem persists, perhaps try changing it to "!=" instead of "!==".

Anyway, do the tooltips work on the Inventory, but not elsewhere? Do any of your item names or descriptions happen to have apostrophes or quotations in them (this might be relevant and would be good to know, I thought I'd caught all of this).
 
I seem to be getting the same error even after changing the !== to !=

Catchable fatal error: Argument 1 passed to GUIContainer::add() must be an instance of GUIComponent, null given, called in /home/monstari/public_html/view/inventoryview.php on line 72 and defined in /home/monstari/public_html/classes/class_guicontainer.php on line 361

As for tooltips they do show up in both shops and the inventory but as plan boxes. I did move the CSS to the main theme but I don't think that's it either.

02334_by_grand_corsair-d9ruuyf.png


I'm not sure if it's related but I've been noticing errors with drop downs and radio buttons related to this GUIContainer even in the admin panel where I have your bootstrap theme installed.
 
Themes don't even modify core files, so I don't see how the two are related.

Please paste your entire inventoryview.php file. And, if you can, please link me to the site so I can see the problem first hand and confirm you have jQuery installed once and only once and in the correct location. I hope we get this figured out. ^^;
 
Thanks for being so penitent. I am still trying to get a handle on this php thing.

http://monstari.mysidiahost.com/index
PHP:
<?php

use Resource\Collection\LinkedList;

class InventoryView extends View{
	
	 public function index(){
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $document->setTitle($mysidia->lang->inventory);
        $document->addLangvar("You may manage these items as you like, or go to the alchemy page to make your own items: <br>");    
        $document->add(new Link("inventory/alchemy", "Go to Alchemy Laboratory!"));    
        $document->add(new Comment("<br><br>")); 
        
        $inventory = $this->getField("inventory");
        
        
        $iids = $inventory->getiids();
        for($i = 0; $i < $iids->length(); $i++){
            $item = $inventory->getitem($iids[$i]);
                 
            # Descriptions of the item functions
            switch ($item->function) {
                case "Click1": $usage = "<br/><b>use:</b> Feed a pet to give them {$item->value} EXP."; break;
                case "Click2": $usage = "<br/><b>use:</b> Feed a pet to set their EXP to {$item->value}."; break;
                case "Click3": $usage = "<br/><b>use:</b> Resets EXP earned today to 0."; break;
                case "Level1": $usage = "<br/><b>use:</b> Raises the Level of your pet by {$item->value}."; break;
                case "Level2": $usage = "<br/><b>use:</b> Sets the Level of your pet to {$item->value}."; break;
                case "Level3": $usage = "<br/><b>use:</b> Makes your pet Level 0 again!"; break;
                case "Gender": $usage = "<br/><b>use:</b> Swaps the gender of your pet to its opposite!"; break;            
                default;
                    $usage = ""; break;
            }  # End item function descriptions        

            
            # Rendering items now
            $document->add(new Comment("
            <div class=\"s_panel sc_item\">
            <img rel=\"tooltip\" title=\"{$item->description} <em>{$usage}</em>\" src=\"{$item->imageurl}\"/><br/>
              <b>{$item->itemname}</b><br> Own ×{$item->quantity}<br/>", FALSE));

            # If item is consumable, add use button
            if($item->consumable == "yes") {
                $useForm = new FormBuilder("useform", "inventory/uses", "post");
                $useForm->setLineBreak(FALSE);
                $useForm->buildPasswordField("hidden", "action", "uses")
                        ->buildPasswordField("hidden", "itemname", $item->itemname)
                        ->buildButton("Use", "use", "use");
                $document->add($useForm);
            }

           # Add sellback button so long as the item is not a key item
            $sellback = $item->price / 2;
            $document->add(new Comment("<hr>{$sellback} {$mysidia->settings->cost} Each ", FALSE));
            if($item->function != "Key") {
                $sellForm = new FormBuilder("sellform", "inventory/sell", "post");
                $sellForm->setLineBreak(FALSE);
                $sellForm->buildPasswordField("hidden", "action", "sell")
                         ->buildPasswordField("hidden", "itemname", $item->itemname);
                
                $quantity = new TextField("quantity");
                $quantity->setSize(3);
                $quantity->setMaxLength(3);
                $quantity->setLineBreak(FALSE);

                $sell = new Button("Sell", "sell", "sell");
                $sell->setLineBreak(FALSE);

                $sellForm->add($quantity);
                $sellForm->add($sell);
            }    
            $document->add($sellForm);
            $document->add(new Comment("</div>", FALSE));   

        } # END item for loop

    } # END index function  
			
	public function uses(){
		$mysidia = Registry::get("mysidia");
		$document = $this->document;	
		if($mysidia->input->post("aid")){
		    $message = (string)$this->getField("message");
		    $document->setTitle($mysidia->lang->global_action_complete);
            $document->addLangvar($message);
            return;		
		}
		
		$petMap = $this->getField("petMap");
		$document->setTitle($mysidia->lang->select_title);
        $document->addLangvar($mysidia->lang->select);		
		$chooseFrom = new Form("chooseform", "uses", "post");
		
		$adoptable = new DropdownList("aid");
		$adoptable->add(new Option("None Selected", "none"));
        if($petMap->size() > 0){
            $iterator = $petMap->iterator();
            while($iterator->hasNext()){
                $adopt = $iterator->nextEntry();
                $adoptable->add(new Option($adopt->getValue(), $adopt->getKey()));
            }
        }		
		$chooseFrom->add($adoptable);
		
		$chooseFrom->add(new PasswordField("hidden", "itemname", $mysidia->input->post("itemname")));
		$chooseFrom->add(new PasswordField("hidden", "validation", "valid"));
		$chooseFrom->add(new Button("Choose this Adopt", "submit", "submit"));
        $document->add($chooseFrom);
	}
	
	public function sell(){
		$mysidia = Registry::get("mysidia");
		$document = $this->document;
		$document->setTitle($this->lang->global_transaction_complete);
		$document->addLangvar("{$this->lang->sell}{$mysidia->input->post("quantity")} {$mysidia->input->post("itemname")} {$this->lang->sell2}");
	}
	
	public function toss(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;
		if($mysidia->input->get("confirm")){
			$document->setTitle($this->lang->global_action_complete);
	        $document->addLangvar("{$this->lang->toss}{$mysidia->input->post("itemname")}{$this->lang->toss2}");
	        return;
		}
	
		$document->setTitle($this->lang->toss_confirm);
		$document->addLangvar($this->lang->toss_warning);	

		$confirmForm = new FormBuilder("confirmform", "toss/confirm", "post");
		$confirmForm->buildPasswordField("hidden", "action", "toss")
		            ->buildPasswordField("hidden", "itemname", $mysidia->input->post("itemname"))
					->buildButton("Please Toss", "confirm", "confirm");
		$document->add($confirmForm);			
	}
public function alchemy(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;
		
		if($mysidia->input->post("iid") and $mysidia->input->post("iid2")){
		    $alchemy = $this->getField("alchemy");
			$newitem = $alchemy->getNewItem()->itemname;
            $document->setTitle($this->lang->alchemy_success);
            $document->addLangvar($this->lang->alchemy_newitem.$newitem.$this->lang->alchemy_newitem2);	
            return;		
		}

		$document->setTitle($this->lang->alchemy_title);
        $document->addLangvar($this->lang->alchemy);
        $itemMap = $this->getField("itemMap");
		$settings = $this->getField("settings");
    	$alchemyFrom = new Form("alchemyform", "alchemy", "post");
		$alchemyFrom->add(new Comment("<b>Cost of performing Alchemy: {$settings->cost} {$mysidia->settings->cost}</b><br>"));
		
        $alchemyFrom->add(new Comment($mysidia->lang->alchemy_choose));		
		$items = new DropdownList("iid");
		$items->add(new Option("None Selected", "none"));
        if($itemMap->size() > 0){
            $iterator = $itemMap->iterator();
            while($iterator->hasNext()){
                $item = $iterator->nextEntry();
                $items->add(new Option($item->getValue(), $item->getKey()));
            }
        }		
		$alchemyFrom->add($items);

        $alchemyFrom->add(new Comment($mysidia->lang->alchemy_choose2));		
		$items2 = new DropdownList("iid2");
		$items2->add(new Option("None Selected", "none"));
        if($itemMap->size() > 0){
            $iterator = $itemMap->iterator();
            while($iterator->hasNext()){
                $item2 = $iterator->nextEntry();
                $items2->add(new Option($item2->getValue(), $item2->getKey()));
            }
        }		
		$alchemyFrom->add($items2);		
		$alchemyFrom->add(new Button("Let's mix the items now!", "submit", "submit"));
        $document->add($alchemyFrom);		
	}
}
?>
 
Mkay, I copy-pasted in your exact file and I have no errors at all? There is no reason you should be having an error on line 72 and not much sooner. Do you have the error without the Alchemy mod installed (I've never used it)? I doubt it would interfere, but it's worth checking...

Can you try moving
HTML:
<!-- Scripts -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> 
<script src="/js/tooltip.js"></script>
<script src="/js/tabs.js"></script>
<script>
$(function() { $("#profile").organicTabs(); });
</script>
<!-- Script end -->
into your header instead of your footer for me? Have you tried this yet? Does it make a difference for the tooltips?
 
Ok so weird thing. I removed everything and can still sell key items so even if I removed your mod I still can sell key items. whelp

Edit:

Ok so I did a fresh install and followed the installation. Installed this mod and got the same error.
 
Last edited:
It's quite bizarre that two other people have this mod installed on their site, other than myself, just fine and never experienced fatal errors. Yet, no matter how much I search, I can't find any helpful reference to a similar error that they would have fixed elsewhere. My classes/class_guicontainer.php and classes/class_guicomponent.php files identical to the default install!

EDIT: I can actually recreate your error... if you followed the instructions wrong, you replaced your entire view/inventoryview.php file instead of replacing only the index() function as instructed. Try replacing your entire file with this (or go back and follow the instructions more carefully):
  Spoiler: replace inventoryview.php 
PHP:
<?php

use Resource\Collection\LinkedList;

class InventoryView extends View{
	
	public function index(){
        $mysidia = Registry::get("mysidia");
        $document = $this->document;
        $document->setTitle($mysidia->lang->inventory);
        
        $inventory = $this->getField("inventory");
        
        $document->add(new Comment(" <style>
                .sc_item {
                  display: inline-table;
                  padding: 5px;
                  text-align: center;
                  font-family: 'Trebuchet MS', Helvetica, sans-serif;
                  font-size: 14px;
                  margin-bottom: 3px;
                  width: 120px;
                }
                .s_panel {
                  border-radius: 2px;
                  border: 1px solid #CCC;
                  background-color: #FBFDF2;  
                }
            </style> ", FALSE));
        $iids = $inventory->getiids();
        for($i = 0; $i < $iids->length(); $i++){
            $item = $inventory->getitem($iids[$i]);
                 
            # Descriptions of the item functions
            switch ($item->function) {
                case "Click1": $usage = "<br/><b>use:</b> Feed a pet to give them {$item->value} EXP."; break;
                case "Click2": $usage = "<br/><b>use:</b> Feed a pet to set their EXP to {$item->value}."; break;
                case "Click3": $usage = "<br/><b>use:</b> Resets EXP earned today to 0."; break;
                case "Level1": $usage = "<br/><b>use:</b> Raises the Level of your pet by {$item->value}."; break;
                case "Level2": $usage = "<br/><b>use:</b> Sets the Level of your pet to {$item->value}."; break;
                case "Level3": $usage = "<br/><b>use:</b> Makes your pet Level 0 again!"; break;
                case "Gender": $usage = "<br/><b>use:</b> Swaps the gender of your pet to its opposite!"; break;            
                default;
                    $usage = ""; break;
            }  # End item function descriptions        

            
            # Rendering items now
            $document->add(new Comment("
            <div class=\"s_panel sc_item\">
            <img rel=\"tooltip\" title=\"{$item->description} <em>{$usage}</em>\" src=\"{$item->imageurl}\"/><br/>
              <b>{$item->itemname}</b><br> Own ×{$item->quantity}<br/>", FALSE));

            # If item is consumable, add use button
            if($item->consumable == "yes") {
                $useForm = new FormBuilder("useform", "inventory/uses", "post");
                $useForm->setLineBreak(FALSE);
                $useForm->buildPasswordField("hidden", "action", "uses")
                        ->buildPasswordField("hidden", "itemname", $item->itemname)
                        ->buildButton("Use", "use", "use");
                $document->add($useForm);
            }

            # Add sellback button so long as the item is not a key item
            $sellback = $item->price / 2;
            $document->add(new Comment("<hr>{$sellback} {$mysidia->settings->cost} Each ", FALSE));
            if($item->category != "Key Items") {
                $sellForm = new FormBuilder("sellform", "inventory/sell", "post");
                $sellForm->setLineBreak(FALSE);
                $sellForm->buildPasswordField("hidden", "action", "sell")
                         ->buildPasswordField("hidden", "itemname", $item->itemname);
                
                $quantity = new TextField("quantity");
                $quantity->setSize(3);
                $quantity->setMaxLength(3);
                $quantity->setLineBreak(FALSE);

                $sell = new Button("Sell", "sell", "sell");
                $sell->setLineBreak(FALSE);

                $sellForm->add($quantity);
                $sellForm->add($sell);
                            $document->add($sellForm);
            }    

            $document->add(new Comment("</div>", FALSE));   

        } # END item for loop

    } # END index function  
	
	public function sell(){
		$mysidia = Registry::get("mysidia");
		$document = $this->document;
		$document->setTitle($this->lang->global_transaction_complete);
		$document->addLangvar("{$this->lang->sell}{$mysidia->input->post("quantity")} {$mysidia->input->post("itemname")} {$this->lang->sell2}");
	}
	
	public function toss(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;
		if($mysidia->input->get("confirm")){
			$document->setTitle($this->lang->global_action_complete);
	        $document->addLangvar("{$this->lang->toss}{$mysidia->input->post("itemname")}{$this->lang->toss2}");
	        return;
		}
	
		$document->setTitle($this->lang->toss_confirm);
		$document->addLangvar($this->lang->toss_warning);	

		$confirmForm = new FormBuilder("confirmform", "toss/confirm", "post");
		$confirmForm->buildPasswordField("hidden", "action", "toss")
		            ->buildPasswordField("hidden", "itemname", $mysidia->input->post("itemname"))
					->buildButton("Please Toss", "confirm", "confirm");
		$document->add($confirmForm);			
	}
}
?>

Anyway, yeah, the Key item thing seems to be a bug or afterthought with the baseline Mysidia framework... by the sounds of it. In classes/class_itemtablehelper.php, the category "Key Items" is referenced twice, rather than the function "Key". I literally just imitated the existing file to render the form, so I copied over the same error.

However, if I do create an item with the category "Key Items" on a default install, it renders as expected on a default install of Mysidia (you can never sell key items). I cannot actually recreate your problem on a default install whatsoever.

  Spoiler: screenshot of default install with key items working as intended 
defaultkeyitem_by_kyttias-d9rx8qh.png


So, this DOES come down to being a bug with my mod, AND I managed to fix it. The fix is in the file above. (I moved $document->add($sellForm); inside the if statement, because that makes more sense, anyway. The variable should have still never been built to display, anyway... but apparently it was?)
 
Last edited:
I'm not sure either. I installed a fresh new install and before adding anything I tested it and it came up a error. I installed it as the guide said. Other then that everything else with the mode is working. Until I can figure this out I'll have to warn people not to sell their key items.

As for tooltips they are working now. I'm not sure what happened but that much is cleared up. I must have installed something that broke it.
 
I made some edits to my last post that should clear everything up. I'm glad the tooltips are working!

edit: And made one last edit to my previous post @ 8:53 EST. Thanks for catching the Key Item thing, it apparently was my fault! I hadn't created a Key Item yet to test, and all I had to do was move one line only slightly. ^^;;;
 
Last edited:
I can't thank you enough. I need to make sure to install mods more carefully. Everything seems to be working now.
 
I'm glad everything got sorted out. :usedusedused: Maybe it'll help someone in the future!
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,119
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top