Mysidia Adoptables Support Forum  

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

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-08-2021, 12:59 PM
parayna's Avatar
parayna parayna is offline
Member
 
Join Date: May 2013
Location: Devon, UK
Posts: 342
Gender: Female
Credits: 22,727
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
 


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 11:16 AM.

Currently Active Users: 699 (0 members and 699 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