Item type/function , Gender swap

Forum
Last Post
Threads / Messages

Kandria

Member
Member
Joined
Jul 4, 2020
Messages
43
Points
8
Age
38
Mysidian Dollar
371
Just suggesting an item type or function, to change pet gender to the opposite (so male-> female or female->male)
 
That shouldn't be too hard to write a function for. I'll have to wait until the weekend to make and test a function for that (I work full time during the week), but all it's really doing is changing the DB gender field of the owned adoptable table for the specific adopt.
 
Even if it needs 2 item functions (so one that makes it female and one that makes it male), it would work, if it's a bit much to code in to get the gender then swap to the other... I thought about looking into it myself too TBH by looking at how other items function factor. However I also fear messing it up xD
 
I made and tested the item function you wanted.

Step 1. Go into model/domainmodel/ownedadoptable

Under this:

public function getGender($fetchMode = ""){
if($fetchMode == Model::GUI) return new Image("picuploads/{$this->gender}.png");
else return $this->gender;
}

Add this:

public function setGender($gender, $assignMode = ""){
if($assignMode == Model::UPDATE) $this->save("gender", $gender);
$this->gender = $gender;
}

Step 2. Go to model/domainmodel/itemfunction

At the top there is a long array list called
protected $validFunctions = [

at the end of that array inside the closing bracket add this ,"Gender"

Step 3. Add this function somewhere after all the other functions but before the save function (for neatness mainly)
Code:
    protected function applyGender(OwnedItem $item, OwnedAdoptable $adopt){
        $mysidia = Registry::get("mysidia");
        $oldGender = $adopt->getGender();
        if($oldGender == "f"){
            $gender = "m";
            $adopt->setGender($gender, "update");
        }elseif($oldGender == "m"){
            $gender = "f";
            $adopt->setGender($gender, "update");
        }else{
            throw new ItemException("There is a problem with changing the gender of this adoptable.");
        }
        return "Your adoptable {$adopt->getName()} has had its gender successfully changed";
    }

Step 4. Add the function in the item_functions table in the database like this:
Screenshot 2024-01-27 at 15-57-32 localhost _ MySQL _ mysidia _ adopts_items_functions phpMyAd...png

Now all you have to do is create an item that uses Gender as the Gender item function and it should work. Here's my test: Screenshot 2024-01-27 at 16-06-37 Mysidia1.3.6.png
Screenshot 2024-01-27 at 16-07-11 Mysidia1.3.6.png
 
Seems to be working perfectly for me too , thank you so much!
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

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

Latest Threads

Latest Posts

Top