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 07-15-2014, 06:11 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 86,952
Kyttias is on a distinguished road
Arrow Giftbox Mod (Randomly appearing, currency giving~)

I know this code to work in Mysidia 1.3.4, because in classes/class_member.php, a certain public function changecash($amount) exists and also because in the Admin CP, Widgets and Modules can be made. Please look for these in older versions of Mysidia before beginning. ^^ As always, make backups of your files.

First of all, you will need jQuery included in your template files. If it is not, or you're not sure, please open up your template.tpl and observe the space before the end of the </body>. If you need a link to jQuery, it is hosted via CDN, so all you need to do is add this line:
Code:
<script src="//cdn.jsdelivr.net/jquery/1.10.0/jquery.min.js"></script>
This next step I'm going to have you do is important. It creates an id wrapper around a user's current cash amount, so that later my script will create a visual showing that the money has increased. Without this first step, a user would not see their new total until they've reloaded or moved on to a new page. Boo! So... in classes/class_sidebar.php, inside function setMoneyBar(), change line

PHP Code:
$this->moneyBar->add(new Comment("You have {$mysidia->user->money} {$mysidia->settings->cost}.")); 
to

PHP Code:
$this->moneyBar->add(new Comment("You have <span id='cashonhand'>{$mysidia->user->money}</span> {$mysidia->settings->cost}.")); 
Note that if you have any other location you are displaying a user's money that you would like to be updated, such as if you made your own display bar, you should be wrapping that variable, or the placeholder for that variable that renders the cash as a number, in a span with the same id as above!

Now, log into your Admin CP and create a new Widget named 'giftbox'. If you name it anything else, you'll be calling it with that name. (Later we'll be calling this widget with {$giftbox}.) Set the Controller Level to 'all', the Widget Order to '50', and Widget Status to 'enabled'.

Next you'll be making a Module with a Parent Widget of 'giftbox', which you just made. You should be able to name the module whatever you like. For amusement's sake, I named mine 'WrappingPaper'. I'm pretty sure the name here will not matter. The Required Userlevel should be 'member'.

Module HTML Code:
Code:
<style>.giftbox {text-align: center;}
.blankbox {background: url(http://fc05.deviantart.net/fs70/f/2014/099/4/f/small_giftbox_by_kyttias-d7dqg9o.png); border: 0px; background-size: 100% 100%; width: 60px; height: 50px;}
.blankbox:hover {background: url(http://fc05.deviantart.net/fs70/f/2014/099/4/f/small_giftbox_by_kyttias-d7dqg9o.png); border: 0px; background-size: 100% 100%; width: 60px; height: 50px;}
</style>

<form id="giftbox" action="giftbox" name="giftbox" method="post" role="form">
<input type="hidden" value="500" name="amount" />
<button class="blankbox" id="submit" value="submit" name="submit" type="submit">*</button>
</form>

<div id="result"></div>

<script>
$(function () {
	$('.giftbox').animate({'height':'55px'});
    	var frm = $('#giftbox');
	frm.submit(function (ev) {
        		$.ajax({
            			type: frm.attr('method'),
            			url: frm.attr('action'),
           			data: frm.serialize(),
            			success: function (data) {
				$( "#giftbox" ).css("display","none"); 
				$amount = $('#giftbox').find( 'input[name=\"amount\"]' ).val();
				$( "#result" ).html( "Gained "+$amount+" CURRENCY!" );
				$cashonhand = $('.cashonhand:first').text();
				$newcash = Number($cashonhand)+Number($amount);
				$('.cashonhand').text($newcash);
				$('.giftbox').animate({ height: 0, opacity: 0 },  { duration: 2000  });
            			}
		});
	ev.preventDefault();
	});
});
</script>
Examine the code above. Find where I wrote CURRENCY and replace it with the name of your own. Because this is Javascript/jQuery and not PHP, I can't have it magically know your currency name, unfortunately. (If I try to have it print a variable, it will print the variable instead of it's value. It has to do with how webpages render.)

Technically, from the code above, the style css you can just add to your stylesheet. You'll recognize that this is where you should change the image of the box.

Lastly, look at the form itself, see this?
Code:
<input type="hidden" value="500" name="amount" />
You can change value to anything, BUT below, you'll see the PHP code is checking that the value is, in fact, 500. Be sure to change both so they match if you want to give users less or more. This is to prevent hackers from inserting their own values.

Module PHP Code:
PHP Code:
if((isset($_POST['amount']) && !empty($_POST['amount'])) && $_POST['amount'] == 500) {
    
$amount $_POST['amount'];
    
$mysidia->user->changecash($amount);

Module Order should be 0, Module Status to be 'enabled'.

All done!

Open up your template and it's template.tpl file and place {$giftbox} to test it out. As you'll see, anywhere {$giftbox} exists, a box will show that you can click.

Now that you have this power in your hands, I know you'll only want your giftbox to show on special circumstances. (I assume) you can use it on your own custom pages, and you can also write scripts. If you'd like that giftbox to show up 5% of the time, this can go in your template (or on a custom page):
Code:
{if rand(0,100) <= 5} {$giftbox} {/if}
You are free to make your own giftbox image or continue using the giftbox image I provided. This example giftbox is, however, transparent. It is also dynamically resized with css, so here it is full size - feel free to color it, then replace the links to it (cool hint: make a second version to fill the reference to it on the 'hover' css - maybe make it wiggle?):


Question time!

- Savvy viewers, how could I go about modifying the php function to deliver an item to the player's inventory? What about an egg directly into their owned adoptables table?

- Are there issues with it appearing on custom pages? I haven't made any/haven't tried to use Smarty variables in them.

(( If you think this was awesome, you can always donate to my PayPal e-mail address, which is my username here @gmail.com. ^^ It'll go towards getting my cat a cool tower to play on. ))
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 07-16-2014 at 03:05 PM.
Reply With Quote
  #2  
Old 07-16-2014, 01:53 PM
squiggler's Avatar
squiggler squiggler is offline
Squiggling since 1995
 
Join Date: Jul 2013
Posts: 185
Gender: Unknown/Other
Credits: 8,101
squiggler is on a distinguished road
Default

This is amazing! I will probably add this! Is there any way to either a) make the currency obtained fluctuate (rand function?), or b) put items in there? Thank you!
__________________
Avatar courtesy of Doll Divine.
Reply With Quote
  #3  
Old 07-16-2014, 02:57 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 86,952
Kyttias is on a distinguished road
Default

^ I'll work on making one that fluctuates. Like... you'll get a random amount between 500 and 2000?

Items I'm not sure on yet. I've got some time in the next few weeks, so I'm hoping to develop something like that.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 07-16-2014 at 03:01 PM.
Reply With Quote
  #4  
Old 07-16-2014, 03:29 PM
squiggler's Avatar
squiggler squiggler is offline
Squiggling since 1995
 
Join Date: Jul 2013
Posts: 185
Gender: Unknown/Other
Credits: 8,101
squiggler is on a distinguished road
Default

Yeah, that's what I mean. Can we just use the rand function?

Thank you! That will be fun.
__________________
Avatar courtesy of Doll Divine.
Reply With Quote
  #5  
Old 07-16-2014, 03:49 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 86,952
Kyttias is on a distinguished road
Default

This is untested, but, to change the value from '500' to 'random' on the form:
Code:
<input type="hidden" value="random" name="amount" />
Module PHP Code will now check that the value is 'random':
PHP Code:
if((isset($_POST['amount']) && !empty($_POST['amount'])) && $_POST['amount'] == "random") {
    
$amount rand(500,2000);
    
$mysidia->user->changecash($amount);

Should work and be plenty secure. ^^
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 07-16-2014 at 03:51 PM.
Reply With Quote
  #6  
Old 07-18-2014, 01:04 AM
squiggler's Avatar
squiggler squiggler is offline
Squiggling since 1995
 
Join Date: Jul 2013
Posts: 185
Gender: Unknown/Other
Credits: 8,101
squiggler is on a distinguished road
Default

Okay, just tested it out with the randomizer and I got about 1000 each time. By the way, I've found out that it only gives you the money if you click on it.

But anyway, it works perfectly! Thank you!
__________________
Avatar courtesy of Doll Divine.
Reply With Quote
  #7  
Old 07-18-2014, 02:59 AM
Infernette Infernette is offline
CODE CODE CODE CODE CODE
 
Join Date: Jan 2013
Location: Where I live? I live home.
Posts: 164
Gender: Female
Credits: 23,614
Infernette is on a distinguished road
Default

1.3.3 does not have a working widget system so it can only work with 1.3.4 btt (at least, a non-basic editable widget system, to my knowledge) Also is there any way that you can supply this in 'non-module' format for those of us with the slightly defunct version? :)
__________________
No, I have no idea what I'm doing. But it works. Barely.
Reply With Quote
  #8  
Old 07-18-2014, 06:39 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 86,952
Kyttias is on a distinguished road
Default

Well, I downloaded 1.3.3 and tried things for several hours and couldn't replicate what I'd done. I can randomly echo out giftbox or not on every page the sidebar exists (all of them), but not place it anywhere conveniently (it sits at the top of the page before the header where it echos out, not even in the sidebar itself, and it refuses to append anywhere else, despite my attempts), or on any particular page. Someone else will have to make an attempt.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 07-18-2014 at 06:42 PM.
Reply With Quote
  #9  
Old 08-20-2015, 02:42 AM
Woodchipz Woodchipz is offline
Member
 
Join Date: Aug 2015
Posts: 8
Gender: Male
Credits: 687
Woodchipz is on a distinguished road
Default

Hey this is an awesome addition! Thanks for this!

Just a little help getting it fully implemented would be awesome! You are quite skilled at what you do here.


I followed all the directions and upon trying to create the module for the widget I am met with the following error:



Warning: require(../inc/config.php): failed to open stream: No such file or directory in /home/paradi17/public_html/classes/class_initializer.php on line 97

Warning: require(../inc/config.php): failed to open stream: No such file or directory in /home/paradi17/public_html/classes/class_initializer.php on line 97

Fatal error: require(): Failed opening required '../inc/config.php' (include_path='.:/opt/alt/php55/usr/share/pear:/opt/alt/php55/usr/share/php') in /home/paradi17/public_html/classes/class_initializer.php on line 97






Any help deciphering this would be great :) Thanks again!

-Chipz
__________________
Reply With Quote
  #10  
Old 08-20-2015, 07:12 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 86,952
Kyttias is on a distinguished road
Default

Confirm that the error does not exist when the module is not being called. (ie, Remove {$giftbox} from your template. Is the error gone?) If the error isn't gone, it's nothing to do with this. If it's gone, then make sure the name is correct. (Again, as stated in the tutorial, if you named it anything else, you'll be calling it with that name.)

Otherwise... eh, this was one of my first mods.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote
Reply

Tags
cash, changecash, currency, giftbox, random

Thread Tools
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help !! Shops not appearing é.è kitty08 Feedback and Suggestions 3 12-31-2014 11:15 AM
Second Currency and Currency icon Rovick Suggestions and Feature Requests 14 11-11-2014 05:29 PM
Site appearing blank? Pear Questions and Supports 18 11-09-2014 04:50 PM
Giving pets a Gender Arianna Mys v1.1.x Mods 64 11-24-2010 01:45 AM
Eggs randomly displayed Quillink Questions and Supports 11 01-30-2009 03:08 AM


All times are GMT -5. The time now is 08:55 AM.

Currently Active Users: 445 (0 members and 445 guests)
Threads: 4,080, Posts: 32,024, 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