Mysidia Adoptables Support Forum  

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

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 01-19-2016, 10:01 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,773
Abronsyth is on a distinguished road
Default 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?
__________________
My Mods Site (1.3.4, 2020 Mods)

Last edited by Abronsyth; 02-18-2016 at 02:48 PM.
Reply With Quote
  #2  
Old 01-29-2016, 08:02 AM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,773
Abronsyth is on a distinguished road
Default

Still looking for some help with this
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #3  
Old 01-29-2016, 09:21 AM
Hwona's Avatar
Hwona Hwona is offline
Member
 
Join Date: Mar 2013
Posts: 620
Gender: Female
Credits: 48,855
Hwona is on a distinguished road
Default

Quote:
Originally Posted by Abronsyth View Post
Still looking for some help with this
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?
Reply With Quote
  #4  
Old 01-29-2016, 12:19 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,773
Abronsyth is on a distinguished road
Default

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;
        } 
__________________
My Mods Site (1.3.4, 2020 Mods)

Last edited by Abronsyth; 01-29-2016 at 12:21 PM.
Reply With Quote
  #5  
Old 01-29-2016, 10:33 PM
FounderSim FounderSim is offline
Member
 
Join Date: Sep 2014
Posts: 65
Gender: Male
Credits: 7,609
FounderSim is on a distinguished road
Default

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;
        }
__________________
Reply With Quote
  #6  
Old 01-29-2016, 11:21 PM
Hwona's Avatar
Hwona Hwona is offline
Member
 
Join Date: Mar 2013
Posts: 620
Gender: Female
Credits: 48,855
Hwona is on a distinguished road
Default

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())); 
Reply With Quote
  #7  
Old 01-30-2016, 04:44 PM
FounderSim FounderSim is offline
Member
 
Join Date: Sep 2014
Posts: 65
Gender: Male
Credits: 7,609
FounderSim is on a distinguished road
Default

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);
__________________
Reply With Quote
  #8  
Old 02-02-2016, 06:42 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,773
Abronsyth is on a distinguished road
Default

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.
__________________
My Mods Site (1.3.4, 2020 Mods)

Last edited by Abronsyth; 02-02-2016 at 06:48 PM.
Reply With Quote
  #9  
Old 02-13-2016, 12:00 PM
Abronsyth's Avatar
Abronsyth Abronsyth is offline
A Headache Embodied
 
Join Date: Aug 2011
Location: NY
Posts: 1,011
Gender: Male
Credits: 113,773
Abronsyth is on a distinguished road
Default

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..?
__________________
My Mods Site (1.3.4, 2020 Mods)
Reply With Quote
  #10  
Old 02-13-2016, 03:45 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,666
Kyttias is on a distinguished road
Default

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(); 
__________________
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.
Reply With Quote
Reply


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 12:57 AM.

Currently Active Users: 3971 (0 members and 3971 guests)
Threads: 4,080, Posts: 32,024, 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