Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Tutorials and Tips

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 02-08-2021, 11:59 AM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 21,722
parayna is on a distinguished road
Default [1.3.4] Currency Promocodes

Hello! This is my first ever tutorial on here lol. Anyway, I wanted the ability to make a promocode to give a user some money (and even premium currency) so I managed to do that. It also has adminCP functions so you can just add promos like you normally would!

First of all, open admincp/view/promoview.php.

Find this, in public function add():

PHP Code:
            $typesList = new RadioList("type");
            
$typesList->add(new RadioButton(" Adoptables""type""Adopt"));
            
$typesList->add(new RadioButton(" Items""type""Item"));
            
$typesList->add(new RadioButton(" Pages""type""Page")); 
Change those 4 lines to:

PHP Code:
            $typesList = new RadioList("type");
            
$typesList->add(new RadioButton(" Adoptables""type""Adopt"));
            
$typesList->add(new RadioButton(" Items""type""Item"));
            
$typesList->add(new RadioButton("Currency""type""Currency"));
            
$typesList->add(new RadioButton(" Pages""type""Page")); 
See where I just added a currency line?

Now, scroll down further until you find the public function edit() section. Find the same 3 lines and add the new currency line. Save the file.

Find and open classes/class_promocode.

Find public function execute(){ and replace it with this:

PHP Code:
  public function execute(){
      
// This method will execute the promocode and give users their desired adoptables or items, need to be used after validation is completed
      
$mysidia Registry::get("mysidia");
      
$document $mysidia->frame->getDocument();
      if(
$this->valid != TRUE) throw new NoPermissionException($mysidia->lang->validate);
      
      switch(
$this->type){
         case 
"Adopt":
            
// The user will receive an adoptable from the promocode now.
            
$code codegen(100);
            
$genders = array('f''m');
            
$rand rand(0,1);
            
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $this->reward"name" => $this->reward"owner" => $this->user"currentlevel" => 0"totalclicks" => 0"code" => $code
                                                           
"imageurl" => NULL"alternate" => 0"tradestatus" => 'fortrade'"isfrozen" => 'no'"gender" => $genders[$rand], "lastbred" => 0"originalowner" => $mysidia->user->username"birthday" => date("F jS, Y")));
            
$document->addLangvar("Congrats, you have acquired the adoptable {$this->reward} by entering promocode.");
            
$this->usepromo();
            break;
         case 
"Item":
            
// The user will receive an item from the promocode now.
        
            
$item = new StockItem($this->reward1);
            
$item->assign($this->user);
            
$newquantity $item->getoldquantity() + 1;
            if(
$item->cap != and $newquantity $item->cap){
                throw new 
NoPermissionException("It appears that you cannot add one more of item {$this->reward} to your inventory, its quantity has already exceeded the upper limit.");
            }
            else{
               
$item->append();
               
$document->addLangvar("Congrats, you have acquired the item {$this->reward} by entering promocode.");
               
$this->usepromo();
            }  
            break;
         case 
"Page":
            
$this->usepromo();
            break;
         case 
"Currency":
            
// The user will receive currency from the promocode now.
            
$cost $mysidia->settings->cost//The name of your site's currency
            
$cash $mysidia->db->select("users", array("money"), "username ='{$mysidia->user->username}'")->fetchColumn(); //How much cash the user has
            
$new_cash $cash $this->reward//Simple sum to calculate user's current cash + reward
            
$mysidia->db->update("users", array("money" => $new_cash), "username ='{$mysidia->user->username}'");  //Update the database with the new cash amount
            
$document->addLangvar("Congrats, you have acquired {$this->reward} {$cost} by entering promocode.");
            
$this->usepromo();
            break;
         default:
            throw new 
InvalidIDException($mysidia->lang->type);     
      }
      
// All done, we're good to go!
  

You can see the part that I added at the bottom there. That section makes it so that currency can be given!

Premium currency tutorial on next comment!
__________________
It's been a long time. I had so much fun making a site back in 2016 that recently, when I started thinking about it again, I decided to come back and work on something small. It'll probably just be a personal project but who knows? We'll see, anyway.

Reply With Quote
  #2  
Old 02-08-2021, 12:00 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 21,722
parayna is on a distinguished road
Default

Adding Premium Currency

First of all, follow this tutorial to add premium currency to your site

Then in admincp/view/promoview.php, add this line...

PHP Code:
$typesList->add(new RadioButton("Premium Currency""type""Premium Currency")); 
...in both the add() and edit() sections. (Use the previous part of this tutorial for guidance)

Then in classes/class_promocode.php, add this...

PHP Code:
 case "Premium Currency":
            
// The user will receive premium currency from the promocode now.
            
$premiumcost $mysidia->settings->premiumcurrency//The name of your site's premium currency
            
$premiumcash $mysidia->db->select("users", array("premiumcurrency"), "username ='{$mysidia->user->username}'")->fetchColumn(); //How much premium currency the user has
            
$new_premiumcash $premiumcash $this->reward//Simple sum to calculate user's current cash + reward
            
$mysidia->db->update("users", array("premiumcurrency" => $new_premiumcash), "username ='{$mysidia->user->username}'");  //Update the database with the new premium currency amount
            
$document->addLangvar("Congrats, you have acquired {$this->reward} {$premiumcost} by entering promocode.");
            
$this->usepromo();
            break; 
...underneath the currency section you just added. (It should go under the break;)

Make sure you look through the code and see if it matches up with your own database! If you named the premium currency field (for example) anything other than 'premiumcurrency' while adding it to your site, you might have to tweak it. I'm willing to help if you need it, just comment below.

Also, this doesn't go over tweaking the descriptions that show up to say you can add currency now. That should be easy enough to do by just finding those lines in promoview.php yourself and making it say whatever you want it to!

I hope this helps someone! It's very simple but I was quite proud of myself for managing it with no help lol.
__________________
It's been a long time. I had so much fun making a site back in 2016 that recently, when I started thinking about it again, I decided to come back and work on something small. It'll probably just be a personal project but who knows? We'll see, anyway.

Reply With Quote
  #3  
Old 05-27-2022, 05:06 AM
LUC1G07CH1's Avatar
LUC1G07CH1 LUC1G07CH1 is offline
Member
 
Join Date: Mar 2016
Location: Too distant for telling, but it's HUEBR
Posts: 152
Gender: Unknown/Other
Credits: 28,165
LUC1G07CH1 is on a distinguished road
Send a message via AIM to LUC1G07CH1 Send a message via Yahoo to LUC1G07CH1
Default

https://enjazalkhaleej.com/---/
https://advocatesnairobi.com/---/
https://advocatesnairobi.com/----/
https://advocatesnairobi.com/------/
https://advocatesnairobi.com/---/
Reply With Quote
Reply

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


All times are GMT -5. The time now is 07:18 AM.

Currently Active Users: 1365 (0 members and 1365 guests)
Threads: 4,081, Posts: 32,026, 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