Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Mys v1.3.x Mods (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=42)
-   -   Mys v1.3.4 Abron's Background Mod (http://www.mysidiaadoptables.com/forum/showthread.php?t=5405)

Abronsyth 04-05-2017 10:51 AM

Abron's Background Mod
 
Hey all!

So I got this feature fully functional on my website and figured I would share it with you all! This is loosely inspired by Hwona's BG Mod for 1.3.3, but this version is strictly for 1.3.4.

What This Mod Does
Lets admins create backgrounds as items for users to purchase/get/etc
The item image is the background (the script uses the image URL)
Users can assign background to a pet, only one at a time
Users can remove an assigned background, and have it readded to their inventory
Users cannot assign a background to a pet that already has a background
They cannot remove a background if the pet doesn't have a background

Now let's get started!
The first thing we're going to do is make a new item function. Go into your database and run the following SQL:
PHP Code:

INSERT INTO `adopts_items_functions` (`ifid`, `function`, `intent`, `description`) VALUES
(14'Background''Adoptable''A background image for an adoptable.'); 

***Change 14 to which ID should come after the newest item function in the table adopts_items_functions in your database***

Now let's open up the file functions/functions_items, scroll all the way to the bottom and paste this just before the closing ?> tag.
PHP Code:

function items_background($item$adopt){
  
$mysidia Registry::get("mysidia");
  
  if(
$adopt->adoptbackground == 'http://YOURSITE.COM/backgrounds/default.png'){
  
$mysidia->db->update("owned_adoptables", array("adoptbackground" => $item->imageurl), "aid ='{$adopt->aid}' and owner='{$item->owner}'");
  
$note "You have changed your pet's background!";
  
$delitem $item->remove();
  }
  else{
  
$note "Your pet already has a background set, go to your <a href='http://YOURSITE.COM/myadopts/manage/{$adopt->aid}'>pet's page</a> to remove the current background before assigning a new one.";
  }
  return 
$note;


Where it says YOURSITE.COM change it to your site's URL.

Lastly for the item function go into classes/class_privateitem and paste this bit before the default case, under public function apply:
PHP Code:

case "Background":
$message items_background($this$owned_adoptable);
break; 

Now we are going to create a new folder in the root directory called backgrounds. Make sure you put a .htaccess file in there so it is accessible! You will need to add a default background in this file and call it default.png. I use a transparent image, like this (right click, save as):
http://orig09.deviantart.net/4530/f/...re-db4r1v6.png

Time for another database edit. Go to phpmyadmin and go to adopts_owned_adoptables. Go to structure and click to add one (1) column to the end of the table. Enter these details:
Name: adoptbackground
Type: varchar(500)
Collation: latin1_swedish_ci
Null: YES
Default: AS DEFINED: http://YOURSITE.COM/backgrounds/default.png

That done, let's head on to the remove function. Open up your myadopts.php file and paste this after the closing } of the freeze function:
PHP Code:

public function removebg(){
$mysidia Registry::get("mysidia");  
$this->setField("adopt"$this->adopt);             



Now for the "fun" part (that gave me a headache for three days). Go into your view/myadoptsview file and add this after the closing } of the freeze function:
PHP Code:

    public function removebg(){
        
$mysidia Registry::get("mysidia");    
        
$adopt $this->getField("adopt");    
        
$document $this->document;
        
$oldbg $mysidia->db->select("items", array("itemname"), "imageurl = '{$adopt->adoptbackground}'")->fetchColumn();
        
$bg $mysidia->db->select("owned_adoptables", array("adoptbackground"), "aid = '{$adopt->aid}'")->fetchColumn();
    
        if (
$bg == "http://YOURSITE.COM/backgrounds/default.png") {$document->setTitle("Error");
        
$document->add(new Comment("Your pet does not have a background assigned."));
        
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=http://YOURSITE.COM/myadopts/manage/{$adopt->aid}' />"));}
        
        elseif (
$bg != "http://YOURSITE.COM/backgrounds/default.png") {  
        
$item $oldbg;
                
$qty 1;
                
$newitem = new StockItem($item);
                
$newitem->append($qty$mysidia->user->username);
        
$mysidia->db->update("owned_adoptables", array("adoptbackground" => "http://YOURSITE.COM/backgrounds/default.png"), "aid ='{$adopt->aid}' and owner='{$mysidia->user->username}'"); 
               
$document->setTitle("Background Removed");
               
$document->add(new Comment("Your pet's background has been removed, and the item has been added back to your inventory."));
               
$document->add(new Comment("<meta http-equiv='refresh' content='1;url=http://YOURSITE.COM/myadopts/manage/{$adopt->aid}' />"));}
    
    } 

We want users to actually be able to use it, so somewhere on the myadopts page, under the manage function, you will need to add this link:
Code:

<a href='../../myadopts/removebg/{$aid}'>Remove Background</a>

Now to put the background into use! Overall it is really easy, you can simply call it through this:
$this->adopt->adoptbackground OR $adopt->adoptbackground

I set it up in my pet profiles this way:
PHP Code:

<td style='background-image:url({$adopt->adoptbackground;});background-repeat: no-repeat;background-position:center;border-top:1px #000 solid;border-bottom:1px #000 solid;vertical-align:bottom;height:155px;'><img src='{$adopt->getImage()}'></td

But how you do it is up to you.

Finally, to add a background! Upload your background image wherever (doesn't really matter), and go into your AdminCP to add a new item. Make the background item consumable and obviously set the function type to background. The Item Image is what the background itself will appear as.

IMPORTANT NOTE ABOUT BACKGROUND SIZES
I HIGHLY advise you make all backgrounds the same size, and base that size off of the largest pet image used on your website. It'll look wonky otherwise.


Alright, that should be everything! If anyone has any questions/comments/concerns, please let me know!
http://img15.deviantart.net/0121/i/2...re-db4r4lh.png

Pear 04-05-2017 01:12 PM

Oooh, looks neat! :3

Dinocanid 04-05-2017 02:08 PM

Thanks for sharing this! What I was trying to do with backgrounds just wasn't working lol

Bexasaurus 04-07-2017 10:52 PM

Noting that "Users can assign background to a pet, only one at a time."

Every pet is able to a have a background, just not multiple ones...correct? :desudesudesu:

Abronsyth 04-08-2017 01:53 PM

Yes, only one background at a time! So if a pet already has a background assigned a user will be asked to remove it before assigning a new one :)

darrinm3 05-02-2017 11:22 AM

Thanks for the script! Got a quick question. I have everything working, up to actually calling the background. What file did you put that php snippet in? Any details about that step would be great. Thanks again!

Abronsyth 05-02-2017 01:17 PM

I have pet profiles set up both for users managing their pets, and for those who click pets. So I want the backgrounds to display for those profiles, and set them up in the two files:
myadoptsview.php
levelup.php

In myadoptsview.php you call it this way {$adopt->adoptbackground}, and in levelup.php it's like this {$this->adopt->adoptbackground}. This calls the url of the background image, so you'll need to put it in image tags, like so:
PHP Code:

<img src='{$adopt->adoptbackground}'

or
PHP Code:

<div style='background:{$adopt->adoptbackground};'>(div elements here)</div

Or other similar methods.

Let me know if that helps!

darrinm3 05-03-2017 09:29 AM

Thanks for the reply! I'm totally new to PHP so bear with me on this one (HTML,CSS, and Javascript are all I really know). Under what function would I create the div/call the background? Again thanks for the help!

Abronsyth 05-03-2017 09:40 AM

That depends on which page you're adding it to? Let me know the file and I can help out :)

darrinm3 05-03-2017 09:43 AM

Oops sorry! I'm adding it to the the myadoptsview.php file.

Abronsyth 05-03-2017 03:00 PM

Okie dokie, so you'll need to put it in the manage function. (Assuming you want it to appear while a user is managing an individual pet).
You can do it like this:

Under the manage function you'll see this:
PHP Code:

        $mysidia Registry::get("mysidia");
        
$aid $this->getField("aid")->getValue();
        
$name $this->getField("name")->getValue();
        
$image $this->getField("image");
        
        
$document $this->document;        
        
$document->setTitle("Managing {$name}");
        
$document->add($image);
        
$document->add(new Comment("<br><br>This page allows you to manage {$name}.  Click on an option below to change settings.<br>")); 

Now remove the $document->add($image);. Go to the new Comment below that and replace the text within the " " with this:
PHP Code:

<div style='background:{$adopt->background} no-repeat;vertical-align:bottom;text-align:center;'><img src='{$adopt->getImage()}'/></div><br><br>This page allows you to manage {$name}.  Click on an option below to change settings.<br

I think that should work, though I haven't tested it because my manage function is heavily modified, so I had to find the original and edit it.

darrinm3 05-04-2017 08:17 AM

Sorry to keep bothering you, but it still doesn't work. It's givin me a blank page (syntax error on "<img src='{$adopt->getImage()}'/>" and when I get rid of it, the background still doesn't show. I've tried all sorts of things but for some reason can't get it. I even tried echoing the {$adopt->background} inside the style to see if that helped but still nothing.

kristhasirah 05-04-2017 09:01 AM

to call the background you must use the same name given in the owned_adoptables database, so if you used the same name posted here: adoptbackground then the correct way to call it it would be: {$adopt->adoptbackground} and the way to call the adopt image is the one you posted: <img src='{$adopt->getImage()}'/> dont know why is giving you a syntax error...=\

darrinm3 05-04-2017 09:20 AM

That was a typo in my comment, oops! Here is the code I use which gives me a 500 error:

public function manage(){
$mysidia = Registry::get("mysidia");
$aid = $this->getField("aid")->getValue();
$name = $this->getField("name")->getValue();
$image = $this->getField("image");

$document = $this->document;
$document->setTitle("Managing {$name}");
$document->add(new Comment("<div style='background:{$adopt->adoptbackground} no-repeat;vertical-align:bottom;text-align:center;width:100px;height:400px'><img src='{$adopt->getImage()}'/></div><br><br>This page allows you to manage {$name}. Click on an option below to change settings.<br> "));


Here is what happens with the same code except I removed the "img src" tag" (I gave it a height and width to show the div was being created and modified):
http://imgur.com/a/obD4g

Thanks for the help guys.

Abronsyth 05-04-2017 10:01 AM

Alright, so it's failing to call the background URL. What should the URL appear as for that adoptable?

Okay, so this is what I have for my site:
PHP Code:

<td style='background-image:url({$adopt->background});background-repeat: no-repeat;background-position:center;border-top:1px #000 solid;border-bottom:1px #000 solid;vertical-align:bottom;height:155px;'><img src='{$adopt->getImage()}'></td

Try replacing style='background:{$adopt->adoptbackground} no-repeat;vertical-align:bottom;text-align:center;width:100px;height:400px' with this:
PHP Code:

style='background-image:url({$adopt->background});background-repeat: no-repeat;background-position:center;vertical-align:bottom;height:400px;width:100px;' 


NobodysHero 03-30-2018 03:46 PM

Heya! I'd love to get this working, but the background image isn't showing up on the pet. Halp?

My code isn't throwing any errors, so not really sure where to go from here. I've tried it in a few different places, but every time nothing changes.

This is the line of code Dinocaid helped me put together, but it's not working either:

PHP Code:

$document->add(new Comment("<div style='background-image:url('{$adopt->adoptbackground}');background-repeat: no-repeat;background-position:center;'><img src='{$adopt->getImage()}'></img></div>);"

I've already uploaded an image and made it a background item, then used it on my pet. I've removed the code from all the pages so my users can still see their pets in the meantime.

Thanks for any help!

draugluin 08-17-2018 04:34 AM

@ Abronsyth

cool. Thank you very much for for sharings this :)

@ Nobody

Have you try it with

PHP Code:

... $adopt->getadoptbackground ... 

?

this works for me :wutno:

Nairi 10-03-2018 11:50 AM

Hi (sorry for my bad english, i'm from germany :D ),

i tried to bring the background to my game, but i'ts dont show =/ and when i try to show the pet-picture, i became an error:

Code:

Fatal error: Call to a member function getImage() on null in /users/equino/www/view/myadoptsview.php on line 135
That's the Line:
PHP Code:

        $document->add(new Comment(" <div style='background-image:url:{$adopt->adoptbackground} no-repeat;vertical-align:bottom;text-align:center;width:400px;height:283px'><img src='{$adopt->getImage()}'></div><br><br>This page allows you to manage {$name}.  Click on an option below to change settings.<br> 

can anyone help me? :)
btw i hope you understand me :coloness:

draugluin 10-04-2018 02:58 AM

Hey Nairi ... endlich mal jemand aus der Heimat :happyc:

hast du unter "Public function manage" stehen

PHP Code:

$image $this->getField("image");
$adopt = new OwnedAdoptable($aid); 

?

und versuch es mal mit getadoptbackground

PHP Code:

..... background-image:url:{$adopt->getadoptbackground


Nairi 10-04-2018 05:08 AM

Hey :)

Na, das ist ja klasse.

Also das Bild vom Haustier wird nun angezeigt, danke :)
Der Hintergrund aber leider noch immer nicht. Sehr mysteriös

draugluin 10-04-2018 06:01 AM

ich hab bei dem Bild auch ziemlich rumprobiert, bis es ging...

versuchs mal mit

PHP Code:

{$adopt->getadoptbackground()} 

wichtig sind da die beiden Klammern

Nairi 10-04-2018 11:36 AM

Okay, ich habs versucht. Nun kommt folgende Fehlermeldung:
Code:

Fatal error: Call to undefined method OwnedAdoptable::getadoptbackground() in /users/equino/www/view/myadoptsview.php on line 146
Die Zeile sieht nun so aus:
PHP Code:

        $document->add(new Comment(" <div style='background-image:url:{$adopt->getadoptbackground()};background-repeat: no-repeat;vertical-align:bottom;text-align:center;width:400px;height:283px'><img src='{$adopt->getImage()}'></div><br><br>This page allows you to manage {$name}.  Click on an option below to change settings.<br> 

Unglaublich :D Ich habe jetzt schon diverses Versucht, aber irgendwie will es einfach nicht.

Edit: Ohne das get habe ich es gerade auch versucht. Gleiche Fehlermeldung.

Edit 2: Ich hab jetzt mal versucht das Hintergrundbild überhaupt anzeigen zu lassen via <img src={$adopt->adoptbackground}> und das wird angezeigt. Nur im Div-Bereich nicht.

Edit 3: Yeah, ich habs hinbekommen :D So siehts aus und funktioniert.
PHP Code:

<div style='background-image: url({$adopt->adoptbackground});background-repeat: no-repeat;vertical-align:bottom;text-align:center;width:400px;height:283px'><img src='{$adopt->getImage()}'></div


draugluin 10-05-2018 01:38 AM

Hey, Glückwunsch.

es ist immer wieder faszinierend, wenn man was selber hinkriegt :)
Aber manchmal kann man auch dran verzweifeln ... und plötzlich klappts doch.

Nairi 10-05-2018 11:55 AM

Danke :)

Eine Frage habe ich aber noch: nun klebt das Pet-Bild oben am Rand des Hintergrundes. Wie bekomme ich das jetzt mittig? Ich stehe gerade völlig auf dem Schlauch.

draugluin 10-08-2018 02:32 AM

gerne.

wenn ich deine Zeile bei mir einfüge, ist das Pet-Bild aber mittig.
Das sagt ja auch der Teil : text-align:center.

Wenns gar nicht anders geht, pack dir doch ein div ins div und platzier das :wiii:


All times are GMT -5. The time now is 10:58 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.