Home Community Mys-Script Creative Off-Topic |
|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
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> PHP Code:
PHP Code:
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> 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" /> Module PHP Code: PHP Code:
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} 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. |
Tags |
cash, changecash, currency, giftbox, random |
|
|
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 |
What's New? |
What's Hot? |
What's Popular? |