• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[Modern AAC] Auction characters

averatec

Advanced OT User
Joined
Jun 1, 2007
Messages
2,243
Solutions
4
Reaction score
159
Location
Poland
Code:
<?php

//[email protected]
/*
  In MySQL:
  CREATE TABLE `characters_auctions` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `state` TINYINT( 1 ) NOT NULL DEFAULT '0' ,
  `finish_time` INT NOT NULL ,
  `char_id` INT NOT NULL ,
  `buy_now` INT NOT NULL ,
  `bid` INT NOT NULL ,
  `bidder` INT NOT NULL ,
  INDEX ( `finish_time` ));
 */

$LINK = WEBSITE . '/index.php/p/v/sellchar';

$config = array();
$config['donator_enabled'] = false;
$config['time_to_finish'] = 7 * 24 * 60 * 60;
$config['max_start_bid'] = 100;
$config['max_buy_now'] = 10000;

$ots = POT::getInstance();
$ots->connect(POT::DB_MYSQL, connection());
$SQL = $ots->getDBHandle();
$uri = $this->uri->uri_to_assoc();
$params = array();
$i = 0;
foreach ($uri as $key => $value) {
	if ($i == 0) {
		$params[$i] = $value;
		$i++;
	} else {
		$params[$i] = $key;
		$i++;
		$params[$i] = $value;
		$i++;
	}
}
$action = $params[0];
$logged = $ide->isLogged();
$account_logged = null;
if ($logged) {
	$account_logged = $ots->createObject('Account');
	$account_logged->load($ide->loggedAccountId());
}
$admin = $ide->isAdmin();

function time_left($integer) {
	$weeks = 0;
	$days = 0;
	$hours = 0;
	$minutes = 0;
	$second = 0;
	$return = null;
	if ($integer <= 0)
		return "Finished";
	$seconds = $integer;
	if ($seconds / 60 >= 1) {
		$minutes = floor($seconds / 60);
		if ($minutes / 60 >= 1) { # Hours  
			$hours = floor($minutes / 60);
			if ($hours / 24 >= 1) { #days  
				$days = floor($hours / 24);
				if ($days / 7 >= 1) { #weeks  
					$weeks = floor($days / 7);
					if ($weeks >= 2)
						$return = "$weeks weeks";
					else
						$return = "$weeks week";
				} #end of weeks  
				$days = $days - (floor($days / 7)) * 7;
				if ($weeks >= 1 && $days >= 1)
					$return = "$return, ";
				if ($days >= 2)
					$return = "$return $days d";
				if ($days == 1)
					$return = "$return $days d";
			} #end of days 
			$hours = $hours - (floor($hours / 24)) * 24;
			if ($days >= 1 && $hours >= 1)
				$return = "$return, ";
			if ($hours >= 2 || $hours == 0)
				$return = "$return $hours h";
			if ($hours == 1)
				$return = "$return $hours h";
		} #end of Hours 
		$minutes = $minutes - (floor($minutes / 60)) * 60;
		if ($hours >= 1 && $minutes >= 1)
			$return = "$return, ";
		if ($minutes >= 2 || $minutes == 0)
			$return = "$return $minutes m";
		if ($minutes == 1)
			$return = "$return $minutes m";
	} #end of minutes  
	$seconds = $integer - (floor($integer / 60)) * 60;
	if ($minutes >= 1 && $seconds >= 1)
		$return = "$return, ";
	if ($seconds >= 2 || $seconds == 0)
		$return = "$return $seconds sec";
	if ($seconds == 1)
		$return = "$return $seconds sec";
	$return = "$return.";
	return $return;
}

foreach ($SQL->query('SELECT * FROM `characters_auctions` WHERE `state` = 0 AND `finish_time` <= ' . time())->fetchAll() as $finishedAuction) {
	if ($finishedAuction['bidder'] > 0) {
		$finishedAuctionBidder = new OTS_Account();
		$finishedAuctionBidder->load($finishedAuction['bidder']);
		$finishedAuctionChar = new OTS_Player();
		$finishedAuctionChar->load($finishedAuction['char_id']);
		$finishedAuctionOwner = new OTS_Account();
		$finishedAuctionOwner->load($finishedAuctionChar->getAccount()->getId());
		$finishedAuctionOwner->setPremiumPoints($finishedAuctionOwner->getPremiumPoints() + $finishedAuction['bid']);
		$finishedAuctionOwner->save();
		$finishedAuctionChar->setAccount($finishedAuctionBidder);
		$finishedAuctionChar->setGroup(1);
		$finishedAuctionChar->save();
		$finishedAuctionChar->setCustomField('deleted', 0);
		$SQL->query('UPDATE `characters_auctions` SET `state` = 2 WHERE `id` = ' . $finishedAuction['id']);
		$SQL->query('INSERT INTO `bans` (`id` , `type` , `value` ,`param` ,`active` ,`expires` ,`added` ,`admin_id` ,`comment` ,`reason` ,`action` ,`statement`) VALUES (NULL , 2, ' . $auctionChar->getId() . ', 2, 1, -1, ' . time() . ', 1, \'BUY CHAR\', 0, 1, \'\');');
	}
	else
		$SQL->query('UPDATE `characters_auctions` SET `state` = 1 WHERE `id` = ' . $finishedAuction['id']);
}

echo '<script type="text/javascript">function countdown(a,b){if(a<=0){document.getElementById(b).innerHTML="Finished";return 0}setTimeout(countdown,1e3,a-1,b);days=Math.floor(a/(60*60*24));a%=60*60*24;hours=Math.floor(a/(60*60));a%=60*60;minutes=Math.floor(a/60);a%=60;seconds=a;dps="s";hps="s";mps="s";sps="s";if(days==1)dps="";if(hours==1)hps="";if(minutes==1)mps="";if(seconds==1)sps="";innerHTML=days+" day"+dps+" ";innerHTML+=hours+" hour"+hps+" ";innerHTML+=minutes+" minute"+mps+" and ";innerHTML+=seconds+" second"+sps;document.getElementById(b).innerHTML=innerHTML}function checkBuyNow(a,b,c){if(!checkLogin(a))return false;if(b<c){alert("This character cost "+c+". You have only "+b+".");return false}var d=confirm("This character cost "+c+". Do you want to buy it?");if(d)return true;else return false}function checkBid(a,b,c,d){if(!checkLogin(a))return false;var e=window.document.getElementById("bid").value;if(e<=d){alert("Current highest bid is "+d+". You can not bid "+e+".");return false}if(e>c){alert("You can not bid "+e+". You have only "+c+".");return false}if(a==b){var f=confirm("You have highest bid in this auction. Are you sure you want make higher bid?");if(f)return true;else return false}return true}function checkLogin(a){if(a==0){alert("You are not logged in.");return false}return true}var innerHTM</script>';

switch ($action) {
	case "add":
		if ($logged) {
			echo '<h1><center>Add Auction</center></h1><br/><br/>';
			$players = $account_logged->getPlayers();
			$id_arr = array();
			foreach ($players as $player) {
				$id_arr[] = $player->getId();
			}
			$auctions = $SQL->query('SELECT * FROM `characters_auctions` WHERE `char_id` IN (' . implode(',', $id_arr) . ') AND `state` = 0')->fetchAll();
			$in_auction = array();
			foreach ($auctions as $auction) {
				$in_auction[] = $auction['char_id'];
			}

			if (isset($_POST['submit'])) {
				$errors = array();
				$_POST['char'] = isset($_POST['char']) ? $_POST['char'] : "";
				$_POST['bid'] = isset($_POST['bid']) ? $_POST['bid'] : 0;
				if ($_POST['bid'] < 0)
					$_POST['bid'] = 0;
				if (isset($_POST['buy_now']) && $_POST['buy_now'] < 0)
					$_POST['buy_now'] = 0;
				if (in_array($_POST['char'], $in_auction)) {
					$errors[] = "This character is aleardy in auction.";
				}
				if (!in_array($_POST['char'], $id_arr)) {
					$errors[] = "This character isn't your.";
				}
				if ($_POST['bid'] > $config['max_start_bid']) {
					$errors[] = "Too high starting bid.";
				}
				if ($_POST['buy_now'] > $config['max_buy_now']) {
					$errors[] = "Too high buy now price.";
				}

				if (count($errors) == 0) {
					$priceAuction = (int) $_POST['bid'];
					$priceBuyNow = (int) isset($_POST['buy_now']) ? $_POST['buy_now'] : 0;
					$auctionTime = (int) $config['time_to_finish'];
					$SQL->query('INSERT INTO `characters_auctions` (`id` ,`finish_time` ,`char_id` ,`buy_now` ,`bid` ,`bidder`) VALUES (NULL , ' . (time() + $auctionTime) . ', ' . $SQL->quote($_POST['char']) . ', ' . $priceBuyNow . ', ' . $priceAuction . ', 0);');
					$char = new OTS_Player();
					$char->load($_POST['char']);
					$char->setCustomField('deleted', 1);
					echo 'Your auction has been added successfully!';
				} else {
					echo 'ERRORS:<br/>';
					foreach ($errors as $error)
						echo $error . '<br/>';
				}
			} else {
				echo '<form action="" method="post"><table>';
				echo '<tr><td>Bid:</td><td><input type="text" name="bid" /></td></tr>';
				echo '<tr><td>Buy now:</td><td><input type="text" name="buy_now" /><small>(leave empty if don\'t want to use it)</small></td></tr>';
				echo '<tr><td>Select character:</td><td><select name="char"><option value="" disabled=disabled selected=selected>';
				foreach ($players as $player) {
					$disabled = "";
					if (in_array($player->getId(), $in_auction))
						$disabled = " disabled=disabled";
					echo '<option value="' . $player->getId() . '" ' . $disabled . '>' . $player->getName() . '</option>';
				}
				echo '</select></td></tr></table><br/>';
				echo '<input type="submit" name="submit" value="ADD" />';
			}
			echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'" class="linkButton">BACK</a></div>';
		} else
			echo 'You are not logged in.';
		break;

	case "show":
		$auctionInfo = $SQL->query('SELECT * FROM `characters_auctions` WHERE `id` = ' . $SQL->quote((int) $params[1]))->fetch();
		echo '<h1><center>Auction Info</center></h1>';
		if (isset($auctionInfo['id'])) {
			$auctionChar = new OTS_Player();
			$auctionChar->load($auctionInfo['char_id']);
			if ($auctionChar->isLoaded()) {
				echo '<table style="margin-left: auto;margin-right: auto;">';
				echo '<tr><td colspan="3">CHARACTER INFO</td></tr>';
				echo '<tr><td><table style="width: 360px;border-spacing: 1px">';
				echo '<tr><td>AUCTION ID:</td><td>' . $auctionInfo['id'] . '</td></tr>';
				echo '<tr><td>Name:</td><td>' . $auctionChar->getName() . '<br /><div style="font-size: 8pt;">(You select new name when you win auction.)</div></td></tr>';
				echo '<tr><td>Level:</td><td>' . $auctionChar->getLevel() . '</td></tr>';
				echo '<tr><td>Vocation:</td><td>' . getVocationName($auctionChar->getVocation(), $auctionChar->getPromotion()) . '</td></tr>';
				echo '<tr><td>Health:</td><td>' . $auctionChar->getHealthMax() . '</td></tr>';
				echo '<tr><td>Mana:</td><td>' . $auctionChar->getManaMax() . '</td></tr>';
				echo '<tr><td>Magic level:</td><td>' . $auctionChar->getMagLevel() . '</td></tr>';
				echo '<tr><td>Sword:</td><td>' . $auctionChar->getSkill(2) . '</td></tr>';
				echo '<tr><td>Axe:</td><td>' . $auctionChar->getSkill(3) . '</td></tr>';
				echo '<tr><td>Club:</td><td>' . $auctionChar->getSkill(1) . '</td></tr>';
				echo '<tr><td>Distance:</td><td>' . $auctionChar->getSkill(4) . '</td></tr>';
				echo '<tr><td>Shielding:</td><td>' . $auctionChar->getSkill(5) . '</td></tr>';
				echo '</table><td>';
				$player_items = array();
				for ($i = 1; $i <= 10; $i++) {
					$player_items[$i] = 0;
				}
				foreach ($SQL->query('SELECT * FROM `player_items` WHERE `player_id` = ' . $auctionChar->getId() . ' AND `pid` >= 1 AND `pid` <= 10;') as $item)
					$player_items[$item['pid']] = $item['itemtype'];
				echo '<td><table style="border-spacing: 1px">';
				echo '<tr><td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/2.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[2] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/1.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[1] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/3.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[3] . '.gif" alt="" class="showItemImage"/></td></tr>';
				echo '<tr><td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/6.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[6] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/4.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[4] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/5.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[5] . '.gif" alt="" class="showItemImage"/></td></tr>';
				echo '<tr><td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/9.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[9] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/7.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[7] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/10.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[10] . '.gif" alt="" class="showItemImage"/></td></tr>';
				echo '<tr><td class="showItemSquare" style="text-align: center">Soul:<br />' . $auctionChar->getSoul() . '</td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/8.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[8] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="text-align: center">Cap:<br />' . $auctionChar->getCap() . '</td></tr>';
				echo '</tr></table></td>';
				echo '</tr></table>';
				if ($config['donator_enabled']) {
					$donators_items = $SQL->query('SELECT `player_items`.`itemtype`, SUM(`player_items`.`count`) AS count, `z_shop_offer`.`offer_name` AS name FROM `player_items`, `z_shop_offer` WHERE `player_items`.`player_id` = ' . $auctionChar->getId() . ' AND `z_shop_offer`.`offer_type` = \'item\' AND `player_items`.`itemtype` = `z_shop_offer`.`itemid1` GROUP BY `player_items`.`itemtype`;')->fetchAll();
					$donators_depotitems = $SQL->query('SELECT `player_depotitems`.`itemtype`, SUM(`player_depotitems`.`count`) AS count, `z_shop_offer`.`offer_name` AS name FROM `player_depotitems`, `z_shop_offer` WHERE `player_depotitems`.`player_id` = ' . $auctionChar->getId() . ' AND `z_shop_offer`.`offer_type` = \'item\' AND `player_depotitems`.`itemtype` = `z_shop_offer`.`itemid1` GROUP BY `player_depotitems`.`itemtype`;')->fetchAll();
					if (count($donators_items) > 0 || count($donators_depotitems) > 0) {
						echo '<table style="margin-left: auto;margin-right: auto;padding-top: 30px;">';
						if (count($donators_items) > 0) {
							echo '<tr><td colspan="3">DONATORS ITEMS</td></tr>';
							$row = 0;
							foreach ($donators_items as $donator_item)
								echo '<tr><td><img src="' . WEBSITE . '/public/images/items/' . $donator_item['itemtype'] . '.gif" alt="" class="showItemImage"/></td><td>' . $donator_item['count'] . 'x</td><td>' . $donator_item['name'] . '</td></tr>';
						}
						if (count($donators_depotitems) > 0) {
							echo '<tr><td colspan="3">DONATORS IN DEPOT</td></tr>';
							$row = 0;
							foreach ($donators_depotitems as $donator_depotitem)
								echo '<tr><td class="showItemSquare"><img src="' . WEBSITE . '/public/images/items/' . $donator_depotitem['itemtype'] . '.gif" alt="" class="showItemImage"/></td><td>' . $donator_depotitem['count'] . 'x</td><td>' . $donator_depotitem['name'] . '</td></tr>';
						}
						echo '</table>';
					}
				}
				echo '<table style="margin-left: auto;margin-right: auto;padding-top: 30px;">';
				echo '<tr><td colspan="2">AUCTION INFO</td></tr>';
				if ($auctionInfo['buy_now'] > 0)
					echo '<tr><td>Buy now:</td><td>' . $auctionInfo['buy_now'] . ' premium points</td></tr>';
				echo '<tr><td>Highest bid:</td><td>' . $auctionInfo['bid'] . ' premium points</td></tr>';
				echo '<tr><td>Time left:</td><td><div name="timer_' . $auctionInfo['id'] . '" id="timer_' . $auctionInfo['id'] . '">' . time_left($auctionInfo['finish_time'] - time()) . '</div></td></tr>';
				echo '</table><br /><script type="text/javascript">countdown(' . ($auctionInfo['finish_time'] - time()) . ', \'timer_' . $auctionInfo['id'] . '\');</script>';
				if ($auctionInfo['state'] == 0) {
					echo '<form action="'.$LINK.'/bid/' . $auctionInfo['id'] . '" method="post" onsubmit="return checkBid(' . (($logged) ? $account_logged->getId() : 0) . ', ' . $auctionInfo['bidder'] . ', ' . (($logged) ? $account_logged->getPremiumPoints() : 0) . ', ' . $auctionInfo['bid'] . ');">';
					echo '<table style="float: left;">';
					echo '<tr><td colspan="2">YOUR BID</td></tr>';
					echo '<tr><td>Bid:</td><td><input type="text" id="bid" name="bid" value="' . ($auctionInfo['bid'] + 1) . '" /> pp</td></tr>';
					echo '<tr><td colspan="2" style="text-align: center;"><input type="submit" value="BID" /></td></tr></table></form><br />';
					if ($auctionInfo['buy_now'] > 0)
						echo '<a href="'.$LINK.'/buy/' . $auctionInfo['id'] . '" class="linkButton" style="float: right;" onclick="return checkBuyNow(' . (($logged) ? $account_logged->getId() : 0) . ', ' . (($logged) ? $account_logged->getPremiumPoints() : 0) . ', ' . $auctionInfo['buy_now'] . ');">BUY NOW!</a>';
				}
				echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'" class="linkButton">BACK</a></div>';
			}
			else
				echo 'ERROR! Character doesn\'t exist.';
		}
		else
			echo 'ERROR! Auction with this ID doesn\'t exist.';
		break;
	case "bid":
		echo '<h1><center>Bid character</center></h1>';
		if ($logged) {
			$auctionInfo = $SQL->query('SELECT * FROM `characters_auctions` WHERE `state` = 0 AND `id` = ' . $SQL->quote((int) $params[1]))->fetch();
			if (isset($auctionInfo['id'])) {
				$auctionChar = new OTS_Player();
				$auctionChar->load($auctionInfo['char_id']);
				if ($auctionChar->isLoaded()) {
					if ($account_logged->getPremiumPoints() > $auctionInfo['bid'] || ($account_logged->getId() == $auctionInfo['bidder'] && $account_logged->getPremiumPoints() > 0)) {
						if (isset($_POST['bid']) && (int) $_POST['bid'] > 0) {
							$userBid = (int) $_POST['bid'];
							if ($account_logged->getPremiumPoints() >= $userBid || ($account_logged->getId() == $auctionInfo['bidder'] && $account_logged->getPremiumPoints() + $auctionInfo['bid'] >= $userBid)) {
								if ($userBid > $auctionInfo['bid']) {
									if ($account_logged->getId() != $auctionInfo['bidder']) {
										$last_bidder = new OTS_Account();
										$last_bidder->load($auctionInfo['bidder']);
										if ($last_bidder->isLoaded()) {
											$last_bidder->setPremiumPoints($last_bidder->getPremiumPoints() + $auctionInfo['bid']);
											$last_bidder->save();
										}
										$account_logged->setPremiumPoints($account_logged->getPremiumPoints() - $userBid);
									}
									else
										$account_logged->setPremiumPoints($account_logged->getPremiumPoints() + $auctionInfo['bid'] - $userBid);
									$account_logged->save();
									$SQL->query('UPDATE `characters_auctions` SET `bid` = ' . $SQL->quote($userBid) . ', `bidder` = ' . $account_logged->getId() . ' WHERE `id` = ' . $auctionInfo['id']);
									if ($auctionInfo['finish_time'] - time() < 60)
										$SQL->query('UPDATE `characters_auctions` SET `finish_time` = ' . time() + 60 . ' WHERE `id` = ' . $auctionInfo['id']);
									echo '<div>You have bidded ' . $userBid . ' premium points on auction ID ' . $auctionInfo['id'] . '!</div>';
									echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'/show/' . $auctionInfo['id'] . '" class="linkButton">BACK</a></div>';
								}
								else
									echo 'Sorry! Your bid is lower then current highest bid.<br />Your bid is: ' . $userBid . '<br />Highest bid: ' . $auctionInfo['bid'];
							}
							else
								echo 'Sorry! You do not have enought premium points.<br />Your bid is: ' . $userBid . '<br />You have: ' . $account_logged->getPremiumPoints();
						}
						else
							echo 'You must bid more then 0.';
					}
					else
						echo 'Sorry! You do not have enought premium points.<br />Highest bid is: ' . $auctionInfo['bid'] . '<br />You have: ' . $account_logged->getPremiumPoints();
				}
				else
					echo 'ERROR! Character doesn\'t exist.';
			}
			else
				echo 'ERROR! Auction with this ID doesn\'t exist.';
		}
		else
			echo 'You are not logged in.';
		break;
	case "buy":
		echo '<h1><center>Buy character</center></h1>';
		if ($logged) {
			$auctionInfo = $SQL->query('SELECT * FROM `characters_auctions` WHERE `state` = 0 AND `id` = ' . $SQL->quote((int) $params[1]))->fetch();
			if (isset($auctionInfo['id'])) {
				if ($auctionInfo['buy_now'] > 0) {
					$auctionChar = new OTS_Player();
					$auctionChar->load($auctionInfo['char_id']);
					if ($auctionChar->isLoaded()) {
						if ($account_logged->getPremiumPoints() >= $auctionInfo['buy_now'] || ($account_logged->getId() == $auctionInfo['bidder'] && $account_logged->getPremiumPoints() + $auctionInfo['bid'] >= $auctionInfo['buy_now'])) {
							if ($account_logged->getId() != $auctionInfo['bidder']) {
								$last_bidder = new OTS_Account();
								$last_bidder->load($auctionInfo['bidder']);
								if ($last_bidder->isLoaded()) {
									$last_bidder->setPremiumPoints($last_bidder->getPremiumPoints() + $auctionInfo['bid']);
									$last_bidder->save();
								}
								$account_logged->setPremiumPoints($account_logged->getPremiumPoints() - $auctionInfo['buy_now']);
							}
							else
								$account_logged->setPremiumPoints($account_logged->getPremiumPoints() + $auctionInfo['bid'] - $auctionInfo['buy_now']);
							$account_logged->save();
							$finishedAuctionOwner = new OTS_Account();
							$finishedAuctionOwner->load($auctionChar->getAccount()->getId());
							$finishedAuctionOwner->setPremiumPoints($finishedAuctionOwner->getPremiumPoints() + $auctionInfo['buy_know']);
							$finishedAuctionOwner->save();
							$auctionChar->setAccount($account_logged);
							$auctionChar->setGroup(1);
							$auctionChar->save();
							$auctionChar->setCustomField('deleted', 0);
							$SQL->query('INSERT INTO `bans` (`id` , `type` , `value` ,`param` ,`active` ,`expires` ,`added` ,`admin_id` ,`comment` ,`reason` ,`action` ,`statement`) VALUES (NULL , 2, ' . $auctionChar->getId() . ', 2, 1, -1, ' . time() . ', 1, \'BUY CHAR\', 0, 1, \'\');');
							$SQL->query('UPDATE `characters_auctions` SET `state` = 2, `finish_time` = ' . time() . ', `bidder` = ' . $account_logged->getId() . ', `bid` = `buy_now` WHERE `id` = ' . $auctionInfo['id']);
							echo '<div>You have bought new character! Character is now on your account. Login in game and select new name for your character.</div>';
							echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'" class="linkButton">BACK</a></div>';
						}
						else
							echo 'Sorry! You do not have enought premium points.<br />It cost: ' . $auctionInfo['buy_now'] . '<br />You have: ' . $account_logged->getPremiumPoints() . '' . $errorFormEnd;
					}
					else
						echo 'ERROR! Character doesn\'t exist.';
				}
				else
					echo 'ERROR! You can not buy this character by Buy Now option. You can only Bid on auction.';
			}
			else
				echo 'ERROR! Auction with this ID doesn\'t exist.';
		}
		else
			echo 'You are not logged in.';
		break;

	default:
		echo '<h1><center>Characters Auctions</center></h1>';
		echo '<br/>With this system you can buy un-used (inactive) characters by auctioning for them. When you bid on a character it will automatically take premium points from your account. If someone out-bids you, you will get those premium points added back to your account. If the auction time is under 2 minutes when someone bids, 1 minute will automatically be added to the auction time to give time for a re-bid from the previous bidder. If you choose to "buy now" you will get the character within 1 minute.<br/><br/>';
		echo '<table width="100%"><tr style="font-size: 14px;text-align: center"><td>Time left</td><td>Char info</td><td>Buy now</td><td>Highest bid</td></tr>';
		$timers = array();
		foreach ($SQL->query('SELECT * FROM `characters_auctions` WHERE `finish_time` > ' . time())->fetchAll() as $auctionInfo) {
			$auctionChar = new OTS_Player();
			$auctionChar->load($auctionInfo['char_id']);
			if ($auctionChar->isLoaded())
				echo '<tr style="font-size: 12px;text-align: center" onclick="window.location = \''.$LINK.'/show/' . $auctionInfo['id'] . '\'"><td><div id="timer_' . $auctionInfo['id'] . '">' . time_left($auctionInfo['finish_time'] - time()) . '</div></td><td>' . $auctionChar->getLevel() . ' ' . getVocationName($auctionChar->getVocation(), $auctionChar->getPromotion()) . '</td><td>' . $auctionInfo['buy_now'] . ' pp</td><td>' . $auctionInfo['bid'] . ' pp</td></tr>';
			$timers['timer_' . $auctionInfo['id']] = $auctionInfo['finish_time'] - time();
		}
		echo '</table><br />Press on auction to get more informations.';
		echo '<script type="text/javascript">';
		if (count($timers) > 0) {
			foreach ($timers as $timer_id => $time_left)
				echo 'countdown(' . $time_left . ', \'' . $timer_id . '\');';
		}
		echo '</script>';
		if ($logged)
			echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'/add" class="linkButton">SELL CHARACTER</a></div>';
		break;
}
?>

How it works?
Player can earn some premium points for characters, when somebody wins auction or uses buy now. Winner can change name of character.​

How to install it?
Save code as file sellchar.php in system/pages​


I've written this code for Tazer, but he didn't want to pay(he already got something like this...)
 
You need active account manager for change name
not be possible or best done via web when you buy that this character can be renamed at the same site?
only that player.
 
Bufo omg. This is for modern acc not geisor. He has take the ides from geisor's so chill out!
 
This script have a nice sql injections u.u
 
Code:
<?php

//[email protected]
/*
  In MySQL:
  CREATE TABLE `characters_auctions` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
  `state` TINYINT( 1 ) NOT NULL DEFAULT '0' ,
  `finish_time` INT NOT NULL ,
  `char_id` INT NOT NULL ,
  `buy_now` INT NOT NULL ,
  `bid` INT NOT NULL ,
  `bidder` INT NOT NULL ,
  INDEX ( `finish_time` ));
 */

$LINK = WEBSITE . '/index.php/p/v/sellchar';

$config = array();
$config['donator_enabled'] = false;
$config['time_to_finish'] = 7 * 24 * 60 * 60;
$config['max_start_bid'] = 100;
$config['max_buy_now'] = 10000;

$ots = POT::getInstance();
$ots->connect(POT::DB_MYSQL, connection());
$SQL = $ots->getDBHandle();
$uri = $this->uri->uri_to_assoc();
$params = array();
$i = 0;
foreach ($uri as $key => $value) {
	if ($i == 0) {
		$params[$i] = $value;
		$i++;
	} else {
		$params[$i] = $key;
		$i++;
		$params[$i] = $value;
		$i++;
	}
}
$action = $params[0];
$logged = $ide->isLogged();
$account_logged = null;
if ($logged) {
	$account_logged = $ots->createObject('Account');
	$account_logged->load($ide->loggedAccountId());
}
$admin = $ide->isAdmin();

function time_left($integer) {
	$weeks = 0;
	$days = 0;
	$hours = 0;
	$minutes = 0;
	$second = 0;
	$return = null;
	if ($integer <= 0)
		return "Finished";
	$seconds = $integer;
	if ($seconds / 60 >= 1) {
		$minutes = floor($seconds / 60);
		if ($minutes / 60 >= 1) { # Hours  
			$hours = floor($minutes / 60);
			if ($hours / 24 >= 1) { #days  
				$days = floor($hours / 24);
				if ($days / 7 >= 1) { #weeks  
					$weeks = floor($days / 7);
					if ($weeks >= 2)
						$return = "$weeks weeks";
					else
						$return = "$weeks week";
				} #end of weeks  
				$days = $days - (floor($days / 7)) * 7;
				if ($weeks >= 1 && $days >= 1)
					$return = "$return, ";
				if ($days >= 2)
					$return = "$return $days d";
				if ($days == 1)
					$return = "$return $days d";
			} #end of days 
			$hours = $hours - (floor($hours / 24)) * 24;
			if ($days >= 1 && $hours >= 1)
				$return = "$return, ";
			if ($hours >= 2 || $hours == 0)
				$return = "$return $hours h";
			if ($hours == 1)
				$return = "$return $hours h";
		} #end of Hours 
		$minutes = $minutes - (floor($minutes / 60)) * 60;
		if ($hours >= 1 && $minutes >= 1)
			$return = "$return, ";
		if ($minutes >= 2 || $minutes == 0)
			$return = "$return $minutes m";
		if ($minutes == 1)
			$return = "$return $minutes m";
	} #end of minutes  
	$seconds = $integer - (floor($integer / 60)) * 60;
	if ($minutes >= 1 && $seconds >= 1)
		$return = "$return, ";
	if ($seconds >= 2 || $seconds == 0)
		$return = "$return $seconds sec";
	if ($seconds == 1)
		$return = "$return $seconds sec";
	$return = "$return.";
	return $return;
}

foreach ($SQL->query('SELECT * FROM `characters_auctions` WHERE `state` = 0 AND `finish_time` <= ' . time())->fetchAll() as $finishedAuction) {
	if ($finishedAuction['bidder'] > 0) {
		$finishedAuctionBidder = new OTS_Account();
		$finishedAuctionBidder->load($finishedAuction['bidder']);
		$finishedAuctionChar = new OTS_Player();
		$finishedAuctionChar->load($finishedAuction['char_id']);
		$finishedAuctionOwner = new OTS_Account();
		$finishedAuctionOwner->load($finishedAuctionChar->getAccount()->getId());
		$finishedAuctionOwner->setPremiumPoints($finishedAuctionOwner->getPremiumPoints() + $finishedAuction['bid']);
		$finishedAuctionOwner->save();
		$finishedAuctionChar->setAccount($finishedAuctionBidder);
		$finishedAuctionChar->setGroup(1);
		$finishedAuctionChar->save();
		$finishedAuctionChar->setCustomField('deleted', 0);
		$SQL->query('UPDATE `characters_auctions` SET `state` = 2 WHERE `id` = ' . $finishedAuction['id']);
		$SQL->query('INSERT INTO `bans` (`id` , `type` , `value` ,`param` ,`active` ,`expires` ,`added` ,`admin_id` ,`comment` ,`reason` ,`action` ,`statement`) VALUES (NULL , 2, ' . $auctionChar->getId() . ', 2, 1, -1, ' . time() . ', 1, \'BUY CHAR\', 0, 1, \'\');');
	}
	else
		$SQL->query('UPDATE `characters_auctions` SET `state` = 1 WHERE `id` = ' . $finishedAuction['id']);
}

echo '<script type="text/javascript">function countdown(a,b){if(a<=0){document.getElementById(b).innerHTML="Finished";return 0}setTimeout(countdown,1e3,a-1,b);days=Math.floor(a/(60*60*24));a%=60*60*24;hours=Math.floor(a/(60*60));a%=60*60;minutes=Math.floor(a/60);a%=60;seconds=a;dps="s";hps="s";mps="s";sps="s";if(days==1)dps="";if(hours==1)hps="";if(minutes==1)mps="";if(seconds==1)sps="";innerHTML=days+" day"+dps+" ";innerHTML+=hours+" hour"+hps+" ";innerHTML+=minutes+" minute"+mps+" and ";innerHTML+=seconds+" second"+sps;document.getElementById(b).innerHTML=innerHTML}function checkBuyNow(a,b,c){if(!checkLogin(a))return false;if(b<c){alert("This character cost "+c+". You have only "+b+".");return false}var d=confirm("This character cost "+c+". Do you want to buy it?");if(d)return true;else return false}function checkBid(a,b,c,d){if(!checkLogin(a))return false;var e=window.document.getElementById("bid").value;if(e<=d){alert("Current highest bid is "+d+". You can not bid "+e+".");return false}if(e>c){alert("You can not bid "+e+". You have only "+c+".");return false}if(a==b){var f=confirm("You have highest bid in this auction. Are you sure you want make higher bid?");if(f)return true;else return false}return true}function checkLogin(a){if(a==0){alert("You are not logged in.");return false}return true}var innerHTM</script>';

switch ($action) {
	case "add":
		if ($logged) {
			echo '<h1><center>Add Auction</center></h1><br/><br/>';
			$players = $account_logged->getPlayers();
			$id_arr = array();
			foreach ($players as $player) {
				$id_arr[] = $player->getId();
			}
			$auctions = $SQL->query('SELECT * FROM `characters_auctions` WHERE `char_id` IN (' . implode(',', $id_arr) . ') AND `state` = 0')->fetchAll();
			$in_auction = array();
			foreach ($auctions as $auction) {
				$in_auction[] = $auction['char_id'];
			}

			if (isset($_POST['submit'])) {
				$errors = array();
				$_POST['char'] = isset($_POST['char']) ? $_POST['char'] : "";
				$_POST['bid'] = isset($_POST['bid']) ? $_POST['bid'] : 0;
				if ($_POST['bid'] < 0)
					$_POST['bid'] = 0;
				if (isset($_POST['buy_now']) && $_POST['buy_now'] < 0)
					$_POST['buy_now'] = 0;
				if (in_array($_POST['char'], $in_auction)) {
					$errors[] = "This character is aleardy in auction.";
				}
				if (!in_array($_POST['char'], $id_arr)) {
					$errors[] = "This character isn't your.";
				}
				if ($_POST['bid'] > $config['max_start_bid']) {
					$errors[] = "Too high starting bid.";
				}
				if ($_POST['buy_now'] > $config['max_buy_now']) {
					$errors[] = "Too high buy now price.";
				}

				if (count($errors) == 0) {
					$priceAuction = (int) $_POST['bid'];
					$priceBuyNow = (int) isset($_POST['buy_now']) ? $_POST['buy_now'] : 0;
					$auctionTime = (int) $config['time_to_finish'];
					$SQL->query('INSERT INTO `characters_auctions` (`id` ,`finish_time` ,`char_id` ,`buy_now` ,`bid` ,`bidder`) VALUES (NULL , ' . (time() + $auctionTime) . ', ' . $SQL->quote($_POST['char']) . ', ' . $priceBuyNow . ', ' . $priceAuction . ', 0);');
					$char = new OTS_Player();
					$char->load($_POST['char']);
					$char->setCustomField('deleted', 1);
					echo 'Your auction has been added successfully!';
				} else {
					echo 'ERRORS:<br/>';
					foreach ($errors as $error)
						echo $error . '<br/>';
				}
			} else {
				echo '<form action="" method="post"><table>';
				echo '<tr><td>Bid:</td><td><input type="text" name="bid" /></td></tr>';
				echo '<tr><td>Buy now:</td><td><input type="text" name="buy_now" /><small>(leave empty if don\'t want to use it)</small></td></tr>';
				echo '<tr><td>Select character:</td><td><select name="char"><option value="" disabled=disabled selected=selected>';
				foreach ($players as $player) {
					$disabled = "";
					if (in_array($player->getId(), $in_auction))
						$disabled = " disabled=disabled";
					echo '<option value="' . $player->getId() . '" ' . $disabled . '>' . $player->getName() . '</option>';
				}
				echo '</select></td></tr></table><br/>';
				echo '<input type="submit" name="submit" value="ADD" />';
			}
			echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'" class="linkButton">BACK</a></div>';
		} else
			echo 'You are not logged in.';
		break;

	case "show":
		$auctionInfo = $SQL->query('SELECT * FROM `characters_auctions` WHERE `id` = ' . $SQL->quote((int) $params[1]))->fetch();
		echo '<h1><center>Auction Info</center></h1>';
		if (isset($auctionInfo['id'])) {
			$auctionChar = new OTS_Player();
			$auctionChar->load($auctionInfo['char_id']);
			if ($auctionChar->isLoaded()) {
				echo '<table style="margin-left: auto;margin-right: auto;">';
				echo '<tr><td colspan="3">CHARACTER INFO</td></tr>';
				echo '<tr><td><table style="width: 360px;border-spacing: 1px">';
				echo '<tr><td>AUCTION ID:</td><td>' . $auctionInfo['id'] . '</td></tr>';
				echo '<tr><td>Name:</td><td>' . $auctionChar->getName() . '<br /><div style="font-size: 8pt;">(You select new name when you win auction.)</div></td></tr>';
				echo '<tr><td>Level:</td><td>' . $auctionChar->getLevel() . '</td></tr>';
				echo '<tr><td>Vocation:</td><td>' . getVocationName($auctionChar->getVocation(), $auctionChar->getPromotion()) . '</td></tr>';
				echo '<tr><td>Health:</td><td>' . $auctionChar->getHealthMax() . '</td></tr>';
				echo '<tr><td>Mana:</td><td>' . $auctionChar->getManaMax() . '</td></tr>';
				echo '<tr><td>Magic level:</td><td>' . $auctionChar->getMagLevel() . '</td></tr>';
				echo '<tr><td>Sword:</td><td>' . $auctionChar->getSkill(2) . '</td></tr>';
				echo '<tr><td>Axe:</td><td>' . $auctionChar->getSkill(3) . '</td></tr>';
				echo '<tr><td>Club:</td><td>' . $auctionChar->getSkill(1) . '</td></tr>';
				echo '<tr><td>Distance:</td><td>' . $auctionChar->getSkill(4) . '</td></tr>';
				echo '<tr><td>Shielding:</td><td>' . $auctionChar->getSkill(5) . '</td></tr>';
				echo '</table><td>';
				$player_items = array();
				for ($i = 1; $i <= 10; $i++) {
					$player_items[$i] = 0;
				}
				foreach ($SQL->query('SELECT * FROM `player_items` WHERE `player_id` = ' . $auctionChar->getId() . ' AND `pid` >= 1 AND `pid` <= 10;') as $item)
					$player_items[$item['pid']] = $item['itemtype'];
				echo '<td><table style="border-spacing: 1px">';
				echo '<tr><td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/2.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[2] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/1.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[1] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/3.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[3] . '.gif" alt="" class="showItemImage"/></td></tr>';
				echo '<tr><td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/6.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[6] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/4.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[4] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/5.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[5] . '.gif" alt="" class="showItemImage"/></td></tr>';
				echo '<tr><td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/9.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[9] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/7.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[7] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/10.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[10] . '.gif" alt="" class="showItemImage"/></td></tr>';
				echo '<tr><td class="showItemSquare" style="text-align: center">Soul:<br />' . $auctionChar->getSoul() . '</td>';
				echo '<td class="showItemSquare" style="background-image: url(' . WEBSITE . '/public/images/items/8.gif)"><img src="' . WEBSITE . '/public/images/items/' . $player_items[8] . '.gif" alt="" class="showItemImage"/></td>';
				echo '<td class="showItemSquare" style="text-align: center">Cap:<br />' . $auctionChar->getCap() . '</td></tr>';
				echo '</tr></table></td>';
				echo '</tr></table>';
				if ($config['donator_enabled']) {
					$donators_items = $SQL->query('SELECT `player_items`.`itemtype`, SUM(`player_items`.`count`) AS count, `z_shop_offer`.`offer_name` AS name FROM `player_items`, `z_shop_offer` WHERE `player_items`.`player_id` = ' . $auctionChar->getId() . ' AND `z_shop_offer`.`offer_type` = \'item\' AND `player_items`.`itemtype` = `z_shop_offer`.`itemid1` GROUP BY `player_items`.`itemtype`;')->fetchAll();
					$donators_depotitems = $SQL->query('SELECT `player_depotitems`.`itemtype`, SUM(`player_depotitems`.`count`) AS count, `z_shop_offer`.`offer_name` AS name FROM `player_depotitems`, `z_shop_offer` WHERE `player_depotitems`.`player_id` = ' . $auctionChar->getId() . ' AND `z_shop_offer`.`offer_type` = \'item\' AND `player_depotitems`.`itemtype` = `z_shop_offer`.`itemid1` GROUP BY `player_depotitems`.`itemtype`;')->fetchAll();
					if (count($donators_items) > 0 || count($donators_depotitems) > 0) {
						echo '<table style="margin-left: auto;margin-right: auto;padding-top: 30px;">';
						if (count($donators_items) > 0) {
							echo '<tr><td colspan="3">DONATORS ITEMS</td></tr>';
							$row = 0;
							foreach ($donators_items as $donator_item)
								echo '<tr><td><img src="' . WEBSITE . '/public/images/items/' . $donator_item['itemtype'] . '.gif" alt="" class="showItemImage"/></td><td>' . $donator_item['count'] . 'x</td><td>' . $donator_item['name'] . '</td></tr>';
						}
						if (count($donators_depotitems) > 0) {
							echo '<tr><td colspan="3">DONATORS IN DEPOT</td></tr>';
							$row = 0;
							foreach ($donators_depotitems as $donator_depotitem)
								echo '<tr><td class="showItemSquare"><img src="' . WEBSITE . '/public/images/items/' . $donator_depotitem['itemtype'] . '.gif" alt="" class="showItemImage"/></td><td>' . $donator_depotitem['count'] . 'x</td><td>' . $donator_depotitem['name'] . '</td></tr>';
						}
						echo '</table>';
					}
				}
				echo '<table style="margin-left: auto;margin-right: auto;padding-top: 30px;">';
				echo '<tr><td colspan="2">AUCTION INFO</td></tr>';
				if ($auctionInfo['buy_now'] > 0)
					echo '<tr><td>Buy now:</td><td>' . $auctionInfo['buy_now'] . ' premium points</td></tr>';
				echo '<tr><td>Highest bid:</td><td>' . $auctionInfo['bid'] . ' premium points</td></tr>';
				echo '<tr><td>Time left:</td><td><div name="timer_' . $auctionInfo['id'] . '" id="timer_' . $auctionInfo['id'] . '">' . time_left($auctionInfo['finish_time'] - time()) . '</div></td></tr>';
				echo '</table><br /><script type="text/javascript">countdown(' . ($auctionInfo['finish_time'] - time()) . ', \'timer_' . $auctionInfo['id'] . '\');</script>';
				if ($auctionInfo['state'] == 0) {
					echo '<form action="'.$LINK.'/bid/' . $auctionInfo['id'] . '" method="post" onsubmit="return checkBid(' . (($logged) ? $account_logged->getId() : 0) . ', ' . $auctionInfo['bidder'] . ', ' . (($logged) ? $account_logged->getPremiumPoints() : 0) . ', ' . $auctionInfo['bid'] . ');">';
					echo '<table style="float: left;">';
					echo '<tr><td colspan="2">YOUR BID</td></tr>';
					echo '<tr><td>Bid:</td><td><input type="text" id="bid" name="bid" value="' . ($auctionInfo['bid'] + 1) . '" /> pp</td></tr>';
					echo '<tr><td colspan="2" style="text-align: center;"><input type="submit" value="BID" /></td></tr></table></form><br />';
					if ($auctionInfo['buy_now'] > 0)
						echo '<a href="'.$LINK.'/buy/' . $auctionInfo['id'] . '" class="linkButton" style="float: right;" onclick="return checkBuyNow(' . (($logged) ? $account_logged->getId() : 0) . ', ' . (($logged) ? $account_logged->getPremiumPoints() : 0) . ', ' . $auctionInfo['buy_now'] . ');">BUY NOW!</a>';
				}
				echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'" class="linkButton">BACK</a></div>';
			}
			else
				echo 'ERROR! Character doesn\'t exist.';
		}
		else
			echo 'ERROR! Auction with this ID doesn\'t exist.';
		break;
	case "bid":
		echo '<h1><center>Bid character</center></h1>';
		if ($logged) {
			$auctionInfo = $SQL->query('SELECT * FROM `characters_auctions` WHERE `state` = 0 AND `id` = ' . $SQL->quote((int) $params[1]))->fetch();
			if (isset($auctionInfo['id'])) {
				$auctionChar = new OTS_Player();
				$auctionChar->load($auctionInfo['char_id']);
				if ($auctionChar->isLoaded()) {
					if ($account_logged->getPremiumPoints() > $auctionInfo['bid'] || ($account_logged->getId() == $auctionInfo['bidder'] && $account_logged->getPremiumPoints() > 0)) {
						if (isset($_POST['bid']) && (int) $_POST['bid'] > 0) {
							$userBid = (int) $_POST['bid'];
							if ($account_logged->getPremiumPoints() >= $userBid || ($account_logged->getId() == $auctionInfo['bidder'] && $account_logged->getPremiumPoints() + $auctionInfo['bid'] >= $userBid)) {
								if ($userBid > $auctionInfo['bid']) {
									if ($account_logged->getId() != $auctionInfo['bidder']) {
										$last_bidder = new OTS_Account();
										$last_bidder->load($auctionInfo['bidder']);
										if ($last_bidder->isLoaded()) {
											$last_bidder->setPremiumPoints($last_bidder->getPremiumPoints() + $auctionInfo['bid']);
											$last_bidder->save();
										}
										$account_logged->setPremiumPoints($account_logged->getPremiumPoints() - $userBid);
									}
									else
										$account_logged->setPremiumPoints($account_logged->getPremiumPoints() + $auctionInfo['bid'] - $userBid);
									$account_logged->save();
									$SQL->query('UPDATE `characters_auctions` SET `bid` = ' . $SQL->quote($userBid) . ', `bidder` = ' . $account_logged->getId() . ' WHERE `id` = ' . $auctionInfo['id']);
									if ($auctionInfo['finish_time'] - time() < 60)
										$SQL->query('UPDATE `characters_auctions` SET `finish_time` = ' . time() + 60 . ' WHERE `id` = ' . $auctionInfo['id']);
									echo '<div>You have bidded ' . $userBid . ' premium points on auction ID ' . $auctionInfo['id'] . '!</div>';
									echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'/show/' . $auctionInfo['id'] . '" class="linkButton">BACK</a></div>';
								}
								else
									echo 'Sorry! Your bid is lower then current highest bid.<br />Your bid is: ' . $userBid . '<br />Highest bid: ' . $auctionInfo['bid'];
							}
							else
								echo 'Sorry! You do not have enought premium points.<br />Your bid is: ' . $userBid . '<br />You have: ' . $account_logged->getPremiumPoints();
						}
						else
							echo 'You must bid more then 0.';
					}
					else
						echo 'Sorry! You do not have enought premium points.<br />Highest bid is: ' . $auctionInfo['bid'] . '<br />You have: ' . $account_logged->getPremiumPoints();
				}
				else
					echo 'ERROR! Character doesn\'t exist.';
			}
			else
				echo 'ERROR! Auction with this ID doesn\'t exist.';
		}
		else
			echo 'You are not logged in.';
		break;
	case "buy":
		echo '<h1><center>Buy character</center></h1>';
		if ($logged) {
			$auctionInfo = $SQL->query('SELECT * FROM `characters_auctions` WHERE `state` = 0 AND `id` = ' . $SQL->quote((int) $params[1]))->fetch();
			if (isset($auctionInfo['id'])) {
				if ($auctionInfo['buy_now'] > 0) {
					$auctionChar = new OTS_Player();
					$auctionChar->load($auctionInfo['char_id']);
					if ($auctionChar->isLoaded()) {
						if ($account_logged->getPremiumPoints() >= $auctionInfo['buy_now'] || ($account_logged->getId() == $auctionInfo['bidder'] && $account_logged->getPremiumPoints() + $auctionInfo['bid'] >= $auctionInfo['buy_now'])) {
							if ($account_logged->getId() != $auctionInfo['bidder']) {
								$last_bidder = new OTS_Account();
								$last_bidder->load($auctionInfo['bidder']);
								if ($last_bidder->isLoaded()) {
									$last_bidder->setPremiumPoints($last_bidder->getPremiumPoints() + $auctionInfo['bid']);
									$last_bidder->save();
								}
								$account_logged->setPremiumPoints($account_logged->getPremiumPoints() - $auctionInfo['buy_now']);
							}
							else
								$account_logged->setPremiumPoints($account_logged->getPremiumPoints() + $auctionInfo['bid'] - $auctionInfo['buy_now']);
							$account_logged->save();
							$finishedAuctionOwner = new OTS_Account();
							$finishedAuctionOwner->load($auctionChar->getAccount()->getId());
							$finishedAuctionOwner->setPremiumPoints($finishedAuctionOwner->getPremiumPoints() + $auctionInfo['buy_know']);
							$finishedAuctionOwner->save();
							$auctionChar->setAccount($account_logged);
							$auctionChar->setGroup(1);
							$auctionChar->save();
							$auctionChar->setCustomField('deleted', 0);
							$SQL->query('INSERT INTO `bans` (`id` , `type` , `value` ,`param` ,`active` ,`expires` ,`added` ,`admin_id` ,`comment` ,`reason` ,`action` ,`statement`) VALUES (NULL , 2, ' . $auctionChar->getId() . ', 2, 1, -1, ' . time() . ', 1, \'BUY CHAR\', 0, 1, \'\');');
							$SQL->query('UPDATE `characters_auctions` SET `state` = 2, `finish_time` = ' . time() . ', `bidder` = ' . $account_logged->getId() . ', `bid` = `buy_now` WHERE `id` = ' . $auctionInfo['id']);
							echo '<div>You have bought new character! Character is now on your account. Login in game and select new name for your character.</div>';
							echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'" class="linkButton">BACK</a></div>';
						}
						else
							echo 'Sorry! You do not have enought premium points.<br />It cost: ' . $auctionInfo['buy_now'] . '<br />You have: ' . $account_logged->getPremiumPoints() . '' . $errorFormEnd;
					}
					else
						echo 'ERROR! Character doesn\'t exist.';
				}
				else
					echo 'ERROR! You can not buy this character by Buy Now option. You can only Bid on auction.';
			}
			else
				echo 'ERROR! Auction with this ID doesn\'t exist.';
		}
		else
			echo 'You are not logged in.';
		break;

	default:
		echo '<h1><center>Characters Auctions</center></h1>';
		echo '<br/>With this system you can buy un-used (inactive) characters by auctioning for them. When you bid on a character it will automatically take premium points from your account. If someone out-bids you, you will get those premium points added back to your account. If the auction time is under 2 minutes when someone bids, 1 minute will automatically be added to the auction time to give time for a re-bid from the previous bidder. If you choose to "buy now" you will get the character within 1 minute.<br/><br/>';
		echo '<table width="100%"><tr style="font-size: 14px;text-align: center"><td>Time left</td><td>Char info</td><td>Buy now</td><td>Highest bid</td></tr>';
		$timers = array();
		foreach ($SQL->query('SELECT * FROM `characters_auctions` WHERE `finish_time` > ' . time())->fetchAll() as $auctionInfo) {
			$auctionChar = new OTS_Player();
			$auctionChar->load($auctionInfo['char_id']);
			if ($auctionChar->isLoaded())
				echo '<tr style="font-size: 12px;text-align: center" onclick="window.location = \''.$LINK.'/show/' . $auctionInfo['id'] . '\'"><td><div id="timer_' . $auctionInfo['id'] . '">' . time_left($auctionInfo['finish_time'] - time()) . '</div></td><td>' . $auctionChar->getLevel() . ' ' . getVocationName($auctionChar->getVocation(), $auctionChar->getPromotion()) . '</td><td>' . $auctionInfo['buy_now'] . ' pp</td><td>' . $auctionInfo['bid'] . ' pp</td></tr>';
			$timers['timer_' . $auctionInfo['id']] = $auctionInfo['finish_time'] - time();
		}
		echo '</table><br />Press on auction to get more informations.';
		echo '<script type="text/javascript">';
		if (count($timers) > 0) {
			foreach ($timers as $timer_id => $time_left)
				echo 'countdown(' . $time_left . ', \'' . $timer_id . '\');';
		}
		echo '</script>';
		if ($logged)
			echo '<div style="padding-top: 120px;padding-left: 45%"><a href="'.$LINK.'/add" class="linkButton">SELL CHARACTER</a></div>';
		break;
}
?>

How it works?
Player can earn some premium points for characters, when somebody wins auction or uses buy now. Winner can change name of character.​

How to install it?
Save code as file sellchar.php in system/pages​


I've written this code for Tazer, but he didn't want to pay(he already got something like this...)

Great release, is it safe?
 
Anyone know of a way to convert this to use name change on the website?
I know its possible bc it works in my shop I just cant seem to figure it out tho. :-/

I'd be willing to throw some compensation and rep if someone could do this.

Pm me if so.
Thanks!
 
you can use namelock system via website, I think, ofc if you've got it : )
 
Any way you would know how to do this? I could provide you with the script my shop uses for this. As I said previously I am willing to send money to anyone could manage to do this for me.

Thanks for your reply Averatec!
 
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'otz.characters_auctions' doesn't exist' in C:\xampp\htdocs\system\pages\sellchar.php:109 Stack trace: #0 C:\xampp\htdocs\system\pages\sellchar.php(109): PDO->query('SELECT * FROM `...') #1 C:\xampp\htdocs\system\application\controllers\p.php(13): include('C:\xampp\htdocs...') #2 [internal function]: p->v('sellchar') #3 C:\xampp\htdocs\system\codeigniter\CodeIgniter.php(236): call_user_func_array(Array, Array) #4 C:\xampp\htdocs\index.php(165): require_once('C:\xampp\htdocs...') #5 {main} thrown in C:\xampp\htdocs\system\pages\sellchar.php on line 109
 
A PHP Error was encountered

Severity: Notice

Message: Undefined index: buy_know

Filename: pages/sellchar.php

Line Number: 365

--
line 365
Code:
$finishedAuctionOwner->setPremiumPoints($finishedAuctionOwner->getPremiumPoints() + $auctionInfo['buy_know']);
;/
 
Back
Top