Skip to content

Instantly share code, notes, and snippets.

@Znote
Last active June 26, 2020 12:39
Show Gist options
  • Save Znote/ed8335bd14d7d49d341a8e7b03c9401b to your computer and use it in GitHub Desktop.
Save Znote/ed8335bd14d7d49d341a8e7b03c9401b to your computer and use it in GitHub Desktop.
Player reset page for Znote AAC
<?php require_once 'engine/init.php'; protect_page(); include 'layout/overall/header.php';
// 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, $player_id = 0) {
$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`,
`p`.`reset`,
CASE WHEN `o`.`player_id` IS NULL
THEN 0
ELSE 1
END AS `online`,
CASE WHEN `a`.`premdays` > 0 THEN
CASE
WHEN `p`.`reset` >= 15 THEN 360
WHEN (`p`.`reset` BETWEEN 10 and 14) THEN 355
WHEN (`p`.`reset` BETWEEN 5 and 9) THEN 340
WHEN (`p`.`reset` BETWEEN 0 and 4) THEN 330
ELSE 330
END
ELSE
CASE
WHEN `p`.`reset` >= 10 THEN 360
WHEN (`p`.`reset` BETWEEN 5 and 9) THEN 355
WHEN (`p`.`reset` BETWEEN 0 and 4) THEN 350
ELSE 350
END
END AS `requirement`,
CASE WHEN `a`.`premdays` > 0 THEN
CASE
WHEN `p`.`reset` >= 15 AND `p`.`level` >= 360 THEN 1
WHEN (`p`.`reset` BETWEEN 10 and 14) AND `p`.`level` >= 355 THEN 1
WHEN (`p`.`reset` BETWEEN 5 and 9) AND `p`.`level` >= 340 THEN 1
WHEN (`p`.`reset` BETWEEN 0 and 4) AND `p`.`level` >= 330 THEN 1
ELSE 0
END
ELSE
CASE
WHEN `p`.`reset` >= 10 AND `p`.`level` >= 360 THEN 1
WHEN (`p`.`reset` BETWEEN 5 and 9) AND `p`.`level` >= 355 THEN 1
WHEN (`p`.`reset` 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`
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, $player_id);
if ($player !== false && !empty($player)) {
$player = $player[0];
if ($player['can_reset'] == 1) {
if ($player['online'] == 0) {
mysql_update("
UPDATE `players` SET
`reset` = (`reset`+1),
`level` = 8,
`experience` = 4200
WHERE `id`={$player_id}
");
?><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);
?>
<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'; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment