Mys 1.3.5 Mod for auto generating promocodes & system PMs alerting 1.3.5

Forum
Last Post
Threads / Messages

GeneticAlpha

Loving Mysidia!
Member
Joined
May 24, 2020
Messages
287
Points
18
Age
31
Location
Tennessee
Mysidian Dollar
13,377
So I wanted a mod that allowed for a user to adopt a dinosaur on my site and the site auto create a promocode for the user to claim the dino with, that way I'm not having to manually create these codes to tie dinos to users. Because the dinosaurs are not tradeable like regular adopt pets and are not in shops, they need to be tied to a user and only available to that user once. But the system has to check and make sure the person doesn't already have the promocode for that dino or that dino as an adopt already if the code had been used. So you could use this in different ways, so you can just look at my code and see what I did and use pieces or whatever you need to do to use it how you want. The code works off a form button submit then if statements that are making checks on the database, that way it only displays certain information depending on what it read on the user.
I'm using a page made from scratch called dinopackagesmosbak which is my view file. I'm doing each dino a page like this, individualized to each dino, but you could actually just use one page and do like a group case or if/elseif statements. But anyway, for now, the dinopackagesmosbak is the only file I'm working in and this is the chunk of code in that file doing my promocode creation. Look below the chunk of code for a breakdown.
So file I'm coding in is dinopackagesmosbakview.php and you will need another page for where the user gets routed to after button submit. Mine is sponsoredview.php .

You'll also need to already of course have your dinos created in the database and their conditions for the promo to attach itself to.
$ownedname = $mysidia->db->select("owned_adoptables", array("name"), "owner ='{$mysidia->user->username}'")->fetchColumn();
$promo = $mysidia->db->select("promocodes", array("name"), "name='Mosbak'")->fetchColumn();

if($ownedname == "Mosbak" || $promo == "Mosbak"){
$document->add(new Comment("You have already sponsored Mosbak.<br>"));
}
else{
if ($mysidia->user->money >= 20000) {
$document->add(new Comment("<form action='../../dinopackagesmosbak' method='post'>

<input type='submit' class='button' name='mosbak' value='Sponsor Mosbak'>

</form>
<p id='p' style='color:green;'><br>You have enough Dino Bucks to adopt this dinosaur! Want to adopt?</p>"));
}
else {
$document->add(new Comment("<p style='color:red;'><b>Sorry, you do not have enough dinobucks to adopt Mosbak.<br></b></p>"));
}
if($mysidia->input->post("mosbak")){
$mosbak = $mysidia->db->select("owned_adoptables", array("name"), "owner ='{$mysidia->user->username}'")->fetchColumn();
$qty = $mysidia->db->select("promocodes", array("code"),"user ='{$mysidia->user->username}'")->fetchColumn();
$qty = $mysidia->db->select("promocodes", array("code"),"user ='{$mysidia->user->username}'")->rowCount();

$new_qty = $qty + 1;
$mysidia->db->insert("promocodes", array("pid" => NULL, "type" => "Adopt", "availability" => "1", "reward" => 'Spinosaurus', "user" => $mysidia->user->username, "name" => "Mosbak", "owner_nickname" => $mysidia->user->nickname, "uid" => $mysidia->user->uid, "personality" => "Easygoing | Submissive | Reliable | Obedient", "age" => "Adult", "class" => "Dinosaur", "code" => $new_qty,
"gender" => "m", "classification" => "Therapod", "fossil" => "Morocco", "height" => "23ft", "weight" => "17,000lbs", "length" => "52ft", "diet" => "Carnivore", "color" => "Greyish-beige, tan, black speckling, yellow, dark grey stripes, blue wavy stripes, red", "sex" => "Female"));
$cash = $mysidia->user->getcash();
$mysidia->user->changecash(-20000);
$cash = $mysidia->user->getcash();
$document->add(new Comment("
<meta http-equiv='refresh' content='0; url=/sponsored'> "));
$pm = new PrivateMessage(); // Send them a welcoming message
$pm->setsender('SYSTEM');
$pm->setrecipient(htmlentities(addslashes(trim($mysidia->user->username))));
$pm->setmessage("Adoption Successful!", "We have deducted 20000 Dino Bucks from your account for your adoption. Your sponsorship was successful.
<br>
<br>Your code to claim your dinosaur is: {$new_qty}
<br>You may now head on over to <a href='https://dinotracks.mysidiahost.com/promo'>Promos</a> to claim it.
<br>
<br>Thank you for adopting Mosbak today!
<br><br>- Dino Tracks Team");
$pm->post();

$pm = new PrivateMessage(); // Send a message
$pm->setsender('SYSTEM');
$pm->setrecipient('GeneticAlpha');
$pm->setmessage("Mosbak Adoption", "User {$mysidia->user->username} has adopted Mosbak through the adopt-a-dino page.");
$pm->post();

return;
}
}

So this piece:
$ownedname = $mysidia->db->select("owned_adoptables", array("name"), "owner ='{$mysidia->user->username}'")->fetchColumn();
$promo = $mysidia->db->select("promocodes", array("name"), "name='Mosbak'")->fetchColumn();
if($ownedname == "Mosbak" || $promo == "Mosbak"){}


is checking the database for if the promocode for this dino has already gotten by the user or if the dino is owned by the user already. If it is, then it says they have already sponsored the dino. Then else all the code for if they don't already have either of those two criteria.
else{
if ($mysidia->user->money >= 20000) {
$document->add(new Comment("<form action='../../dinopackagesmosbak' method='post'>

<input type='submit' class='button' name='mosbak' value='Sponsor Mosbak'>

</form>
<p id='p' style='color:green;'><br>You have enough Dino Bucks to adopt this dinosaur! Want to adopt?</p>"));
}


So you might notice in the else statement I added another if case. That's because the dino costs 20,000 Dinobucks to adopt. So I wanted this to only show up if the user had 20,000 in their hand. (I do have a bank system, but they still need money in hand. It won't read what you have in the bank) so if they do have it, the whole form shows up. If they don't, it says they don't have the money. So the form has a 'name' of 'name='mosbak' and this is what we use to tie to a if statement on if the form button is pressed.

if($mysidia->input->post("mosbak")){
$mosbak = $mysidia->db->select("owned_adoptables", array("name"), "owner ='{$mysidia->user->username}'")->fetchColumn();
$qty = $mysidia->db->select("promocodes", array("code"),"user ='{$mysidia->user->username}'")->fetchColumn();
$qty = $mysidia->db->select("promocodes", array("code"),"user ='{$mysidia->user->username}'")->rowCount();

$new_qty = $qty + 1;
$mysidia->db->insert("promocodes", array("pid" => NULL, "type" => "Adopt", "availability" => "1", "reward" => 'Spinosaurus', "user" => $mysidia->user->username, "name" => "Mosbak", "owner_nickname" => $mysidia->user->nickname, "uid" => $mysidia->user->uid, "personality" => "Easygoing | Submissive | Reliable | Obedient", "age" => "Adult", "class" => "Dinosaur", "code" => $new_qty,
"gender" => "m", "classification" => "Therapod", "fossil" => "Morocco", "height" => "23ft", "weight" => "17,000lbs", "length" => "52ft", "diet" => "Carnivore", "color" => "Greyish-beige, tan, black speckling, yellow, dark grey stripes, blue wavy stripes, red", "sex" => "Female"));
$cash = $mysidia->user->getcash();
$mysidia->user->changecash(-20000);
$cash = $mysidia->user->getcash();
$document->add(new Comment("
<meta http-equiv='refresh' content='0; url=/sponsored'> "));
$pm = new PrivateMessage(); // Send them a welcoming message
$pm->setsender('SYSTEM');
$pm->setrecipient(htmlentities(addslashes(trim($mysidia->user->username))));
$pm->setmessage("Adoption Successful!", "We have deducted 20000 Dino Bucks from your account for your adoption. Your sponsorship was successful.
<br>
<br>Your code to claim your dinosaur is: {$new_qty}
<br>You may now head on over to <a href='https://dinotracks.mysidiahost.com/promo'>Promos</a> to claim it.
<br>
<br>Thank you for adopting Mosbak today!
<br><br>- Dino Tracks Team");
$pm->post();

$pm = new PrivateMessage(); // Send a message
$pm->setsender('SYSTEM');
$pm->setrecipient('GeneticAlpha');
$pm->setmessage("Mosbak Adoption", "User {$mysidia->user->username} has adopted Mosbak through the adopt-a-dino page.");
$pm->post();

return;
}
}
So this is pretty straight forward I think. The first bit is saying if the form button was submitted
if($mysidia->input->post("mosbak")){ }
then the code all in there does everything such as taking money out of the user's account, adding a promocode to the promocodes table, redirecting the user to the confirmation page (sponsoredview.php) The promocode creating code is this:
$qty = $mysidia->db->select("promocodes", array("code"),"user ='{$mysidia->user->username}'")->fetchColumn();
$qty = $mysidia->db->select("promocodes", array("code"),"user ='{$mysidia->user->username}'")->rowCount();

$new_qty = $qty + 1;
$mysidia->db->insert("promocodes", array("pid" => NULL, "type" => "Adopt", "availability" => "1", "reward" => 'Spinosaurus', "user" => $mysidia->user->username, "name" => "Mosbak", "owner_nickname" => $mysidia->user->nickname, "uid" => $mysidia->user->uid, "personality" => "Easygoing | Submissive | Reliable | Obedient", "age" => "Adult", "class" => "Dinosaur", "code" => $new_qty,
"gender" => "m", "classification" => "Therapod", "fossil" => "Morocco", "height" => "23ft", "weight" => "17,000lbs", "length" => "52ft", "diet" => "Carnivore", "color" => "Greyish-beige, tan, black speckling, yellow, dark grey stripes, blue wavy stripes, red", "sex" => "Female"));


It does the checks on the system and the insert code here is so long because I added a LOT of extra info for my dinos. So only use the info in the database you want to have things inserted or it'll just leave it blank for you if you leave it out of the insert.

This code below is the PM that gets sent to the user for adopting the dino that holds their promocode that they can use to claim the dino.
$pm = new PrivateMessage(); // Send them a welcoming message
$pm->setsender('SYSTEM');
$pm->setrecipient(htmlentities(addslashes(trim($mysidia->user->username))));
$pm->setmessage("Adoption Successful!", "We have deducted 20000 Dino Bucks from your account for your adoption. Your sponsorship was successful.
<br>
<br>Your code to claim your dinosaur is: {$new_qty}
<br>You may now head on over to <a href='https://dinotracks.mysidiahost.com/promo'>Promos</a> to claim it.
<br>
<br>Thank you for adopting Mosbak today!
<br><br>- Dino Tracks Team");
$pm->post();


and then this next one is the PM I wanted sent to me so I can keep track of which dino is more popular and being adopted for funsies lol.
$pm = new PrivateMessage(); // Send a message
$pm->setsender('SYSTEM');
$pm->setrecipient('GeneticAlpha');
$pm->setmessage("Mosbak Adoption", "User {$mysidia->user->username} has adopted Mosbak through the adopt-a-dino page.");
$pm->post();


return;

annnnd that's it I'm pretty sure.
 

Attachments

  • mod.png
    mod.png
    1.7 MB · Views: 5
Last edited:
Update: I decided I wanted my systems to clean out any of these codes if they had been used, so this is the code I used. I used it on my user Account page in the class file, but you could probably put it on any main page a user is directed to everyday like a landing page upon logging in, etc.

$promocodeclass = $mysidia->db->select("promocodes", array("name"), "user ='{$mysidia->user->username}'")->fetchColumn();
$available = $mysidia->db->select("promocodes", array("availability"), "user ='{$mysidia->user->username}'")->fetchColumn();
if($promocodeclass == "Coby" || $promocodeclass == "Mikaia" || $promocodeclass == "Mosbak" ||$promocodeclass == "Toast" || $promocodeclass == "Gerald"||$promocodeclass == "Mac" ||
$promocodeclass == "Albion"|| $promocodeclass == "Azure" || $promocodeclass == "Allena" || $promocodeclass == "Marella" || $promocodeclass == "Oreo" || $promocodeclass == "Tracer"
|| $promocodeclass == "Terra" || $promocodeclass == "Sue" && $available == "0"){
$available = $mysidia->db->select("promocodes", array("availability"), "user ='{$mysidia->user->username}'")->fetchColumn();
$mysidia->db->delete("promocodes", "availability='0'");
}
 
Last edited:

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,274
Messages
33,115
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top