Home Community Mys-Script Creative Off-Topic |
|
|
Thread Tools | Display Modes |
#1
|
||||
|
||||
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:
__________________
My Mods Site (1.3.4, 2020 Mods) Last edited by Abronsyth; 02-18-2016 at 02:48 PM. |
#2
|
||||
|
||||
Still looking for some help with this
__________________
My Mods Site (1.3.4, 2020 Mods) |
#3
|
||||
|
||||
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? |
#4
|
||||
|
||||
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:
__________________
My Mods Site (1.3.4, 2020 Mods) Last edited by Abronsyth; 01-29-2016 at 12:21 PM. |
#5
|
|||
|
|||
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; }
__________________
|
#6
|
||||
|
||||
Wait, I found a mistake in the sql syntax... try this:
PHP Code:
|
#7
|
|||
|
|||
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->user->changecash(-$cost);
__________________
|
#8
|
||||
|
||||
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. |
#9
|
||||
|
||||
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) |
#10
|
||||
|
||||
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:
PHP Code:
__________________
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. |
|
|
What's New? |
What's Hot? |
What's Popular? |