add to SQL
CREATE TABLE IF NOT EXISTS `teams` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(255) NOT NULL,
 `color` varchar(50) NOT NULL,
 `points` bigint(20) NOT NULL DEFAULT '0',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT IGNORE INTO `teams` (`id`, `name`, `color`, `points`) VALUES
(1, 'Archivists', '#ff4444', 0),
(2, 'Vanguard', '#44ff44', 0),
(3, 'The Network', '#4444ff', 0);


ALTER TABLE `users`
ADD `team_id` int(11) NOT NULL DEFAULT '0',
ADD `event_upload` bigint(20) unsigned NOT NULL DEFAULT '0',
ADD `event_seed_time` int(11) NOT NULL DEFAULT '0';


CREATE TABLE IF NOT EXISTS `team_battle_log` (
 `id` int(1) NOT NULL,
 `last_run_month` int(2) NOT NULL DEFAULT '0',
 `fl_expire` int(11) NOT NULL DEFAULT '0',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT IGNORE INTO `team_battle_log` (`id`, `last_run_month`, `fl_expire`) VALUES
(1, 0, 0),
(2, 0, 0);


in announce.php search
if ($MEMBERSONLY) {
   $res = SQL_Query_exec("SELECT u.id,


after add
u.team_id,


still in announce.php search
 if ($upthis > 0 || $down_val > 0) {
       SQL_Query_exec("UPDATE users SET uploaded = uploaded + $upthis, downloaded = downloaded + $down_val WHERE id = $userid");
   }


right after add
// --- TEAM BATTLE LOGIC ---
   $team_id = isset($user['team_id']) ? (int)$user['team_id'] : 0;
   if ($team_id > 0) {
       $points_earned = 0;
       $event_upload_add = 0;
       $event_seed_time_add = 0;

       if ($upthis > 0) {
           $points_earned += floor($upthis / 10485760);
           $event_upload_add = $upthis;
       }

      if ($left == 0) {
           $points_earned += 1;
           $event_seed_time_add = 1;
       }

       if ($points_earned > 0 || $event_upload_add > 0 || $event_seed_time_add > 0) {
           SQL_Query_exec("UPDATE users SET event_upload = event_upload + $event_upload_add, event_seed_time = event_seed_time + $event_seed_time_add WHERE id = $userid");
           if ($points_earned > 0) {
               SQL_Query_exec("UPDATE teams SET points = points + $points_earned WHERE id = $team_id");
           }
       }
   }
   // --- END TEAM BATTLE LOGIC ---


OPTIONAL: if you want if a user is on a team to show the team after username in functions.php search for
function class_user($name)


in query add team_id

stil in same function before
return unesc


add
    // --- Team Tag ---
   $team_tag = "";
   $team_id = (int)$classy[11];
   
   if ($team_id == 1) {
       $team_tag = " <span style='color: #ff4444; font-size: 10px; font-weight: bold;'>[Archivists]</span>";
   } elseif ($team_id == 2) {
       $team_tag = " <span style='color: #44ff44; font-size: 10px; font-weight: bold;'>[Vanguard]</span>";
   } elseif ($team_id == 3) {
       $team_tag = " <span style='color: #4444ff; font-size: 10px; font-weight: bold;'>[The Network]</span>";
   }
   // --- End Team Tag --


in cleanup.php
before last  ?> add
// =================================================================
// --- TEAM BATTLE ---
// =================================================================
$current_month = (int)date('n');
$current_day = (int)date('j');  

if ($current_day == 1) {
   
   
   SQL_Query_exec("CREATE TABLE IF NOT EXISTS `team_battle_log` (`id` int(1) NOT NULL, `last_run_month` int(2) NOT NULL DEFAULT '0', PRIMARY KEY (`id`))");
   SQL_Query_exec("INSERT IGNORE INTO `team_battle_log` (`id`, `last_run_month`) VALUES (1, 0)");
   
   
   $res_last_run = SQL_Query_exec("SELECT last_run_month FROM team_battle_log WHERE id = 1");
   $row_last_run = mysqli_fetch_assoc($res_last_run);
   $last_run_month = $row_last_run ? (int)$row_last_run['last_run_month'] : 0;

 
   if ($last_run_month !== $current_month) {
       
       
       SQL_Query_exec("UPDATE team_battle_log SET last_run_month = $current_month WHERE id = 1");
       
       
       $res_check = SQL_Query_exec("SELECT SUM(points) as total FROM teams");
       $check = mysqli_fetch_assoc($res_check);
       
       if ($check['total'] > 0) {
           $res_teams = SQL_Query_exec("SELECT id, name FROM teams ORDER BY points DESC");
           $rank = 1;
           $msg_date = get_date_time();

           while ($team = mysqli_fetch_assoc($res_teams)) {
               $team_id = $team['id'];
               
               
               $res_users = SQL_Query_exec("SELECT id, class FROM users WHERE team_id = $team_id AND (event_upload >= 10737418240 OR event_seed_time >= 100)");
               
               while ($user = mysqli_fetch_assoc($res_users)) {
                   $uid = $user['id'];
                   $uclass = $user['class'];
                   $bonus = 0;
                   $pm_msg = "";
                   $new_class = $uclass;

                   if ($rank == 1) {
                       $bonus = 50000;
                       if ($uclass < 7) { $new_class = 7; } //change with your VIP class ID
                       $pm_msg = "Congratulations! Your team " . $team['name'] . " finished in 1st Place this month! You have been awarded 1 Month VIP and $bonus Seedbonus points.";
                       
                       
                       $trophy_html = "<span title=\'Team Battle Winner - Month $current_month\' style=\'font-size: 20px; cursor: help;\'>🏆</span> ";
                       SQL_Query_exec("UPDATE users SET seedbonus = seedbonus + $bonus, class = $new_class, team_badges = CONCAT(IFNULL(team_badges, ''), '$trophy_html') WHERE id = $uid");

                   } elseif ($rank == 2) {
                       $bonus = 25000;
                       $pm_msg = "Great effort! Your team " . $team['name'] . " finished in 2nd Place this month. You received $bonus Seedbonus points.";
                       
                       SQL_Query_exec("UPDATE users SET seedbonus = seedbonus + $bonus, class = $new_class WHERE id = $uid");

                   } elseif ($rank == 3) {
                       $bonus = 10000;
                       $pm_msg = "Thanks for participating! Your team " . $team['name'] . " finished in 3rd Place this month. You received $bonus Seedbonus points.";
                       
                       SQL_Query_exec("UPDATE users SET seedbonus = seedbonus + $bonus, class = $new_class WHERE id = $uid");
                   }

                   SQL_Query_exec("INSERT INTO messages (sender, receiver, added, subject, msg, unread, location)
                                   VALUES (0, $uid, '$msg_date', 'Team Battle Results!', " . sqlesc($pm_msg) . ", 'yes', 'in')");
               }
               $rank++;
           }

           SQL_Query_exec("UPDATE users SET team_id = 0, event_upload = 0, event_seed_time = 0 WHERE team_id > 0");
           SQL_Query_exec("UPDATE teams SET points = 0");
       }
   }
}
// =================================================================
// --- END TEAM BATTLE ---
// =================================================================

// =================================================================
// --- TEAM BATTLE: MONITOR GLOBAL 500k GOAL & FREELEECH TIMER ---
// =================================================================
$global_goal = 500000; // Unlock threshold

// 1. CHECK IF FREELEECH EXPIRED (Turn it OFF)
$res_expire = SQL_Query_exec("SELECT fl_expire FROM team_battle_log WHERE id = 2");
$row_expire = mysqli_fetch_assoc($res_expire);

if ($row_expire && $row_expire['fl_expire'] > 0 && time() >= $row_expire['fl_expire']) {
   // 48 hours have passed! Remove freeleech and reset timer
   SQL_Query_exec("UPDATE torrents SET freeleech = 0");
   SQL_Query_exec("UPDATE team_battle_log SET fl_expire = 0 WHERE id = 2");
}

// 2. CHECK IF GOAL IS REACHED (Turn it ON)
$res_check_fl = SQL_Query_exec("SELECT SUM(points) as total FROM teams");
$check_fl = mysqli_fetch_assoc($res_check_fl);
$total_team_points = (int)$check_fl['total'];

if ($total_team_points >= $global_goal) {
   $current_month = (int)date('n');
   
   SQL_Query_exec("INSERT IGNORE INTO `team_battle_log` (`id`, `last_run_month`, `fl_expire`) VALUES (2, 0, 0)");
   
   $res_log_fl = SQL_Query_exec("SELECT last_run_month FROM team_battle_log WHERE id = 2");
   $row_log_fl = mysqli_fetch_assoc($res_log_fl);
   $fl_awarded_month = $row_log_fl ? (int)$row_log_fl['last_run_month'] : 0;
   
   if ($fl_awarded_month !== $current_month) {
       
       $expire_time = time() + (48 * 3600); // Current time + 48 hours in seconds
       
       // Block future runs this month AND set the expiration timer
       SQL_Query_exec("UPDATE team_battle_log SET last_run_month = $current_month, fl_expire = $expire_time WHERE id = 2");
       
       // ACTIVATE GLOBAL FREELEECH
       SQL_Query_exec("UPDATE torrents SET freeleech = 1");
   }
}
// =================================================================



in index where you want to show live stats
add
// --- Team Batlle ---
begin_frame("Team Battle - Live Standings");

$res_teams = SQL_Query_exec("SELECT name, color, points FROM teams ORDER BY points DESC");
$total_points = 0;

echo "<div style='width: 100%; max-width: 600px; margin: 0 auto; padding: 15px;'>";
while ($row_team = mysqli_fetch_assoc($res_teams)) {
   $total_points += $row_team['points'];
   
   echo "<div style='margin-bottom: 15px;'>";
   echo "<strong style='color: " . $row_team['color'] . ";'>" . htmlspecialchars($row_team['name']) . "</strong>: " . number_format($row_team['points']) . " Points";
   
   $percent = min(100, ($row_team['points'] / 100000) * 100);
   echo "<div style='background-color: #222; width: 100%; height: 25px; border-radius: 5px; border: 1px solid rgba(255,255,255,0.1); margin-top: 5px;'>";
   echo "<div style='background-color: " . $row_team['color'] . "; width: " . $percent . "%; height: 100%; border-radius: 4px; box-shadow: 0 0 10px " . $row_team['color'] . ";'></div>";
   echo "</div></div>";
}

// --- Global free (PvE) ---
$global_goal = 500000; //  500k points
$global_percent = min(100, ($total_points / $global_goal) * 100);

echo "<hr style='border: 0; border-top: 1px dashed rgba(255,255,255,0.2); margin: 25px 0 15px 0;'>";
echo "<div style='text-align: center; margin-bottom: 10px;'>";
echo "<strong style='color: #FFBF00; font-size: 16px;'>🌟 COMMUNITY GOAL: UNLOCK GLOBAL FREELEECH</strong><br>";
echo "<small style='color: #aaa;'>Work together! If all teams gather 500,000 points combined, a Freeleech Weekend will be triggered!</small>";
echo "</div>";

echo "<div style='background-color: #111; width: 100%; height: 30px; border-radius: 15px; border: 2px solid #FFBF00; position: relative; overflow: hidden;'>";
echo "<div style='background: linear-gradient(90deg, #ff8a00, #e52e71); width: " . $global_percent . "%; height: 100%; transition: width 1s ease;'></div>";
echo "<span style='position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); color: #fff; font-weight: bold; text-shadow: 1px 1px 2px #000;'>" . number_format($total_points) . " / " . number_format($global_goal) . " (" . number_format($global_percent, 1) . "%)</span>";
echo "</div>";

if ($total_points >= $global_goal) {
   echo "<div style='text-align: center; margin-top: 10px; color: #00ff00; font-weight: bold; font-size: 15px; animation: blinker 1s linear infinite;'>🎉 GOAL REACHED! FREELEECH UNLOCKED! 🎉</div>";
}

echo "<center style='margin-top: 20px;'><a href='teams.php' style='color: #0077CC; font-weight: bold;'>Join a Team / View Details</a></center>";
echo "</div>";

end_frame();
// --- end team batlle ---


add teams.php under public_html







i dont use teams as the default source if you want you can change in factions for example but that meand you wil need to change in all code also

if i forgot something just tell and ill give all

teams.php
Download
teams.php
Download
Last edited by djlive on 2026-11-01 23:44:37