<?php require_once 'engine/init.php'; protect_page(); include 'layout/overall/header.php';
// Player storagevalue that keeps track of the resets
$playerStorage_reset = 378378;
// Get player List from logged in account, with extra data to see resets, if they can reset, level requirement for their reset.
function getSpecialPlayerList($account_id, $playerStorage_reset, $player_id = 0) {
$account_id = (int)$account_id;
$playerStorage_reset = (int)$playerStorage_reset;
$player_id = (int)$player_id;
$where_player = ($player_id > 0) ? "AND `p`.`id`={$player_id}" : "";
return mysql_select_multi("
SELECT
`p`.`id`,
`p`.`name`,
`p`.`level`,
IFNULL(`s`.`value`, 0) AS `reset`,
CASE WHEN `o`.`player_id` IS NULL
THEN 0
ELSE 1
END AS `online`,
CASE WHEN `a`.`premdays` > 0 THEN
CASE
WHEN IFNULL(`s`.`value`, 0) >= 15 THEN 360
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 10 and 14) THEN 355
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 5 and 9) THEN 340
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 0 and 4) THEN 330
ELSE 330
END
ELSE
CASE
WHEN IFNULL(`s`.`value`, 0) >= 10 THEN 360
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 5 and 9) THEN 355
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 0 and 4) THEN 350
ELSE 350
END
END AS `requirement`,
CASE WHEN `a`.`premdays` > 0 THEN
CASE
WHEN IFNULL(`s`.`value`, 0) >= 15 AND `p`.`level` >= 360 THEN 1
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 10 and 14) AND `p`.`level` >= 355 THEN 1
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 5 and 9) AND `p`.`level` >= 340 THEN 1
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 0 and 4) AND `p`.`level` >= 330 THEN 1
ELSE 0
END
ELSE
CASE
WHEN IFNULL(`s`.`value`, 0) >= 10 AND `p`.`level` >= 360 THEN 1
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 5 and 9) AND `p`.`level` >= 355 THEN 1
WHEN (IFNULL(`s`.`value`, 0) BETWEEN 0 and 4) AND `p`.`level` >= 350 THEN 1
ELSE 0
END
END AS `can_reset`
FROM `players` AS `p`
INNER JOIN `accounts` AS `a`
ON `p`.`account_id` = `a`.`id`
LEFT JOIN `players_online` AS `o`
ON `p`.`id` = `o`.`player_id`
LEFT JOIN `player_storage` AS `s`
ON `p`.`id` = `s`.`player_id`
AND `s`.`key` = {$playerStorage_reset}
WHERE `p`.`account_id` = {$account_id}
{$where_player}
");
}
// Get account_id of logged in player
$account_id = (int)$session_user_id;
// Handle reset action
$player_id = (isset($_POST['player_id'])) ? (int)getValue($_POST['player_id']) : false;
if ($player_id !== false) {
$player = getSpecialPlayerList($account_id, $playerStorage_reset, $player_id);
if ($player !== false && !empty($player)) {
$player = $player[0];
if ($player['can_reset'] == 1) {
if ($player['online'] == 0) {
mysql_update("
UPDATE `players` SET
`level` = 8,
`experience` = 4200
WHERE `id`={$player_id}
");
$playerStorage_reset = (int)$playerStorage_reset;
setPlayerStorage($player_id, $playerStorage_reset, (int)$player['reset'] + 1)
?><p><strong>Success:</strong> Player has been reset!</p><?php
} else {
?><p><strong>Error:</strong> player must be offline.</p><?php
}
} else {
?><p><strong>Error:</strong> You cannot reset this player.</p><?php
}
}
}
$playerList = getSpecialPlayerList($account_id, $playerStorage_reset);
?>
<h1>Player Reset System</h1>
<!-- If account don't have any players -->
<?php if (empty($playerList) || $playerList === false):
?>
<p>You don't have any players yet.</p>
<?php include 'layout/overall/footer.php'; exit();
endif; ?>
<!-- Player Reset Table -->
<table class="tbl_reset_player">
<thead>
<tr>
<th>Name</th>
<th>Resets</th>
<th>Level</th>
<th>Requirement</th>
<th>Reset</th>
</tr>
</thead>
<tbody>
<?php foreach($playerList as $player): ?>
<tr>
<td><?php echo $player['name']; ?></td>
<td><?php echo $player['reset']; ?></td>
<td><?php echo $player['level']; ?></td>
<td><?php echo $player['requirement']; ?></td>
<td>
<?php if ($player['can_reset'] == 1): ?>
<form action="" method="post">
<input type="hidden" name="player_id" value="<?php echo $player['id']; ?>">
<input type="submit" value="Reset">
</form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!-- Table CSS style -->
<style type="text/css">
.tbl_reset_player th {
padding: 5px;
line-height: 2.5;
}
.tbl_reset_player td {
text-align: center;
}
</style>
<?php include 'layout/overall/footer.php'; ?>