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(); 



All times are GMT -5. The time now is 01:32 AM.

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