Restricting 1 Adopt to User with Promocodes Mod 1.3.5

Forum
Last Post
Threads / Messages

GeneticAlpha

Loving Mysidia!
Member
Joined
May 24, 2020
Messages
289
Points
28
Age
31
Location
Tennessee
Mysidian Dollar
13,392
Thanks to Ittermat and Kristhasirah I was able to get this code working. Basically, when users claim adopts through the promocode system, conditions don't work. Because the Mysidia script applies conditions to adopts purchased through the adopt shop. So now, my promocode area blocks users from getting more than one of this specific adopt I set, which is Dimas. The only file you need to mod is promo.php.

In the public function index you'll find the input->post code, this:​
if($mysidia->input->post("promocode")){
$mysidia->session->validate("promo");
$promo = new Promocode($mysidia->input->post("promocode"));
switch($promo->pid){
case 0:
throw new PromocodeException("fail");
break;
default:
if($promo->validate($mysidia->input->post("promocode"))) $promo->execute();
}
$mysidia->session->terminate("promo");
return;
}
$mysidia->session->assign("promo", 1);
}
and we're going to change it to this:​
$check = $mysidia->db->select("owned_adoptables", array("type"), "type='Mitikabe' and owner = '{$mysidia->user->username}'")->rowCount();
$dimas = $mysidia->db->select("owned_adoptables",array("type"),"type='Mitikabe' and owner='{$mysidia->user->username}'")->rowCount();

if($mysidia->input->post("promocode") == '779369439249332' and $dimas >= 1){
$mysidia = Registry::get("mysidia");
$this->setFlags("error", "<br><br><b>Sorry, you have already claimed this code. If you believe this is a problem, please message an admin or moderator.</b>");
}
elseif($mysidia->input->post("promocode")){
$mysidia->session->validate("promo");
$promo = new Promocode($mysidia->input->post("promocode"));
switch($promo->pid){
case 0:
throw new PromocodeException("fail");
break;
default:
if($promo->validate($mysidia->input->post("promocode"))) $promo->execute();
}
$mysidia->session->terminate("promo");
return;
}
$mysidia->session->assign("promo", 1);
}
}

You'll need to change the 'type' areas because Mitikabe is my own species, of course lol, and change the $check and $dimas if you want. That 779369439249332 area is the promocode code, annnnd that's it! :)
 
An idea to make this reusable would be to make a db table for promocodes with a check if it's been used or not and who that code belongs to. This way, if you want each promocode to be unique and only one person claim it, they can't go back and get multiple copies of that pet, or pass the code to friends. I worked on something like this for 1.2.4 but it's harder for me to wrap my head around OOP Mysidia, so maybe this idea can help those who know how to code the newer versions.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,295
Messages
33,186
Members
1,606
Latest member
kandriamage
BETA

Latest Threads

Latest Posts

Top