Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.3.x Mods

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 04-05-2017, 11:51 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 133,612
Abronsyth is on a distinguished road
Default 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):


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!
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #2  
Old 04-05-2017, 02:12 PM
Pear's Avatar
Pear Pear is offline
Woah man.
 
Join Date: Dec 2013
Location: The Underworld
Posts: 169
Gender: Female
Credits: 48,275
Pear is on a distinguished road
Default

Oooh, looks neat! :3
__________________
Noot noot! Gotta get a new signooture. >->
Reply With Quote
  #3  
Old 04-05-2017, 03:08 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 79,283
Dinocanid is on a distinguished road
Default

Thanks for sharing this! What I was trying to do with backgrounds just wasn't working lol
__________________
Reply With Quote
  #4  
Old 04-07-2017, 11:52 PM
Bexasaurus's Avatar
Bexasaurus Bexasaurus is offline
〈 ᴘʀᴀᴄᴛɪᴄɪɴɢ ᴀʀᴛɪsᴛ 〉
 
Join Date: Aug 2015
Posts: 101
Gender: Female
Credits: 8,169
Bexasaurus is on a distinguished road
Default

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?
__________________
TUMBLR * NOPE
I post art and stuff, feel free to follow/watch!
Reply With Quote
  #5  
Old 04-08-2017, 02:53 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 133,612
Abronsyth is on a distinguished road
Default

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 :)
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #6  
Old 05-02-2017, 12:22 PM
darrinm3 darrinm3 is offline
Member
 
Join Date: May 2017
Posts: 5
Gender: Male
Credits: 788
darrinm3 is on a distinguished road
Default

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!
Reply With Quote
  #7  
Old 05-02-2017, 02:17 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 133,612
Abronsyth is on a distinguished road
Default

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!
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #8  
Old 05-03-2017, 10:29 AM
darrinm3 darrinm3 is offline
Member
 
Join Date: May 2017
Posts: 5
Gender: Male
Credits: 788
darrinm3 is on a distinguished road
Default

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!
Reply With Quote
  #9  
Old 05-03-2017, 10:40 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 133,612
Abronsyth is on a distinguished road
Default

That depends on which page you're adding it to? Let me know the file and I can help out :)
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #10  
Old 05-03-2017, 10:43 AM
darrinm3 darrinm3 is offline
Member
 
Join Date: May 2017
Posts: 5
Gender: Male
Credits: 788
darrinm3 is on a distinguished road
Default

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:17 PM.

Currently Active Users: 735 (0 members and 735 guests)
Threads: 4,081, Posts: 32,032, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636