Advertisement
Sweetening

Untitled

Mar 19th, 2024
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. <?php
  2.  
  3. // Disallow direct access to this file for security reasons
  4. if (!defined("IN_MYBB")) {
  5. die("Direct initialization of this file is not allowed.");
  6. }
  7.  
  8. // Hook into post and thread creation to check for the flip command
  9. $plugins->add_hook("newreply_do_newreply_end", "process_flip_command");
  10. $plugins->add_hook("newthread_do_newthread_end", "process_flip_command");
  11.  
  12. function flipcoin_info() {
  13. return array(
  14. "name" => "Flip Coin",
  15. "description" => "Allows users to flip a coin and bet bytes, earning or losing them based on the result.",
  16. "website" => "http://yourwebsite.com",
  17. "author" => "Your Name",
  18. "authorsite" => "http://yourwebsite.com",
  19. "version" => "1.0",
  20. "compatibility" => "18*"
  21. );
  22. }
  23.  
  24. function flipcoin_activate() {
  25. global $db;
  26. // Ensure there's a 'bytes' column in the users table for tracking currency
  27. if (!$db->field_exists('bytes', 'users')) {
  28. $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD `bytes` INT NOT NULL DEFAULT '0'");
  29. }
  30. }
  31.  
  32. function flipcoin_deactivate() {
  33. // Cleanup tasks like removing or modifying the database are usually performed here
  34. // Caution is advised to not remove user data unintentionally
  35. // For this example, we'll leave the bytes column intact on deactivation
  36. }
  37.  
  38. function process_flip_command() {
  39. global $mybb, $db, $post;
  40.  
  41. // Check if the message contains the /flip command
  42. if (preg_match('/\/flip (\d+)/', $post['message'], $matches)) {
  43. $bet = (int)$matches[1];
  44. $uid = (int)$mybb->user['uid'];
  45.  
  46. // Retrieve user's current bytes
  47. $query = $db->simple_select("users", "bytes", "uid='{$uid}'");
  48. $userBytes = $db->fetch_field($query, "bytes");
  49.  
  50. if ($bet > 0 && $userBytes >= $bet) {
  51. // Flip the coin
  52. $result = rand(0, 1) ? "win" : "lose";
  53. $newBytes = $result === "win" ? ($userBytes + $bet) : ($userBytes - $bet);
  54.  
  55. // Update user's bytes
  56. $db->update_query("users", ["bytes" => $newBytes], "uid='{$uid}'");
  57.  
  58. // Append the result to the post's message
  59. $post['message'] .= "\n\n[b]Flip Result:[/b] You {$result}! You now have {$newBytes} bytes.";
  60. } else {
  61. // Not enough bytes or invalid bet
  62. $post['message'] .= "\n\n[b]Flip Error:[/b] Invalid bet or not enough bytes.";
  63. }
  64. }
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement