function umc_money_give() { global $UMC_USER; XMPP_ERROR_trace(__FUNCTION__, func_get_args()); $player = $UMC_USER['username']; $args = $UMC_USER['args']; if (!isset($args[2])) { umc_error('You need to enter the user to give money to!'); } else { if (strtolower($args[2]) == strtolower($player)) { umc_error('You cannot give money to yourself!'); } } if (!isset($args[3])) { umc_error('You need to enter amount of money!'); } else { if ($args[3] <= 0) { umc_error('You will need to give more than that!'); } } $target = umc_sanitize_input($args[2], 'player'); $sum = umc_sanitize_input($args[3], 'price'); $check = umc_money($player, $target, $sum); if ($check) { umc_error('The transaction failed! Make sure that the target user exists'); } else { umc_echo("You successfully transferred {$sum} Uncs to {$target}"); } // get UUID or target player $target_uuid = umc_user2uuid($target); // check if the user is online if (isset($UMC_USER['player_data'][$target_uuid])) { umc_msg_user($target, "You just received {$sum} Uncs from {$player}!"); umc_echo("The recipient is online, the server sent a notification message."); } else { // otherwise, send an email $title = "You received {$sum} Uncs from {$player}!"; $message = "Dear {$target},\nyou just received {$sum} Uncs from {$player}.\n" . "The amount in in your account now.\n" . "Use /money check to see your account balance.\n"; umc_mail_quick_send($title, $message, $target_uuid, false); umc_echo("The recipient is currently offline, the server sent a notification email."); } umc_log('money', 'give', "{$player} gave {$target} {$sum} Uncs"); umc_money_status(); }
/** * Buy XP in-game // function is still working with usernames instead of UUID since * the /xp command does not work with UUIDs (yet) * * * @global type $UMC_USER */ function umc_do_buyxp() { global $UMC_USER; $player = $UMC_USER['username']; $args = $UMC_USER['args']; $xp_ratio = 1; // check to see if player has entered a value of xp to buy if (isset($args[2])) { // feedback on current xp point values $user_xp = $UMC_USER['xp']; umc_echo("{white} You started with {$user_xp} experience points."); // amount player is trying to spend $amount = $args[2]; // cast argument to type int to sanitise the data settype($amount, 'int'); // amount of xp calculated $xp = floor($amount * $xp_ratio); // retrieve the players balance to check if they can afford $balance = umc_money_check($player); if ($xp < 1 || $amount < 1) { umc_error("{red}You need to buy at least 1 XP. For {$amount} Uncs you get only {$xp} XP (ratio is {$xp_ratio}!)"); } if ($amount > $balance) { umc_error("{red}Sorry, you cannot afford this purchase. You currently have {$balance} uncs."); } // calculate the total new xp point value $new_xp = $user_xp + $xp; // apply purchase // send the console command to give the player experience umc_ws_cmd("exp set {$player} {$new_xp}", 'asConsole'); // take the purchase amount from players account. // take from, give to, positive value umc_money($player, false, $amount); // announce the purchase to encourage players to consider buying xp umc_announce("{gold}{$player}{gray} just bought {purple}{$xp} XP{gray} for{cyan} {$amount} Uncs{gray}!"); umc_echo("{white} You ended with {$new_xp} experience points."); // log the purchase umc_log('buyxp', 'buy', "{$player} paid {$amount} for {$xp} XP, going from {$user_xp} to {$new_xp}"); } else { umc_error("{red}You need to specify the amount of Uncs you want to spend. See {yellow}/helpme buyxp"); } }
/** * Adds or removes a player to a region. Works for Owners (default) as well as members. * must ensure beforehand that the user and the lot and the world esists * * @param type $player * @param type $lot * @param type $owner * @param type $cost * @return boolean */ function umc_lot_add_player($player, $lot, $owner = 1, $cost = false) { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); $world = umc_get_lot_world($lot); $world_id = umc_get_worldguard_id('world', $world); if (!$world) { XMPP_ERROR_trigger("World could not be found for lot {$lot} ({$player}) (umc_lot_add_player)"); die('umc_lot_add_player'); } $user_id = umc_get_worldguard_id('user', $player, true); // check first if the same user is already member/owner $sql = "SELECT * FROM minecraft_worldguard.region_players WHERE region_id='{$lot}' AND world_id='{$world_id}' AND user_id={$user_id};"; $C = umc_mysql_fetch_all($sql); if (count($C) > 0) { XMPP_ERROR_trigger("attempt to add user {$player} to lot {$lot} failed; user is already member/owner (umc_lot_add_player)"); return false; } $sql = "INSERT INTO minecraft_worldguard.region_players (region_id, world_id, user_id, Owner) " . "VALUES ('{$lot}', {$world_id}, {$user_id}, {$owner})"; umc_mysql_query($sql, true); XMPP_ERROR_send_msg("{$player} was added to lot {$lot}; Owner: {$owner}"); umc_log('lot_manager', 'add_player_to_lot', "{$player} was added to lot {$lot}; Owner: {$owner}"); if ($owner == 1) { //umc_exec_command("ch qm u Congratz for user $player to get lot $lot!"); } // reload regions file umc_exec_command("regions load -w {$world}", 'asConsole'); if ($cost) { umc_money($player, false, $cost); } return true; }
function umc_hunger_trophy() { global $UMC_USER, $HUNGER; XMPP_ERROR_trace(__FUNCTION__, func_get_args()); $args = $UMC_USER['args']; $player = $UMC_USER['username']; $uuid = $UMC_USER['uuid']; $game_id = isset($args[2]) ? $args[2] + 0 : null; if (!$game_id) { umc_error("[Hunger] {red}You must specify a [game-id] for which you were the winner."); } $victim = strtolower(umc_sanitize_input($args[3], 'player')); $victim_uuid = umc_user2uuid($victim); $sql_games = "SELECT *, timediff(NOW(),end) as age FROM minecraft_iconomy.hunger_games WHERE id = {$game_id}"; $rst_games = umc_mysql_query($sql_games); if (mysql_num_rows($rst_games) > 0) { $game = umc_mysql_fetch_array($rst_games); } if (!$game) { umc_error("[Hunger] {red}No such game with game-id {yellow}{$game_id}"); } if ($game['winner'] != $uuid) { umc_error("[Hunger] {red}You were not the winner of game-id {yellow}{$game_id}{red}."); } if ($game['trophy_claimed'] == 'y') { umc_error("[Hunger] {red}You already claimed a trophy for game-id {yellow}{$game_id}{red}."); } if ($game['age'] > '24:00:00') { // umc_error("{red}That game ended more than 24 hours ago, the corpses are too rotten."); } if ($victim_uuid == $uuid) { umc_error("[Hunger] {red}You can't claim your own head. Weirdo."); } umc_echo("finding players of game {$game_id}..."); $HUNGER = umc_hunger_find_players($game_id); $players = $HUNGER['old_game'][$game_id]['players']; if (!in_array($victim, $players)) { umc_error("[Hunger] {red}{gold}{$victim}{red} was not vanquished in that game."); } umc_echo("checking your account balance...."); $balance = umc_money_check($player); if ($balance < $HUNGER['trophy_cost']) { umc_error("[Hunger] {red}You can't afford a trophy, they cost {green}{$HUNGER['trophy_cost']} Uncs"); } umc_echo("Account is fine..."); $item_slot = $UMC_USER['current_item']; if ($item_slot != 0 || isset($UMC_USER['inv'][$item_slot])) { umc_error("[Hunger] {red}You have to pick first hotbar slot, and it has to be empty."); } umc_echo("[Hunger] all good, taking trophy..."); #-- All good, do the work! $sql = "UPDATE minecraft_iconomy.hunger_games SET trophy_claimed = 'y' WHERE id = {$game_id}"; umc_mysql_query($sql, true); umc_echo("[Hunger] charging {$HUNGER['trophy_cost']}..."); umc_money($player, false, $HUNGER['trophy_cost']); umc_echo("[Hunger] {yellow}[\$]{gray} You have been charged {yellow}{$HUNGER['trophy_cost']}{gray} uncs."); umc_echo("[Hunger] getting head..."); // umc_ws_cmd("give $player 397:3 1","asConsole"); umc_ws_cmd("ph spawn {$victim} {$player}", "asConsole"); umc_echo("[Hunger] {purple}Enjoy this small memento of your victory!"); umc_log('hunger', 'trophy', "{$player} got the head of {$victim}"); }
function umc_vanity_set() { global $UMC_USER; $player = $UMC_USER['username']; $args = $UMC_USER['args']; $userlevel = umc_get_userlevel($player); // umc_echo("$userlevel"); if (!isset($args[2]) || !is_numeric($args[2]) || $args[2] < 1) { umc_error("{red}You need to specify a number of days"); } else { if (!isset($args[3])) { umc_error("{red}You need to specify the title you want to have. See {yellow}/helpme vanity"); } } $days = $args[2]; $vanity_raw = ''; // concatenate all into a string for ($i = 3; $i < count($args); $i++) { $vanity_raw .= " " . $args[$i]; } $vanity = trim($vanity_raw); $donator_str = ''; if (strstr($userlevel, 'DonatorPlus')) { $donator_str = '&6++&f'; } else { if (strstr($userlevel, 'Donator')) { $donator_str = '&6+&f'; } else { if ($userlevel == 'Owner') { $donator_str = '&6++&f'; } } } $final_title = ' [' . $vanity . '&f]'; // check for invalid chars umc_vanity_sanitize($vanity); $quote_array = umc_vanity_quote_title($vanity); $total_cost = $quote_array['cost'] * $days; $balance = umc_money_check($player); if ($quote_array['length'] > 20) { umc_error("Your title is too long ({$quote_array['length']} vs. 20 max!"); } if ($total_cost > $balance) { umc_error("You do not have enough money to pay for this title for {$days} days. You need {$total_cost} but have only {$balance}!"); } // check if there is a title already set $check = umc_vanity_get_title(); if ($final_title == $check . $donator_str) { umc_header("Vanity Title"); umc_echo("The same title is already set and will be extended by {$days} days!"); } else { if ($check && $final_title != $check . $donator_str) { umc_error("You have a different title already set. You need to cancel that one first or set the same one to extend it!"); } else { // no title set yet $uuid = umc_user2uuid($player); umc_header("Vanity Title"); umc_echo("No title yet set, setting new one..."); umc_exec_command("pex user {$uuid} suffix \"{$final_title}{$donator_str}\"", 'asConsole'); } } // set timer umc_money($player, false, $total_cost); umc_timer_set($player, 'custom_title', $days); $date_out = umc_timer_get($player, 'custom_title'); $time_out = $date_out->format('Y-m-d H:i:s'); $date_today = umc_datetime(); $interval = $date_today->diff($date_out); $days_interval = $interval->days; $hours_interval = $interval->h; umc_echo("Your title [{$vanity}{white}] will expire on {$time_out} (in {$days_interval} days and {$hours_interval} hours)!"); umc_echo("Your account has been debited {$total_cost}!"); umc_log('vanity', 'set', "{$player} paid {$total_cost} for {$vanity} for {$days} days"); umc_footer(true); }
function umc_lottery() { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); global $UMC_USER, $lottery, $ENCH_ITEMS; $user_input = $UMC_USER['args'][2]; // check if there is a valid user on the server before applying the vote. $user = umc_check_user($user_input); if (!$user) { umc_log("lottery", "voting", "user {$user} does not exist"); return false; } // get the voting players uuid $uuid = umc_user2uuid($user); // give reinforcing feedback - set subtitle (not displayed) $subtitle = 'title ' . $user . ' subtitle {text:"Thanks for your vote!",color:gold}'; umc_ws_cmd($subtitle, 'asConsole'); // display the feedback - displays subtitle AND title $title = 'title ' . $user . ' title {text:"+100 Uncs",color:gold}'; umc_ws_cmd($title, 'asConsole'); // allow uncovery to test chance rolls for debugging purposes $chance = false; if ($user == 'uncovery' && isset($UMC_USER['args'][5])) { $chance = $UMC_USER['args'][5]; } // get the roll array based on chance $roll = umc_lottery_roll_dice($chance); // umc_echo(umc_ws_vardump($roll)); // define the rewards and item more legibly $item = $roll['item']; $luck = $roll['luck']; $prize = $lottery[$item]; //echo "type = {$prize['type']}<br>;"; //echo "complete chance: $chance<br>;"; //var_dump($prize); // get the metadata if required for the item if (isset($prize['detail'])) { $detail = $prize['detail']; } $type = $prize['type']; // always give 100 uncs irrespective of roll. umc_money(false, $user, 100); // instantiate block variables $given_block_data = 0; $given_block_type = 0; //var_dump($prize); // based on item type, give reward to the player switch ($type) { case 'item': umc_deposit_give_item($uuid, $detail['type'], $detail['data'], $detail['ench'], 1, 'lottery'); $item_txt = $prize['txt']; break; case 'additional_home': $newname = 'lottery' . "_" . umc_random_code_gen(4); umc_home_add($uuid, $newname, true); $item_txt = "an addtional home!!"; break; case 'random_unc': $luck2 = mt_rand(1, 500); umc_money(false, $user, $luck2); $item_txt = "{$luck2} Uncs"; break; case 'random_potion': $luck2 = mt_rand(0, 63); umc_deposit_give_item($uuid, 373, $luck2, '', 1, 'lottery'); $item_txt = $prize['txt']; break; case 'random_ench': // pick which enchantment $rand_ench = array_rand($ENCH_ITEMS); $ench_arr = $ENCH_ITEMS[$rand_ench]; //pick which item to enchant $rand_item = array_rand($ench_arr['items']); $rand_item_id = $ench_arr['items'][$rand_item]; // pick level of enchantment $lvl_luck = mt_rand(1, $ench_arr['max']); //echo "$item $ench_txt $lvl_luck"; $item_ench_arr = array($rand_ench => $lvl_luck); $item = umc_goods_get_text($rand_item_id, 0, $item_ench_arr); $item_name = $item['item_name']; $full = $item['full']; umc_deposit_give_item($uuid, $item_name, 0, $item_ench_arr, 1, 'lottery'); $item_txt = "a " . $full; break; case 'random_pet': // same as blocks below but only 1 always umc_echo($type); $block = $prize['blocks']; $luck2 = mt_rand(0, count($prize['blocks']) - 1); $given_block = explode(":", $block[$luck2]); $given_block_type = $given_block[0]; $given_block_data = $given_block[1]; umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', 1, 'lottery'); $item = umc_goods_get_text($given_block_type, $given_block_data); $item_txt = "a " . $item['full']; break; case 'random_common': case 'random_ore': case 'random_manuf': $block = $prize['blocks']; $luck2 = mt_rand(0, count($prize['blocks']) - 1); $luck3 = mt_rand(1, 64); $given_block = explode(":", $block[$luck2]); $given_block_type = $given_block[0]; $given_block_data = $given_block[1]; umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', $luck3, 'lottery'); $item = umc_goods_get_text($given_block_type, $given_block_data); $item_txt = "{$luck3} " . $item['full']; break; } if ($user != 'uncovery') { // testing only $item_nocolor = umc_ws_color_remove($item_txt); umc_ws_cmd("ch qm N {$user} voted, rolled a {$luck} and got {$item_nocolor}!", 'asConsole'); umc_log('votelottery', 'vote', "{$user} rolled {$luck} and got {$item_nocolor} ({$given_block_type}:{$given_block_data})"); $userlevel = umc_get_userlevel($user); if (in_array($userlevel, array('Settler', 'Guest'))) { $msg = "You received {$item_txt} from the lottery! Use {green}/withdraw @lottery{white} to get it!"; umc_msg_user($user, $msg); } } else { umc_echo("{$user} voted, rolled a {$luck} and got {$item_txt}!"); } // add vote to the database $service_raw = strtolower($UMC_USER['args'][3]); // fix service $search = array('http://www.', 'https://www.', 'http://', 'https://'); $service = umc_mysql_real_escape_string(str_replace($search, '', $service_raw)); // sql log $sql_reward = umc_mysql_real_escape_string($type); $ip = umc_mysql_real_escape_string($UMC_USER['args'][4]); $sql = "INSERT INTO minecraft_log.votes_log (`username`, `datetime`, `website`, `ip_address`, `roll_value`, `reward`)\r\n VALUES ('{$uuid}', NOW(), {$service}, {$ip}, {$luck}, {$sql_reward});"; umc_mysql_query($sql, true); }
function umc_home_sell() { XMPP_ERROR_trace(__FUNCTION__, func_get_args()); global $UMC_USER; $args = $UMC_USER['args']; $count = umc_home_count(); $cost = umc_home_calc_costs($count) / 2; if (!isset($args[2])) { umc_error("{red}You need to specify which home you wish to sell"); } else { $name = umc_mysql_real_escape_string(trim($args[2])); $name_check = umc_home_count($name); if ($name_check == 0) { umc_error("{red}You do not have a home with that name!"); } } umc_money(false, $UMC_USER['uuid'], $cost); $bank = umc_money_check($UMC_USER['uuid']); $newcount = $count - 1; $sql = "DELETE FROM minecraft_srvr.`homes` WHERE uuid='{$UMC_USER['uuid']}' AND name={$name};"; umc_mysql_query($sql, true); umc_header("Selling a home"); umc_echo("You currently have {$count} homes, selling one."); umc_echo("This home sell earns you {$cost} Uncs! You now have {$bank} Uncs in your account."); umc_echo("Your home slot has been sold successfully sold, you now have {$newcount} homes."); umc_footer(); umc_log('home', 'sell', "{$UMC_USER['uuid']}/{$UMC_USER['username']} sold the home called {$args[2]}!"); }
function umc_trivia_close_quiz($quiz_arr = false) { global $UMC_USER; $player = $UMC_USER['username']; if (!$quiz_arr) { $quiz_arr = umc_trivia_get_current_quiz(); } $quiz_id = $quiz_arr['id']; // get best user and points $sql = "SELECT username, count(result) as points FROM minecraft_quiz.quiz_answers WHERE quiz_id={$quiz_id} AND result='right' GROUP BY username ORDER BY count(result) DESC;"; $D = umc_mysql_fetch_all($sql); $data = array(); $prev_points = 0; foreach ($D as $row) { $username = $row['username']; $points = $row['points']; if ($points < $prev_points) { break; } $data[] = $username; // array of the winner(s) $prev_points = $points; } $winner_count = count($data); if ($winner_count > 0) { $winner_str = implode(", ", $data); // how many answers have been given? $answer_sql = "SELECT count(answer_id) as counter FROM minecraft_quiz.quiz_answers WHERE quiz_id={$quiz_id};"; $A = umc_mysql_fetch_all($answer_sql); $answer_row = $A[0]; $answer_count = $answer_row['counter']; $prize = $answer_count * $quiz_arr['price'] / $winner_count; umc_ws_cmd("ch qm o &3[Trivia]&f We have {$winner_count} winner(s) who each get {$prize}!"); umc_ws_cmd("ch qm o &3[Trivia]&f Winner(s): {$winner_str}"); umc_money(false, $row['username'], $prize); $sql = "UPDATE minecraft_quiz.quizzes SET end=NOW(), winner='{$winner_str}', points={$prev_points} WHERE quiz_id={$quiz_id};"; } else { $sql = "UPDATE minecraft_quiz.quizzes SET end=NOW(), winner='', points=0 WHERE quiz_id={$quiz_id};"; } umc_mysql_query($sql, true); umc_ws_cmd("ch qm o &3[Trivia]&f Thanks for participating. Create your own quiz with /trivia new!"); umc_log('trivia', 'close', "{$player} closed trivia {$quiz_id} and gave {$prize} to {$winner_str} each"); }
function umc_lottery() { // umc_error_notify("User $user, $chance (umc_lottery)"); global $UMC_USER, $lottery, $ENCH_ITEMS; $user_input = $UMC_USER['args'][2]; $user = umc_check_user($user_input); if (!$user) { umc_log("lottery", "voting", "user {$user} does not exist"); return false; } $uuid = umc_user2uuid($user); $chance = false; if ($user == 'uncovery' && isset($UMC_USER['args'][3])) { $chance = $UMC_USER['args'][3]; } $roll = umc_lottery_roll_dice($chance); // umc_echo(umc_ws_vardump($roll)); $item = $roll['item']; $luck = $roll['luck']; $prize = $lottery[$item]; //echo "type = {$prize['type']}<br>;"; //echo "complete chance: $chance<br>;"; //var_dump($prize); if (isset($prize['detail'])) { $detail = $prize['detail']; } $type = $prize['type']; // always give 100 uncs umc_money(false, $user, 100); $given_block_data = 0; $given_block_type = 0; //var_dump($prize); switch ($type) { case 'item': umc_deposit_give_item($uuid, $detail['type'], $detail['data'], $detail['ench'], 1, 'lottery'); $item_txt = $prize['txt']; break; case 'random_unc': $luck2 = mt_rand(1, 500); umc_money(false, $user, $luck2); $item_txt = "{$luck2} Uncs"; break; case 'random_potion': $luck2 = mt_rand(0, 63); umc_deposit_give_item($uuid, 373, $luck2, '', 1, 'lottery'); $item_txt = $prize['txt']; break; case 'random_ench': // pick which enchantment $rand_ench = array_rand($ENCH_ITEMS); $ench_arr = $ENCH_ITEMS[$rand_ench]; //pick which item to enchant $rand_item = array_rand($ench_arr['items']); $rand_item_id = $ench_arr['items'][$rand_item]; // pick level of enchantment $lvl_luck = mt_rand(1, $ench_arr['max']); //echo "$item $ench_txt $lvl_luck"; $item_ench_arr = array($rand_ench => $lvl_luck); $item = umc_goods_get_text($rand_item_id, 0, $item_ench_arr); $item_name = $item['item_name']; $full = $item['full']; umc_deposit_give_item($uuid, $item_name, 0, $item_ench_arr, 1, 'lottery'); $item_txt = "a " . $full; break; case 'random_pet': // same as blocks below but only 1 always umc_echo($type); $block = $prize['blocks']; $luck2 = mt_rand(0, count($prize['blocks']) - 1); $given_block = explode(":", $block[$luck2]); $given_block_type = $given_block[0]; $given_block_data = $given_block[1]; umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', 1, 'lottery'); $item = umc_goods_get_text($given_block_type, $given_block_data); $item_txt = "a " . $item['full']; break; case 'random_common': case 'random_ore': case 'random_manuf': $block = $prize['blocks']; $luck2 = mt_rand(0, count($prize['blocks']) - 1); $luck3 = mt_rand(1, 64); $given_block = explode(":", $block[$luck2]); $given_block_type = $given_block[0]; $given_block_data = $given_block[1]; umc_deposit_give_item($uuid, $given_block_type, $given_block_data, '', $luck3, 'lottery'); $item = umc_goods_get_text($given_block_type, $given_block_data); $item_txt = "{$luck3} " . $item['full']; break; } if ($user != 'uncovery') { // testing only $item_nocolor = umc_ws_color_remove($item_txt); umc_ws_cmd("ch qm N {$user} voted, rolled a {$luck} and got {$item_nocolor}!", 'asConsole'); umc_log('votelottery', 'vote', "{$user} rolled {$luck} and got {$item_nocolor} ({$given_block_type}:{$given_block_data})"); $userlevel = umc_get_userlevel($user); if (in_array($userlevel, array('Settler', 'Guest'))) { $msg = "You received {$item_txt} from the lottery! Use {green}/withdraw @lottery{white} to get it!"; umc_msg_user($user, $msg); } } else { umc_echo("{$user} voted, rolled a {$luck} and got {$item_txt}!"); } // add vote to the database $service = umc_mysql_real_escape_string($UMC_USER['args'][3]); $ip = umc_mysql_real_escape_string($UMC_USER['args'][4]); $sql = "INSERT INTO minecraft_log.votes_log (`username`, `datetime`, `website`, `ip_address`)\r\n VALUES ('{$uuid}', NOW(), {$service}, {$ip});"; umc_mysql_query($sql, true); // echo "$user voted for the server and got $item_txt!;"; }
/** * Create a request * * @global type $UMC_USER * @return type */ function umc_do_request() { global $UMC_USER; $player = $UMC_USER['username']; $uuid = $UMC_USER['uuid']; $args = $UMC_USER['args']; // this returns a item_array already $item_check = umc_sanitize_input($args[2], 'item'); if (!$item_check) { umc_error("{red}Unknown item ({yellow}{$args['2']}{red}). Try using {yellow}/search{red} to find names."); } else { XMPP_ERROR_trace("item_check", $item_check); $item = umc_goods_get_text($item_check['item_name'], $item_check['type']); } $item_name = $item['item_name']; $type = $item['type']; $meta = ''; $meta_txt = ''; $do_check = false; $pos = array_search('check', $args); if ($pos) { $do_check = true; array_splice($args, $pos, 1); } // TODO: This should be checking for the item type instead of assuming 0 //if ($UMC_ITEMS[$type][0]['avail'] == false) { // umc_error("{red}Sorry, this item (ID $type) is unavailable in the game!",true); //} $sql = "SELECT * FROM minecraft_iconomy.request\r\n WHERE item_name='{$item_name}' AND damage='{$type}' AND meta='{$meta}' AND uuid='{$uuid}';"; $sql_data = umc_mysql_fetch_all($sql); if (count($sql_data) == 0) { $row = false; } else { $row = $sql_data[0]; } // buy item at same price, check if exists if (!isset($args[3])) { if ($row) { $price = $row['price']; } else { umc_error("{red}Since you do not have the same item already in the shop you need to specify a price.;"); } } else { $price = umc_sanitize_input($args[3], 'price'); } // check if an argument was given for amount. $amount = umc_sanitize_input($args[4], 'amount'); if ($amount == NULL) { // buying 0 amount available is not possible umc_error("{red}You need to specify an amount, too!;"); } $cost = $price * $amount; // if there is an existing row, recalculate price accordingly if ($row) { // give money back from the original request $refund = $row['amount'] * $row['price']; // calculate how much this one + the old item amount would cost $new_cost = ($amount + $row['amount']) * $price; // do the sum for the balance, can be negative $cost = $new_cost - $refund; } $balance = umc_money_check($uuid); if ($balance < $cost) { umc_error("{red}[!]{gray} Insufficient funds ({white}{$cost}{gray} needed). " . "{purple}[?]{white} Why don't you vote for the server and try again?"); } if ($do_check) { if ($row) { $sum = $amount + $row['amount']; umc_echo("{white}[?]{gray} This would update your existing request to " . "{yellow}{$sum} {$item['full']}{darkgray} @ {cyan}{$price}{gray} each."); } else { umc_echo("{white}[?]{gray} This would create a new request for " . "{yellow}{$amount} {$item['full']}{darkgray} @ {cyan}{$price}{gray} each."); } if ($cost > 0) { umc_echo("{white}[?]{white} Your account would be charged {cyan}{$cost}{gray} Uncs."); } else { umc_echo("{white}[?]{white} Your account would be credited {cyan}" . $cost * -1 . "{gray} Uncs."); } return; } $sum = 0; $posted_id = 0; if ($row) { // Update existing listing $sum = $amount + $row['amount']; umc_echo("{green}[+]{gray} You already requested {yellow}" . "{$row['amount']} {$item['full']}{gray}. Adding another {yellow}{$amount}{gray}."); $sql = "UPDATE minecraft_iconomy.`request` SET `amount` = amount + '{$amount}', price='{$price}' WHERE id={$row['id']};"; $rst = umc_mysql_query($sql); $posted_id = $row['id']; } else { // Create a new listing. $sum = $amount; umc_echo("{green}[+]{gray} You are now requesting {yellow}" . "{$sum} {$item['full']}{gray} in the shop."); $sql = "INSERT INTO minecraft_iconomy.`request` (`id` ,`damage` ,`uuid` ,`item_name` ,`price` ,`amount` ,`meta`)\r\n VALUES (NULL , '{$type}', '{$uuid}', '{$item['item_name']}', '{$price}', '{$amount}', '{$meta}');"; //XMPP_ERROR_trigger($sql); $rst = umc_mysql_query($sql); $posted_id = umc_mysql_insert_id(); } if ($cost > 0) { umc_echo("{yellow}[\$]{white} Your account has been charged {cyan}{$cost}{gray} Uncs."); } else { umc_echo("{green}[\$]{white} Your account has been credited {cyan}" . $cost * -1 . "{gray} Uncs."); } umc_money($player, false, $cost); umc_announce("{gold}{$player}{gray} is {red}requesting to buy {yellow}{$sum}{$meta_txt}{green} " . "{$item['full']}{darkgray} @ {cyan}{$price}{gray} each{darkgray}, shop-id {gray}{$posted_id}"); }