Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Subtract currency upon adopting (http://www.mysidiaadoptables.com/forum/showthread.php?t=4988)

Abronsyth 01-19-2016 10:01 AM

Subtract currency upon adopting
 
Resolved

Now a mod-- Click!

OK, so I'm trying to essentially copy the files adoptview.php, adopt.php, and lang_adopt.php in order to create more adoption centers such as these because I'm able to individually customize the stores a lot more then.

However I've run into a road block. I don't know how to make it, when using these files, so that when a user "adopts" a cat that has a cost set to it, it subtracts the cost from the user's amount of currency. I can see where it happens in the shop files, but I'm not sure how to convert that over to the adopt files.

I think this is the function I need, but I don't know how to include/implement it in the shopname.php or shopnameview.php files (which are just versions of the adopt.php and adoptview.php files);
PHP Code:

    public function purchase($adopt){
        
$mysidia Registry::get("mysidia");
        if(
$adopt->owner != $mysidia->user->username) Throw new NoPermissionException('Something is very very wrong, please contact an admin asap.');
        else{
            
$cost $adopt->getcost($this->salestax);
            
$moneyleft $mysidia->user->money $cost;
            if(
$moneyleft >= 0){    
                
$purchase $adopt->append($adopt->owner);
                
$mysidia->db->update("users", array("money" => $moneyleft), "username = '{$adopt->owner}'");
                
$status TRUE;
            }            
            else throw new 
InvalidActionException($mysidia->lang->money);
        }
        return 
$status;
    } 

Would anyone be able/willing to help with this?

Abronsyth 01-29-2016 08:02 AM

Still looking for some help with this :happyc:

Hwona 01-29-2016 09:21 AM

Quote:

Originally Posted by Abronsyth (Post 33622)
Still looking for some help with this :happyc:

Okay... I'm not sure if this will work, but declare a new adopt in the adopt file (if not already declared):
$adopt = new Adoptable($mysidia->input->post("id"));

Then:
$cost = $adopt->getCost();
$usermoney = $mysidia->db->select("users", array("money"), "username = {$mysidia->user->username}")->fetchColumn();
$newusermoney = $usermoney - $cost;
$mysidia->db->update("users", array("money" => $newusermoney), "username='{$mysidia->user->username}'");

....

Is this what you need?

Abronsyth 01-29-2016 12:19 PM

Unfortunately it doesn't seem to be subtracting any currency :(
((showing index function in my "mao.php" file which is basically a copy of adopt.php))
PHP Code:

public function index(){
        
$mysidia Registry::get("mysidia");        
        if(
$mysidia->input->post("submit")){
            
$this->access "member";
            
$this->handleAccess();
            
$id $mysidia->input->post("id");
            if(
$mysidia->session->fetch("adopt") != or !$id) throw new InvalidIDException("global_id");            
            
            
$adopt = new Adoptable($id);
            
$cost $adopt->getCost();
            
$usermoney $mysidia->db->select("users", array("money"), "username = {$mysidia->user->username}")->fetchColumn();
            
$newusermoney $usermoney $cost;
            
$mysidia->db->update("users", array("money" => $newusermoney), "username='{$mysidia->user->username}'");
            
$conditions $adopt->getConditions();
            if(!
$conditions->checkConditions()) throw new NoPermissionException("condition");
            
            
$name = (!$mysidia->input->post("name"))?"Unnamed":$mysidia->input->post("name");
            
$alts $adopt->getAltStatus();
            
$code $adopt->getCode();
            
$gender $adopt->getGender();
            
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $adopt->getType(), "name" => $name"owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code
                                                           
"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'notfortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0"lastbred" => 0"originalowner" => $mysidia->user->username"birthday" => date("F jS, Y")  ));
                        
            
$aid $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn();
            
$this->setField("aid", new Integer($aid));
            
$this->setField("name", new String($name));            
            
$this->setField("eggImage", new String($adopt->getEggImage()));
            return;
        } 


FounderSim 01-29-2016 10:33 PM

Here's how I debug some mysidia scripting I do. I add DIE's in the code to check on things. I added two DIE statements in your code.

Code:

public function index(){
        $mysidia = Registry::get("mysidia");       
        if($mysidia->input->post("submit")){
            $this->access = "member";
            $this->handleAccess();
            $id = $mysidia->input->post("id");
            if($mysidia->session->fetch("adopt") != 1 or !$id) throw new InvalidIDException("global_id");           
           
            $adopt = new Adoptable($id);
            $cost = $adopt->getCost();
DIE("COST: " . $cost); //delete after seeing result
            $usermoney = $mysidia->db->select("users", array("money"), "username = {$mysidia->user->username}")->fetchColumn();
DIE("MONEY: " . $usermoney); // delete after seeing result
            $newusermoney = $usermoney - $cost;
            $mysidia->db->update("users", array("money" => $newusermoney), "username='{$mysidia->user->username}'"); //this line updates money. I assume $cost is 0 since no subtracting is done.
            $conditions = $adopt->getConditions();
            if(!$conditions->checkConditions()) throw new NoPermissionException("condition");
           
            $name = (!$mysidia->input->post("name"))?"Unnamed":$mysidia->input->post("name");
            $alts = $adopt->getAltStatus();
            $code = $adopt->getCode();
            $gender = $adopt->getGender();
            $mysidia->db->insert("owned_adoptables", array("aid" => NULL, "type" => $adopt->getType(), "name" => $name, "owner" => $mysidia->user->username, "currentlevel" => 0, "totalclicks" => 0, "code" => $code,
                                                          "imageurl" => NULL, "usealternates" => $alts, "tradestatus" => 'notfortrade', "isfrozen" => 'no', "gender" => $gender, "offsprings" => 0, "lastbred" => 0, "originalowner" => $mysidia->user->username, "birthday" => date("F jS, Y")  ));
                       
            $aid = $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn();
            $this->setField("aid", new Integer($aid));
            $this->setField("name", new String($name));           
            $this->setField("eggImage", new String($adopt->getEggImage()));
            return;
        }


Hwona 01-29-2016 11:21 PM

Wait, I found a mistake in the sql syntax... try this:
PHP Code:

public function index(){
        
$mysidia Registry::get("mysidia");        
        if(
$mysidia->input->post("submit")){
            
$this->access "member";
            
$this->handleAccess();
            
$id $mysidia->input->post("id");
            if(
$mysidia->session->fetch("adopt") != or !$id) throw new InvalidIDException("global_id");            
            
            
$adopt = new Adoptable($id);
            
$cost $adopt->getCost();
            
$usermoney $mysidia->db->select("users", array("money"), "username = '{$mysidia->user->username}'")->fetchColumn();
            
$newusermoney $usermoney $cost;
            
$mysidia->db->update("users", array("money" => $newusermoney), "username='{$mysidia->user->username}'");
            
$conditions $adopt->getConditions();
            if(!
$conditions->checkConditions()) throw new NoPermissionException("condition");
            
            
$name = (!$mysidia->input->post("name"))?"Unnamed":$mysidia->input->post("name");
            
$alts $adopt->getAltStatus();
            
$code $adopt->getCode();
            
$gender $adopt->getGender();
            
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $adopt->getType(), "name" => $name"owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code
                                                           
"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'notfortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0"lastbred" => 0"originalowner" => $mysidia->user->username"birthday" => date("F jS, Y")  ));
                        
            
$aid $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn();
            
$this->setField("aid", new Integer($aid));
            
$this->setField("name", new String($name));            
            
$this->setField("eggImage", new String($adopt->getEggImage())); 


FounderSim 01-30-2016 04:44 PM

I also found this in pound.php

Code:

                            $poundAdopt->dopound();
                                if($this->settings->cost->active == "yes"){       
                            $cost = $this->getCost($this->adopt, "pound");
                                $mysidia->user->changecash(-$cost);
                                        $this->setField("cost", new Integer($cost));
                            }

Mysidia has built in function to change cash. I assume - subtracts from money. If you wanted to add money, use positive #.

$mysidia->user->changecash(-$cost);

Abronsyth 02-02-2016 06:42 PM

Huh, nothing's worked as of yet. I'll keep working on this, I'd like to pretty up the layout a bit, and then release it as a mod once I do get it working.

Trying to see if I can somehow use the purchase function now...hm.

Abronsyth 02-13-2016 12:00 PM

I'm now wondering if this has something to do with the way the adopt function itself is set up...is it just entirely designed to never subtract currency if a user is adopting a pet..?

Kyttias 02-13-2016 03:45 PM

The species has a cost set to it, but you need to pull up that information before you can use it. In the default shop's purchasing function, the line $adopt->getcost($this->salestax); uses $adopt, but that $adopt refers to the species, not to the pet that was just adopted. We can't use that, we already have a variable called $adopt which refers to the pet we just created, not the species as a whole.

Right after the pet is inserted into the database, try this (this should go in adopts.php, obviously):
PHP Code:

$cost $mysidia->db->select("adoptables", array("cost"), "type='{$adopt->getType()}'")->fetchColumn();
$mysidia->user->changecash(-$cost); 

I suggest putting it before this line:
PHP Code:

$aid $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn(); 


Abronsyth 02-13-2016 04:59 PM

Nope, still refuses to work (though that tip does make sense, thank you!)

PHP Code:

<?php

use Resource\Native\Integer;
use 
Resource\Native\String;
use 
Resource\Native\Arrays;
use 
Resource\Native\Null;

class 
MaoController extends AppController{

    public function 
__construct(){
        
parent::__construct("member");
        
$mysidia Registry::get("mysidia");
        if(
$mysidia->usergroup->getpermission("canadopt") != "yes"){
            throw new 
NoPermissionException("permission");
        }    
    }
    
    public function 
index(){ 
        
$mysidia Registry::get("mysidia");         
        if(
$mysidia->input->post("submit")){ 
            
$this->access "member"
            
$this->handleAccess(); 
            
$id $mysidia->input->post("id"); 
            if(
$mysidia->session->fetch("adopt") != or !$id) throw new InvalidIDException("global_id");             
             
            
$adopt = new Adoptable($id); 
            
$conditions $adopt->getConditions(); 
            if(!
$conditions->checkConditions()) throw new NoPermissionException("condition"); 
             
            
$name = (!$mysidia->input->post("name"))?"Unnamed":$mysidia->input->post("name"); 
            
$alts $adopt->getAltStatus(); 
            
$code $adopt->getCode(); 
            
$gender $adopt->getGender(); 
            
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $adopt->getType(), "name" => $name"owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code,  
                                                           
"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'notfortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0"lastbred" => 0"originalowner" => $mysidia->user->username"birthday" => date("F jS, Y")  )); 
            
$cost $mysidia->db->select("adoptables", array("cost"), "type='{$adopt->getType()}'")->fetchColumn();
            
$mysidia->user->changecash(-$cost);               
            
$aid $mysidia->db->select("owned_adoptables", array("aid"), "code='{$code}' and owner='{$mysidia->user->username}'")->fetchColumn(); 
            
$this->setField("aid", new Integer($aid)); 
            
$this->setField("name", new String($name));             
            
$this->setField("eggImage", new String($adopt->getEggImage()));  
            return;
        }  
        
        
$mysidia->session->assign("adopt"1TRUE);
        
$ids $mysidia->db->select("adoptables", array("id"), "shop='Mao Cats'")->fetchAll(PDO::FETCH_COLUMN);
        
$total = ($ids)?count($ids):0;
        
        if(
$total == 0$adopts = new Null;
        else{        
            
$adopts = new Arrays($total);
            
$available 0;
            
            foreach(
$ids as $id){
                
$adopt = new Adoptable($id);
                
$conditions $adopt->getConditions();    
                  if(
$conditions->checkConditions()) $adopts[$available++] = $adopt;    
            }
            
            if(
$available == 0$adopts = new Null;
            else 
$adopts->setSize($available);            
        }        
        if(
$adopts instanceof Null) throw new InvalidActionException("adopt_none");
        
$this->setField("adopts"$adopts);
    }
}
?>

Don't know what I'm doing wrong at this point @_@

Kyttias 02-13-2016 05:22 PM

Very odd... I mean... they do get the pet, right, it just doesn't take out money?

Abronsyth 02-16-2016 09:50 AM

Yep, the pet is added to the account just fine, but it doesn't subtract any currency.

Kyttias 02-16-2016 11:41 AM

Okay, get this: If you delete the line that inserts the pet into the database in mao.php, it still gets added. Something tells me it's still using the original adopt.php to do it's work. This is because it's still sending the form data to it!

In view/maoview.php find:
PHP Code:

$adoptForm = new Form("form""adopt""post"); 

And change it to:
PHP Code:

$adoptForm = new Form("form""mao""post"); 

The currency is then going down, but you have to go to another page to see that.
http://orig13.deviantart.net/90be/f/...as-d9rzrmn.gif

(Still using this:)
PHP Code:

$cost $mysidia->db->select("adoptables", array("cost"), "type='{$adopt->getType()}'")->fetchColumn();
$mysidia->user->changecash(-$cost); 


Abronsyth 02-16-2016 12:44 PM

-throws hands into the air and starts dancing-

Yes! Brilliant! It's working now! Thank you so, so much, Kyttias! You've saved Catisserie's entire economy, haha! I figured it had something to do with the form, but I was looking at the submit action, and not that part.

Thank you so much! Seriously, please let me know if there's ever anything at all I can help you with because you've done so much to help!


All times are GMT -5. The time now is 12:54 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.