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:
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:
Next, in the same file, find and replace public function edit:
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:
Open model/domainmodel/itemfunction.php. At the top find:
Replace with:
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:
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:
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.
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.

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

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:

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:


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.
Last edited: