Mys 1.3.6 Coin Purse Mod

Forum
Last Post
Threads / Messages

KittHaven

Member
Member
Joined
May 21, 2013
Messages
478
Points
28
Age
25
Location
Devon, UK
Mysidian Dollar
8,292
Hi, made another item function that lets users get some money by opening an item. The amount is randomised between two values.

First, please follow the instructions in the spoiler to prepare the 'value' field in the adopts_items table. You need to prepare it to accept multiple values as by default it will only allow 1 integer.

  Spoiler: Prepare Value Field 

Open your DB, adopts_items, click structure and change 'value' to this:

2023-11-18 01_22_55-localhost _ MySQL _ mysidia _ adopts_items _ phpMyAdmin 5.2.0 and 10 more ...png

Now we need to change a few lines in the files as value is sometimes forced to be an integer, so we need to remove that.

Open, controller/admincp/itemcontroller.php and find and replace public function add:

PHP:
public function add(){
        $mysidia = Registry::get("mysidia");    
        if($mysidia->input->post("submit")){
            $this->dataValidate();
            $imageurl = ($mysidia->input->post("existingimageurl") == "none") ? $mysidia->input->post("imageurl") : $mysidia->input->post("existingimageurl");    
            $mysidia->db->insert("items", ["category" => $mysidia->input->post("category"), "itemname" => $mysidia->input->post("itemname"), "description" => $mysidia->input->post("description"), "imageurl" => $imageurl, "function" => $mysidia->input->post("function"), "target" => $mysidia->input->post("target"), "value" => $mysidia->input->post("value"),
                                           "shop" => (int)$mysidia->input->post("shop"), "price" => (int)$mysidia->input->post("price"), "chance" => (int)$mysidia->input->post("chance"), "cap" => (int)$mysidia->input->post("cap"), "tradable" => $mysidia->input->post("tradable"), "consumable" => $mysidia->input->post("consumable")]);    
        }

Next, in the same file, find and replace public function edit:

PHP:
public function edit($id = NULL){
        $mysidia = Registry::get("mysidia");    
        if(!$id) return $this->index();
        try{
            $item = new Item($id);
            if($mysidia->input->post("submit")){
                 $this->dataValidate();
                $imageurl = ($mysidia->input->post("existingimageurl") == "none") ? $mysidia->input->post("imageurl") : $mysidia->input->post("existingimageurl");
                $mysidia->db->update("items", ["category" => $mysidia->input->post("category"), "itemname" => $mysidia->input->post("itemname"), "description" => $mysidia->input->post("description"), "imageurl" => $imageurl, "function" => $mysidia->input->post("function"), "target" => $mysidia->input->post("target"), "value" => $mysidia->input->post("value"),
                                               "shop" => (int)$mysidia->input->post("shop"), "price" => (int)$mysidia->input->post("price"), "chance" => (int)$mysidia->input->post("chance"), "cap" => (int)$mysidia->input->post("cap"), "tradable" => $mysidia->input->post("tradable"), "consumable" => $mysidia->input->post("consumable")], "id='{$item->getID()}'");          
            }
            $this->setField("item", $item);
        }
        catch(Exception $e){
            throw new InvalidIDException("nonexist");
        }
    }

All that does is replace:

"value" => (int)$mysidia->input->post("value")

to:

"value" => $mysidia->input->post("value")

Which will allow you to have value be whatever you need it to be.


In your DB, open adopts_items_functions and add this as a new entry:

2023-11-18 02_37_18-localhost _ MySQL _ mysidia _ adopts_items_functions _ phpMyAdmin 5.2.0 an...png

Open model/domainmodel/itemfunction.php. At the top find:

PHP:
protected $validFunctions = ["Valuable", "Level1", "Level2", "Level3", "Click1", "Click2", "Breed1", "Breed2", "Alts1", "Alts2", "Name1", "Name2"];

Replace with:

PHP:
protected $validFunctions = ["Valuable", "Level1", "Level2", "Level3", "Click1", "Click2", "Breed1", "Breed2", "Alts1", "Alts2", "Name1", "Name2", "CoinPurse"];

If you already have edited validFunctions, don't replace it and just add "CoinPurse" to the end.

Now scroll down and add the below to the other functions:

PHP:
protected function applyCoinPurse(OwnedItem $item, OwnedAdoptable $adopt){
        $mysidia = Registry::get("mysidia");
        $loot = explode(',', $item->getValue());
        $num_loot = count($loot);
        if($num_loot == 1){
            $mysidia->user->changeMoney($reward);
            return "You opened the {$item->getItemname()} and received {$reward} {$mysidia->settings->cost}!";
        }
        else{
            $reward = mt_rand($loot[0],$loot[1]);
            $mysidia->user->changeMoney($reward);
            return "You opened the {$item->getItemname()} and received {$reward} {$mysidia->settings->cost}!";
        } 
    }

Now you can add new items that reward money! You can use 1 value to give an exact amount, or put 2 values for the reward to be between them. [Min,Max] Here's an example:

2023-11-18 02_38_33-Mysidia Adoptables v1.3.6 and 11 more pages - Personal - Microsoft Edge.png

2023-11-18 02_38_17-Mysidia Adoptables v1.3.6 and 11 more pages - Personal - Microsoft Edge.png

In the above, the Small gives between 10 and 100, the Medium gives between 101 and 500, and the Large gives between 501 and 1000.

  Spoiler: Images 
 
Last edited:
Thanks!! This goes well with the treasure chest implemented in the fishing mod. Err... it would, if I could get the fishing mod working lol.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,122
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top