Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Disallow direct access to this file for security reasons
- if (!defined("IN_MYBB")) {
- die("Direct initialization of this file is not allowed.");
- }
- // Hook into post and thread creation to check for the flip command
- $plugins->add_hook("newreply_do_newreply_end", "process_flip_command");
- $plugins->add_hook("newthread_do_newthread_end", "process_flip_command");
- function flipcoin_info() {
- return array(
- "name" => "Flip Coin",
- "description" => "Allows users to flip a coin and bet bytes, earning or losing them based on the result.",
- "website" => "http://yourwebsite.com",
- "author" => "Your Name",
- "authorsite" => "http://yourwebsite.com",
- "version" => "1.0",
- "compatibility" => "18*"
- );
- }
- function flipcoin_activate() {
- global $db;
- // Ensure there's a 'bytes' column in the users table for tracking currency
- if (!$db->field_exists('bytes', 'users')) {
- $db->write_query("ALTER TABLE " . TABLE_PREFIX . "users ADD `bytes` INT NOT NULL DEFAULT '0'");
- }
- }
- function flipcoin_deactivate() {
- // Cleanup tasks like removing or modifying the database are usually performed here
- // Caution is advised to not remove user data unintentionally
- // For this example, we'll leave the bytes column intact on deactivation
- }
- function process_flip_command() {
- global $mybb, $db, $post;
- // Check if the message contains the /flip command
- if (preg_match('/\/flip (\d+)/', $post['message'], $matches)) {
- $bet = (int)$matches[1];
- $uid = (int)$mybb->user['uid'];
- // Retrieve user's current bytes
- $query = $db->simple_select("users", "bytes", "uid='{$uid}'");
- $userBytes = $db->fetch_field($query, "bytes");
- if ($bet > 0 && $userBytes >= $bet) {
- // Flip the coin
- $result = rand(0, 1) ? "win" : "lose";
- $newBytes = $result === "win" ? ($userBytes + $bet) : ($userBytes - $bet);
- // Update user's bytes
- $db->update_query("users", ["bytes" => $newBytes], "uid='{$uid}'");
- // Append the result to the post's message
- $post['message'] .= "\n\n[b]Flip Result:[/b] You {$result}! You now have {$newBytes} bytes.";
- } else {
- // Not enough bytes or invalid bet
- $post['message'] .= "\n\n[b]Flip Error:[/b] Invalid bet or not enough bytes.";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement