Example #1
0
<?
if($_POST['buy2']){

	$cost_steel = secureData($_POST['cost_steel']);
	$cost_crystal = secureData($_POST['cost_crystal']);
	$cost_erbium = secureData($_POST['cost_erbium']);
	$cost_titanium = secureData($_POST['cost_titanium']);
	$order_id = secureData($_POST['order_id']);
	$seller_id = secureData($_POST['seller_id']);

	if (checkSteelResource($playerdata['id'], $cost_steel) && checkCrystalResource($playerdata['id'], $cost_crystal) && checkErbiumResource($playerdata['id'], $cost_erbium) && checkTitaniumResource($playerdata['id'], $cost_titanium)) {

		$sql_updres = "UPDATE $table[players] SET `res_steel` = `res_steel` - '$cost_steel', `res_crystal` = `res_crystal` - '$cost_crystal', `res_erbium` = `res_erbium` - '$cost_erbium', `res_titanium` = `res_titanium` - '$cost_titanium' WHERE `id` = '$playerdata[id]'";
		mysql_query($sql_updres) or die(mysql_error());

		$sql_updres2 = "UPDATE $table[players] SET `res_steel` = `res_steel` + '$cost_steel', `res_crystal` = `res_crystal` + '$cost_crystal', `res_erbium` = `res_erbium` + '$cost_erbium', `res_titanium` = `res_titanium` + '$cost_titanium' WHERE `id` = '$seller_id'";
		mysql_query($sql_updres2) or die(mysql_error());

		$sql_getorderships = "SELECT `order_id`, `ship_id`, `amount` FROM $table[market_ships] WHERE `order_id` = '$order_id'";
		$rec_getorderships = mysql_query($sql_getorderships);

		while ($res_getordership = mysql_fetch_array($rec_getorderships)) {
			$baseships = getBaseShips($playerdata['id'], $res_getordership['ship_id']);
			if ($baseships == 0){
				$sql_insertship = "INSERT INTO `$table[playerunit]` (`player_id`, `type_id`, `unit_id`, `amount`) VALUES ('$playerdata[id]', '3', '$res_getordership[ship_id]', '$res_getordership[amount]')";
				mysql_query($sql_insertship) or die(mysql_error());
			}else{
				$sql_updships = "UPDATE $table[playerunit] SET `amount` = `amount` + '$res_getordership[amount]' WHERE `player_id` = '$playerdata[id]' AND `unit_id` = '$res_getordership[ship_id]'";
				mysql_query($sql_updships) or die(mysql_error());
			}
			$sql_delships = "DELETE FROM $table[market_ships] WHERE `order_id` = '$order_id' AND `ship_id` = '$res_getordership[ship_id]'";
function tryShipDefenseProductionAdd($player_id, $type_id, $item_table, $item_id, $amount) {
	global $table;
	$sql_getitemdata = "SELECT * FROM $item_table WHERE `id` = '$item_id'";
	$res_getitemdata = mysql_fetch_array(mysql_query($sql_getitemdata));
	if (!checkItem($player_id, $res_getitemdata['depends'])) { return 1; } /* 1; Depencies are incorrect */
	$cost_steel = $amount * $res_getitemdata['cost_steel'];
	$cost_crystal = $amount * $res_getitemdata['cost_crystal'];
	$cost_erbium = $amount * $res_getitemdata['cost_erbium'];
	$cost_titanium = $amount * $res_getitemdata['cost_titanium'];
	if (checkSteelResource($player_id, $cost_steel) && checkCrystalResource($player_id, $cost_crystal) && checkErbiumResource($player_id, $cost_erbium) && checkTitaniumResource($player_id, $cost_titanium)) {
		$currenttick = getCurrentTick();
		$ready_tick = $currenttick + $res_getitemdata['eta'];
		$sql_addprod = "INSERT INTO `$table[productions]` (`id`, `player_id`, `type_id`, `item_id`, `ready_tick`, `amount`)
					VALUES ('', '$player_id', '$type_id', '$item_id', '$ready_tick', '$amount')";
		mysql_query($sql_addprod);
		decreaseCurrentResources($player_id, $cost_steel, $cost_crystal, $cost_erbium, $cost_titanium);
	} else {
		return 2; /* Not enough resources to build */
	}
	return 0; /* Succesfull executed! */
}